diff --git a/src/gptscript.ts b/src/gptscript.ts index baa8a15..8b8fbf9 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -168,18 +168,19 @@ export class GPTScript { } } - listModels(providers?: string[], credentialOverrides?: string[]): Promise { + async listModels(providers?: string[], credentialOverrides?: string[]): Promise> { if (this.opts.DefaultModelProvider) { if (!providers) { providers = [] } providers.push(this.opts.DefaultModelProvider) } - return this.runBasicCommand("list-models", { + const result = await this.runBasicCommand("list-models", { "providers": providers, "env": this.opts.Env, "credentialOverrides": credentialOverrides }) + return await JSON.parse(result) as Array } version(): Promise { @@ -1229,6 +1230,34 @@ export type Credential = { refreshToken?: string | undefined } +// Types for OpenAI API-compatible models + +export type Permission = { + created: number, + id: string, + object: string, + allow_create_engine: boolean, + allow_sampling: boolean, + allow_logprobs: boolean, + allow_search_indices: boolean, + allow_view: boolean, + allow_fine_tuning: boolean, + organization: string, + group: any, + is_blocking: boolean, +} + +export type Model = { + created: number, + id: string, + object: string, + owned_by: string, + permission: Array, + root: string, + parent: string, + metadata: Record, +} + // for internal use only type cred = { context: string diff --git a/tests/gptscript.test.ts b/tests/gptscript.test.ts index 077107c..6cc0cfb 100644 --- a/tests/gptscript.test.ts +++ b/tests/gptscript.test.ts @@ -51,12 +51,12 @@ describe("gptscript module", () => { return } - let models = await g.listModels(["github.com/gptscript-ai/claude3-anthropic-provider"], ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY"]) + const models = await g.listModels(["github.com/gptscript-ai/claude3-anthropic-provider"], ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY"]) expect(models).toBeDefined() - for (let model of models.split("\n")) { + for (const model of models) { expect(model).toBeDefined() - expect(model.startsWith("claude-3-")).toBe(true) - expect(model.endsWith("from github.com/gptscript-ai/claude3-anthropic-provider")).toBe(true) + expect(model.id.startsWith("claude-3-")).toBe(true) + expect(model.id.endsWith("from github.com/gptscript-ai/claude3-anthropic-provider")).toBe(true) } }, 60000) @@ -67,12 +67,12 @@ describe("gptscript module", () => { const newg = new gptscript.GPTScript({DefaultModelProvider: "github.com/gptscript-ai/claude3-anthropic-provider"}) try { - let models = await newg.listModels(undefined, ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY"]) + const models = await newg.listModels(undefined, ["github.com/gptscript-ai/claude3-anthropic-provider/credential:ANTHROPIC_API_KEY"]) expect(models).toBeDefined() - for (let model of models.split("\n")) { + for (const model of models) { expect(model).toBeDefined() - expect(model.startsWith("claude-3-")).toBe(true) - expect(model.endsWith("from github.com/gptscript-ai/claude3-anthropic-provider")).toBe(true) + expect(model.id.startsWith("claude-3-")).toBe(true) + expect(model.id.endsWith("from github.com/gptscript-ai/claude3-anthropic-provider")).toBe(true) } } finally { newg.close()