From 57702f545da93efe352608e6f484e975d10fba02 Mon Sep 17 00:00:00 2001 From: SuYao Date: Mon, 25 Aug 2025 19:49:52 +0800 Subject: [PATCH] =?UTF-8?q?fix(OpenAIApiClient):=20=E9=80=82=E9=85=8Dglm?= =?UTF-8?q?=204.5=20toolcall=20(#9516)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(OpenAIApiClient): update toolCalls handling to support dynamic index assignment * refactor(OpenAIApiClient): streamline toolCalls management with reusable object structure --- .../src/aiCore/clients/openai/OpenAIApiClient.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts b/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts index 4808d8a4e9..9693988ed1 100644 --- a/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts +++ b/src/renderer/src/aiCore/clients/openai/OpenAIApiClient.ts @@ -924,13 +924,19 @@ export class OpenAIAPIClient extends OpenAIBaseClient< if ('index' in toolCall) { const { id, index, function: fun } = toolCall if (fun?.name) { - toolCalls[index] = { + const toolCallObject = { id: id || '', function: { name: fun.name, arguments: fun.arguments || '' }, - type: 'function' + type: 'function' as const + } + + if (index === -1) { + toolCalls.push(toolCallObject) + } else { + toolCalls[index] = toolCallObject } } else if (fun?.arguments) { if (toolCalls[index] && toolCalls[index].type === 'function' && 'function' in toolCalls[index]) {