Skip to content

Commit f24e6b1

Browse files
authored
Merge pull request #87 from thedadams/add-load-tests
chore: add load tests
2 parents fae5ed7 + 0be229f commit f24e6b1

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

src/gptscript.ts

+8
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ export class GPTScript {
172172
this.ready = await this.testGPTScriptURL(20)
173173
}
174174

175+
if (this.opts.Env) {
176+
opts.env = this.opts.Env.concat(opts.env || [])
177+
}
178+
175179
return (new Run("run", toolName, {...this.opts, ...opts}, GPTScript.serverURL)).nextChat(opts.input)
176180
}
177181

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

194+
if (this.opts.Env) {
195+
opts.env = this.opts.Env.concat(opts.env || [])
196+
}
197+
190198
return (new Run("evaluate", tool, {...this.opts, ...opts}, GPTScript.serverURL)).nextChat(opts.input)
191199
}
192200

tests/gptscript.test.ts

+56
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as gptscript from "../src/gptscript"
22
import {ArgumentSchemaType, getEnv, PropertyType, RunEventType, TextType, ToolType} from "../src/gptscript"
33
import path from "path"
44
import {fileURLToPath} from "url"
5+
import * as fs from "node:fs"
56

67
let gFirst: gptscript.GPTScript
78
let g: gptscript.GPTScript
@@ -286,6 +287,7 @@ describe("gptscript module", () => {
286287
await g.parse(path.join(__dirname, "fixtures", "non-existent.gpt"))
287288
} catch (e) {
288289
expect(e).toBeDefined()
290+
expect(typeof e !== "string").toBeTruthy()
289291
return
290292
}
291293
expect(false).toBeTruthy()
@@ -296,6 +298,7 @@ describe("gptscript module", () => {
296298
await g.parse("github.com/thedadams/dne")
297299
} catch (e) {
298300
expect(e).toBeDefined()
301+
expect(typeof e !== "string").toBeTruthy()
299302
return
300303
}
301304
expect(false).toBeTruthy()
@@ -408,6 +411,59 @@ describe("gptscript module", () => {
408411
expect(response).toContain("Type: Context")
409412
})
410413

414+
test("load simple file", async () => {
415+
const response = await g.load(path.join(__dirname, "fixtures", "test.gpt"))
416+
expect(response.program).toBeDefined()
417+
expect(response.program.name).toBeTruthy()
418+
expect(response.program.entryToolId).toBeTruthy()
419+
expect(response.program.toolSet).toBeDefined()
420+
}, 30000)
421+
422+
test("load remote tool", async () => {
423+
const response = await g.load("github.com/gptscript-ai/context/workspace")
424+
expect(response.program).toBeDefined()
425+
expect(response.program.name).toBeTruthy()
426+
expect(response.program.entryToolId).toBeTruthy()
427+
expect(response.program.toolSet).toBeDefined()
428+
}, 30000)
429+
430+
test("load content", async () => {
431+
const content = fs.readFileSync(path.join(__dirname, "fixtures", "test.gpt"), {encoding: "utf8"})
432+
const response = await g.loadContent(content)
433+
expect(response.program).toBeDefined()
434+
// Name will not be defined in this case.
435+
expect(response.program.name).toBeFalsy()
436+
expect(response.program.entryToolId).toBeTruthy()
437+
expect(response.program.toolSet).toBeDefined()
438+
}, 30000)
439+
440+
test("load tools", async () => {
441+
const tools = [{
442+
tools: ["ask"],
443+
instructions: "Only use the ask tool to ask who was the president of the united states in 1928?"
444+
},
445+
{
446+
name: "other",
447+
instructions: "Who was the president of the united states in 1986?"
448+
},
449+
{
450+
name: "ask",
451+
description: "This tool is used to ask a question",
452+
arguments: {
453+
type: "object",
454+
question: "The question to ask"
455+
},
456+
instructions: "${question}"
457+
},
458+
] as gptscript.ToolDef[]
459+
const response = await g.loadTools(tools)
460+
expect(response.program).toBeDefined()
461+
// Name will not be defined in this case.
462+
expect(response.program.name).toBeFalsy()
463+
expect(response.program.entryToolId).toBeTruthy()
464+
expect(response.program.toolSet).toBeDefined()
465+
}, 30000)
466+
411467
test("exec tool with chat", async () => {
412468
let err = undefined
413469
const t = {

0 commit comments

Comments
 (0)