Skip to content

Commit 76709c2

Browse files
fix: first tool call chunk without arguments (#2234)
Co-authored-by: Marcus Schiesser <marcus.schiesser@googlemail.com>
1 parent a57e52a commit 76709c2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

.changeset/swift-eagles-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@llamaindex/openai": patch
3+
---
4+
5+
fix: first tool call chunk without arguments

packages/providers/openai/src/llm.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,12 +415,16 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
415415
toolCallMap.set(choice.delta.tool_calls[0].id, currentToolCall);
416416
} else {
417417
if (choice.delta.tool_calls?.[0]!.function?.arguments) {
418+
if (typeof currentToolCall!.input !== "string") {
419+
currentToolCall!.input = "";
420+
}
418421
currentToolCall!.input +=
419422
choice.delta.tool_calls[0].function.arguments;
420423
}
421424
}
422425

423-
const isDone: boolean = choice.finish_reason !== null;
426+
const isDone: boolean =
427+
choice.finish_reason !== null && choice.finish_reason !== undefined;
424428

425429
if (isDone && currentToolCall) {
426430
// for the last one, we need to emit the tool call

0 commit comments

Comments
 (0)