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