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

Run tool calls in parallel #1132

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions src/lib/AbstractChatCompletionRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ export class AbstractChatCompletionRunner<
return;
}

for (const tool_call of message.tool_calls) {
if (tool_call.type !== 'function') continue;
await Promise.all(message.tool_calls.map(async (tool_call) => {
if (tool_call.type !== 'function') return;
const tool_call_id = tool_call.id;
const { name, arguments: args } = tool_call.function;
const fn = functionsByName[name];
Expand All @@ -445,14 +445,14 @@ export class AbstractChatCompletionRunner<
.join(', ')}. Please try again`;

this._addMessage({ role, tool_call_id, content });
continue;
return;
} else if (singleFunctionToCall && singleFunctionToCall !== name) {
const content = `Invalid tool_call: ${JSON.stringify(name)}. ${JSON.stringify(
singleFunctionToCall,
)} requested. Please try again`;

this._addMessage({ role, tool_call_id, content });
continue;
return;
}

let parsed;
Expand All @@ -461,7 +461,7 @@ export class AbstractChatCompletionRunner<
} catch (error) {
const content = error instanceof Error ? error.message : String(error);
this._addMessage({ role, tool_call_id, content });
continue;
return;
}

// @ts-expect-error it can't rule out `never` type.
Expand All @@ -472,7 +472,7 @@ export class AbstractChatCompletionRunner<
if (singleFunctionToCall) {
return;
}
}
});
}

return;
Expand Down