Skip to content

chore: add load tests #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ export class GPTScript {
this.ready = await this.testGPTScriptURL(20)
}

if (this.opts.Env) {
opts.env = this.opts.Env.concat(opts.env || [])
}

return (new Run("run", toolName, {...this.opts, ...opts}, GPTScript.serverURL)).nextChat(opts.input)
}

Expand All @@ -187,6 +191,10 @@ export class GPTScript {
this.ready = await this.testGPTScriptURL(20)
}

if (this.opts.Env) {
opts.env = this.opts.Env.concat(opts.env || [])
}

return (new Run("evaluate", tool, {...this.opts, ...opts}, GPTScript.serverURL)).nextChat(opts.input)
}

Expand Down
56 changes: 56 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as gptscript from "../src/gptscript"
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolType} from "../src/gptscript"
import path from "path"
import {fileURLToPath} from "url"
import * as fs from "node:fs"

let gFirst: gptscript.GPTScript
let g: gptscript.GPTScript
Expand Down Expand Up @@ -286,6 +287,7 @@ describe("gptscript module", () => {
await g.parse(path.join(__dirname, "fixtures", "non-existent.gpt"))
} catch (e) {
expect(e).toBeDefined()
expect(typeof e !== "string").toBeTruthy()
return
}
expect(false).toBeTruthy()
Expand All @@ -296,6 +298,7 @@ describe("gptscript module", () => {
await g.parse("github.com/thedadams/dne")
} catch (e) {
expect(e).toBeDefined()
expect(typeof e !== "string").toBeTruthy()
return
}
expect(false).toBeTruthy()
Expand Down Expand Up @@ -408,6 +411,59 @@ describe("gptscript module", () => {
expect(response).toContain("Type: Context")
})

test("load simple file", async () => {
const response = await g.load(path.join(__dirname, "fixtures", "test.gpt"))
expect(response.program).toBeDefined()
expect(response.program.name).toBeTruthy()
expect(response.program.entryToolId).toBeTruthy()
expect(response.program.toolSet).toBeDefined()
}, 30000)

test("load remote tool", async () => {
const response = await g.load("github.com/gptscript-ai/context/workspace")
expect(response.program).toBeDefined()
expect(response.program.name).toBeTruthy()
expect(response.program.entryToolId).toBeTruthy()
expect(response.program.toolSet).toBeDefined()
}, 30000)

test("load content", async () => {
const content = fs.readFileSync(path.join(__dirname, "fixtures", "test.gpt"), {encoding: "utf8"})
const response = await g.loadContent(content)
expect(response.program).toBeDefined()
// Name will not be defined in this case.
expect(response.program.name).toBeFalsy()
expect(response.program.entryToolId).toBeTruthy()
expect(response.program.toolSet).toBeDefined()
}, 30000)

test("load tools", async () => {
const tools = [{
tools: ["ask"],
instructions: "Only use the ask tool to ask who was the president of the united states in 1928?"
},
{
name: "other",
instructions: "Who was the president of the united states in 1986?"
},
{
name: "ask",
description: "This tool is used to ask a question",
arguments: {
type: "object",
question: "The question to ask"
},
instructions: "${question}"
},
] as gptscript.ToolDef[]
const response = await g.loadTools(tools)
expect(response.program).toBeDefined()
// Name will not be defined in this case.
expect(response.program.name).toBeFalsy()
expect(response.program.entryToolId).toBeTruthy()
expect(response.program.toolSet).toBeDefined()
}, 30000)

test("exec tool with chat", async () => {
let err = undefined
const t = {
Expand Down