From 9b7cb795ca0ccd44b97fc51e1c1740b2913d30ea Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Sun, 22 Sep 2024 18:53:51 +0800 Subject: [PATCH] hotfix openai function call tool_calls no index --- app/client/platforms/openai.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 664ff872b..349a014ec 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -244,6 +244,7 @@ export class ChatGPTApi implements LLMApi { ); } if (shouldStream) { + let index = -1; const [tools, funcs] = usePluginStore .getState() .getAsTools( @@ -269,7 +270,7 @@ export class ChatGPTApi implements LLMApi { }>; const tool_calls = choices[0]?.delta?.tool_calls; if (tool_calls?.length > 0) { - const index = tool_calls[0]?.index; + index += 1; const id = tool_calls[0]?.id; const args = tool_calls[0]?.function?.arguments; if (id) { @@ -294,6 +295,8 @@ export class ChatGPTApi implements LLMApi { toolCallMessage: any, toolCallResult: any[], ) => { + // reset index value + index = -1; // @ts-ignore requestPayload?.messages?.splice( // @ts-ignore