Skip to content

Commit

Permalink
chore: add load tests
Browse files Browse the repository at this point in the history
Signed-off-by: Donnie Adams <[email protected]>
  • Loading branch information
thedadams committed Aug 30, 2024
1 parent fae5ed7 commit 5635b1b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 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,58 @@ 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()
expect(response.program.name).toBeTruthy()
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

0 comments on commit 5635b1b

Please sign in to comment.