Skip to content

Commit 0e2a16c

Browse files
authored
Merge pull request #39 from thedadams/add-tool-context
feat: add support for tools context
2 parents 21772e2 + c28abda commit 0e2a16c

12 files changed

+28
-188
lines changed

examples/example-file-stream.js

-21
This file was deleted.

examples/example-models.js

-11
This file was deleted.

examples/example-parse-file.js

-11
This file was deleted.

examples/example-parse.js

-11
This file was deleted.

examples/example-tool-chat-stream.js

-49
This file was deleted.

examples/example-tool-stream.js

-23
This file was deleted.

examples/example-tools.js

-11
This file was deleted.

examples/example-version.js

-11
This file was deleted.

examples/sangeetha.js

-40
This file was deleted.

src/gptscript.ts

+7
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,7 @@ export interface ToolDef {
729729
arguments: ArgumentSchema
730730
tools: string[]
731731
globalTools: string[]
732+
context: string[]
732733
export: string[]
733734
blocking: boolean
734735
instructions: string
@@ -960,6 +961,12 @@ function toolDefToString(tool: ToolDef) {
960961
if (tool.tools?.length > 0) {
961962
toolInfo.push(`Tools: ${tool.tools.join(", ")}`)
962963
}
964+
if (tool.context?.length > 0) {
965+
toolInfo.push(`Context: ${tool.context.join(", ")}`)
966+
}
967+
if (tool.export?.length > 0) {
968+
toolInfo.push(`Export: ${tool.export.join(", ")}`)
969+
}
963970
if (tool.maxTokens !== undefined) {
964971
toolInfo.push(`Max Tokens: ${tool.maxTokens}`)
965972
}

tests/fixtures/acorn-labs-context.gpt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Say "Answer every query with 'Acorn Labs'"

tests/gptscript.test.ts

+20
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ describe("gptscript module", () => {
6363
expect(err).toEqual("")
6464
})
6565

66+
test("evaluate executes a prompt correctly with context", async () => {
67+
let out = ""
68+
let err = undefined
69+
const t = {
70+
instructions: "who was the president of the united states in 1928?",
71+
context: [path.join(__dirname, "fixtures", "acorn-labs-context.gpt")]
72+
}
73+
74+
try {
75+
const run = client.evaluate(t as any, {disableCache: true})
76+
out = await run.text()
77+
err = run.err
78+
} catch (e) {
79+
console.error(e)
80+
}
81+
82+
expect(out).toContain("Acorn Labs")
83+
expect(err).toEqual("")
84+
})
85+
6686
describe("run with test.gpt fixture", () => {
6787
test("should execute test.gpt correctly", async () => {
6888
const testGptPath = path.join(__dirname, "fixtures", "test.gpt")

0 commit comments

Comments
 (0)