Skip to content

Commit 8de25eb

Browse files
authored
Merge pull request #22 from thedadams/add-sub-tools
feat: add support for the subTool option
2 parents 56c7164 + 189c4b4 commit 8de25eb

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

src/gptscript.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const optToArg = {
1515
cacheDir: "--cache-dir=",
1616
quiet: "--quiet=",
1717
chdir: "--chdir=",
18+
subTool: "--sub-tool=",
1819
}
1920

2021
function toArgs(opts) {

src/request.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ async function makeStreamRequest(path, tool, opts = {}) {
5151
const req = http.request(options, (res) => {
5252
res.on('data', (chunk) => {
5353
const c = chunk.toString().replace(/^(data: )/,"").trim();
54-
if (c === 'DONE') {
54+
if (c === '[DONE]') {
5555
} else if (c.startsWith('{"stderr":')) {
5656
stderr.push(JSON.parse(c).stderr);
5757
} else {
@@ -100,7 +100,7 @@ async function makeStreamRequestWithEvents(path, tool, opts = {}) {
100100
const req = http.request(options, (res) => {
101101
res.on('data', (chunk) => {
102102
const c = chunk.toString().replace(/^(data: )/,"").trim();
103-
if (c === 'DONE') {
103+
if (c === '[DONE]') {
104104
} else if (c.startsWith('{"stderr":')) {
105105
stderr.push(JSON.parse(c).stderr);
106106
} else if (c.startsWith('{"stdout":')) {

tests/gptscript.test.js

+42-17
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,47 @@ describe('gptscript module', () => {
174174
expect(event).toContain("events: ");
175175
});
176176

177-
test('exec of multiple tools', async () => {
178-
const t0 = new gptscript.Tool({
179-
tools: ["ask"],
180-
instructions: "Only use the ask tool to ask who was the president of the united states in 1928?"
181-
});
182-
const t1 = new gptscript.Tool({
183-
name: "ask",
184-
description: "This tool is used to ask a question",
185-
args: {
186-
question: "The question to ask"
187-
},
188-
instructions: "${question}"
189-
});
177+
describe('exec with multiple tools', () => {
178+
test('multiple tools', async () => {
179+
const t0 = new gptscript.Tool({
180+
tools: ["ask"],
181+
instructions: "Only use the ask tool to ask who was the president of the united states in 1928?"
182+
});
183+
const t1 = new gptscript.Tool({
184+
name: "ask",
185+
description: "This tool is used to ask a question",
186+
args: {
187+
question: "The question to ask"
188+
},
189+
instructions: "${question}"
190+
});
190191

191-
const response = await gptscript.exec([t0, t1]);
192-
expect(response).toBeDefined();
193-
expect(response).toContain("Calvin Coolidge");
194-
}, 30000);
192+
const response = await gptscript.exec([t0, t1]);
193+
expect(response).toBeDefined();
194+
expect(response).toContain("Calvin Coolidge");
195+
}, 30000);
196+
197+
test('with sub tool', async () => {
198+
const t0 = new gptscript.Tool({
199+
tools: ["ask"],
200+
instructions: "Only use the ask tool to ask who was the president of the united states in 1928?"
201+
});
202+
const t1 = new gptscript.Tool({
203+
name: "other",
204+
instructions: "Who was the president of the united states in 1986?"
205+
});
206+
const t2 = new gptscript.Tool({
207+
name: "ask",
208+
description: "This tool is used to ask a question",
209+
args: {
210+
question: "The question to ask"
211+
},
212+
instructions: "${question}"
213+
});
214+
215+
const response = await gptscript.exec([t0, t1, t2], {subTool: 'other'});
216+
expect(response).toBeDefined();
217+
expect(response).toContain("Ronald Reagan");
218+
}, 30000);
219+
});
195220
});

0 commit comments

Comments
 (0)