Skip to content

Commit

Permalink
fix: stringify non-tool tools
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 ad748d9 commit 7a32707
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/gptscript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,16 @@ export class GPTScript {
const nodes: any[] = []

for (const block of blocks) {
if (block.type === "tool") {
if (block.type === "text") {
nodes.push({
toolNode: {
tool: block
textNode: {
text: "!" + (block.format || "text") + "\n" + block.content
}
})
} else if (block.type === "text") {
} else {
nodes.push({
textNode: {
text: "!" + (block.format || "text") + "\n" + block.content
toolNode: {
tool: block
}
})
}
Expand Down
25 changes: 25 additions & 0 deletions tests/gptscript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,31 @@ describe("gptscript module", () => {
expect(response).toContain("Parameter: text: The text to write")
})

test("format context tool", async () => {
const tool = {
id: "my-tool",
type: "context" as ToolType,
tools: ["sys.write", "sys.read"],
instructions: "This is a test",
arguments: {
type: ArgumentSchemaType,
properties: {
text: {
type: PropertyType,
description: "The text to write"
}
}
}
}

const response = await g.stringify([tool])
expect(response).toBeDefined()
expect(response).toContain("Tools: sys.write, sys.read")
expect(response).toContain("This is a test")
expect(response).toContain("Parameter: text: The text to write")
expect(response).toContain("Type: Context")
})

test("exec tool with chat", async () => {
let err = undefined
const t = {
Expand Down

0 comments on commit 7a32707

Please sign in to comment.