diff --git a/src/gptscript.ts b/src/gptscript.ts index cfb8cfe..099c5bc 100644 --- a/src/gptscript.ts +++ b/src/gptscript.ts @@ -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 } }) } diff --git a/tests/gptscript.test.ts b/tests/gptscript.test.ts index 42b4398..ca86083 100644 --- a/tests/gptscript.test.ts +++ b/tests/gptscript.test.ts @@ -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 = {