Skip to content
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

feat: add support for tools context #39

Merged
merged 1 commit into from
May 17, 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
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