From dd29cf895f433813a565350da506355580a9088a Mon Sep 17 00:00:00 2001 From: "jinhui.li" Date: Tue, 17 Jun 2025 09:01:53 +0800 Subject: [PATCH] fix API Error: A.map is not a function --- src/utils/stream.ts | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/utils/stream.ts b/src/utils/stream.ts index 7f3c4e7..c139cf3 100644 --- a/src/utils/stream.ts +++ b/src/utils/stream.ts @@ -58,15 +58,26 @@ export async function streamOpenAIResponse( type: "message", role: "assistant", // @ts-ignore - content: completion.choices[0].message.content || completion.choices[0].message.tool_calls?.map((item) => { - return { - type: 'tool_use', - id: item.id, - name: item.function?.name, - input: item.function?.arguments ? JSON.parse(item.function.arguments) : {}, - }; - }) || '', - stop_reason: completion.choices[0].finish_reason === 'tool_calls' ? "tool_use" : "end_turn", + content: completion.choices[0].message.content || + completion.choices[0].message.tool_calls?.map((item) => { + return { + type: "tool_use", + id: item.id, + name: item.function?.name, + input: item.function?.arguments + ? JSON.parse(item.function.arguments) + : {}, + }; + }) || [ + { + type: "text", + text: "", + }, + ], + stop_reason: + completion.choices[0].finish_reason === "tool_calls" + ? "tool_use" + : "end_turn", stop_sequence: null, usage: { input_tokens: 100,