Skip to content

Commit

Permalink
Merge pull request #39 from thedadams/add-tool-context
Browse files Browse the repository at this point in the history
feat: add support for tools context
  • Loading branch information
thedadams authored May 17, 2024
2 parents 21772e2 + c28abda commit 0e2a16c
Show file tree
Hide file tree
Showing 12 changed files with 28 additions and 188 deletions.
21 changes: 0 additions & 21 deletions examples/example-file-stream.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/example-models.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/example-parse-file.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/example-parse.js

This file was deleted.

49 changes: 0 additions & 49 deletions examples/example-tool-chat-stream.js

This file was deleted.

23 changes: 0 additions & 23 deletions examples/example-tool-stream.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/example-tools.js

This file was deleted.

11 changes: 0 additions & 11 deletions examples/example-version.js

This file was deleted.

40 changes: 0 additions & 40 deletions examples/sangeetha.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,7 @@ export interface ToolDef {
arguments: ArgumentSchema
tools: string[]
globalTools: string[]
context: string[]
export: string[]
blocking: boolean
instructions: string
Expand Down Expand Up @@ -960,6 +961,12 @@ function toolDefToString(tool: ToolDef) {
if (tool.tools?.length > 0) {
toolInfo.push(`Tools: ${tool.tools.join(", ")}`)
}
if (tool.context?.length > 0) {
toolInfo.push(`Context: ${tool.context.join(", ")}`)
}
if (tool.export?.length > 0) {
toolInfo.push(`Export: ${tool.export.join(", ")}`)
}
if (tool.maxTokens !== undefined) {
toolInfo.push(`Max Tokens: ${tool.maxTokens}`)
}
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/acorn-labs-context.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Say "Answer every query with 'Acorn Labs'"
20 changes: 20 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ describe("gptscript module", () => {
expect(err).toEqual("")
})

test("evaluate executes a prompt correctly with context", async () => {
let out = ""
let err = undefined
const t = {
instructions: "who was the president of the united states in 1928?",
context: [path.join(__dirname, "fixtures", "acorn-labs-context.gpt")]
}

try {
const run = client.evaluate(t as any, {disableCache: true})
out = await run.text()
err = run.err
} catch (e) {
console.error(e)
}

expect(out).toContain("Acorn Labs")
expect(err).toEqual("")
})

describe("run with test.gpt fixture", () => {
test("should execute test.gpt correctly", async () => {
const testGptPath = path.join(__dirname, "fixtures", "test.gpt")
Expand Down

0 comments on commit 0e2a16c

Please sign in to comment.