From 93370d825d86cbf5dc8ed09216f68d93fa2127d1 Mon Sep 17 00:00:00 2001 From: castortech Date: Sat, 20 Jul 2024 08:05:03 -0400 Subject: [PATCH] Fix issue of ignoring multiple tool calls This issue is described here: https://github.com/Ironclad/rivet/issues/431#issuecomment-2240039688 --- packages/core/src/model/nodes/ChatNode.ts | 50 +++++++++-------------- 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/packages/core/src/model/nodes/ChatNode.ts b/packages/core/src/model/nodes/ChatNode.ts index f9890b39c..5ed85a86e 100644 --- a/packages/core/src/model/nodes/ChatNode.ts +++ b/packages/core/src/model/nodes/ChatNode.ts @@ -910,37 +910,25 @@ export class ChatNodeImpl extends NodeImpl { } if (functionCalls.length > 0) { - if (isMultiResponse) { - output['function-call' as PortId] = { - type: 'object[]', - value: functionCalls.map((functionCalls) => ({ - name: functionCalls[0]?.name, - arguments: functionCalls[0]?.lastParsedArguments, - id: functionCalls[0]?.id, - })), - }; - } else { - if (this.data.parallelFunctionCalling) { - console.dir({ functionCalls }); - output['function-calls' as PortId] = { - type: 'object[]', - value: functionCalls[0]!.map((functionCall) => ({ - name: functionCall.name, - arguments: functionCall.lastParsedArguments, - id: functionCall.id, - })), - }; - } else { - output['function-call' as PortId] = { - type: 'object', - value: { - name: functionCalls[0]![0]?.name, - arguments: functionCalls[0]![0]?.lastParsedArguments, - id: functionCalls[0]![0]?.id, - } as Record, - }; - } - } + if (isMultiResponse) { + output['function-call' as PortId] = { + type: 'object[]', + value: functionCalls.flat().map((functionCall) => ({ + name: functionCall.name, + arguments: functionCall.lastParsedArguments, + id: functionCall.id, + })), + } + } else { + output['function-call' as PortId] = { + type: 'object[]', + value: functionCalls[0]!.map((functionCall) => ({ + name: functionCall.name, + arguments: functionCall.lastParsedArguments, + id: functionCall.id, + })), + } + } } context.onPartialOutputs?.(output);