fix API Error: A.map is not a function

This commit is contained in:
jinhui.li
2025-06-17 09:01:53 +08:00
parent 56ab2ee309
commit dd29cf895f

View File

@@ -58,15 +58,26 @@ export async function streamOpenAIResponse(
type: "message", type: "message",
role: "assistant", role: "assistant",
// @ts-ignore // @ts-ignore
content: completion.choices[0].message.content || completion.choices[0].message.tool_calls?.map((item) => { content: completion.choices[0].message.content ||
completion.choices[0].message.tool_calls?.map((item) => {
return { return {
type: 'tool_use', type: "tool_use",
id: item.id, id: item.id,
name: item.function?.name, name: item.function?.name,
input: item.function?.arguments ? JSON.parse(item.function.arguments) : {}, input: item.function?.arguments
? JSON.parse(item.function.arguments)
: {},
}; };
}) || '', }) || [
stop_reason: completion.choices[0].finish_reason === 'tool_calls' ? "tool_use" : "end_turn", {
type: "text",
text: "",
},
],
stop_reason:
completion.choices[0].finish_reason === "tool_calls"
? "tool_use"
: "end_turn",
stop_sequence: null, stop_sequence: null,
usage: { usage: {
input_tokens: 100, input_tokens: 100,