fix: first tool call chunk without arguments (#2234)

Co-authored-by: Marcus Schiesser <marcus.schiesser@googlemail.com>
This commit is contained in:
fengkx
2025-11-25 13:57:07 +08:00
committed by GitHub
parent a57e52a9c8
commit 76709c2100
2 changed files with 10 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/openai": patch
---
fix: first tool call chunk without arguments
+5 -1
View File
@@ -415,12 +415,16 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
toolCallMap.set(choice.delta.tool_calls[0].id, currentToolCall);
} else {
if (choice.delta.tool_calls?.[0]!.function?.arguments) {
if (typeof currentToolCall!.input !== "string") {
currentToolCall!.input = "";
}
currentToolCall!.input +=
choice.delta.tool_calls[0].function.arguments;
}
}
const isDone: boolean = choice.finish_reason !== null;
const isDone: boolean =
choice.finish_reason !== null && choice.finish_reason !== undefined;
if (isDone && currentToolCall) {
// for the last one, we need to emit the tool call