feat(anthropic): stream partial tool calls (#2100)

This commit is contained in:
r3rer3
2025-07-15 13:06:17 -04:00
committed by GitHub
parent 1782554488
commit ddc0eafbaa
2 changed files with 21 additions and 10 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"@llamaindex/anthropic": patch
---
anthropic: stream partial tool calls
+16 -10
View File
@@ -578,7 +578,6 @@ export class Anthropic extends ToolCallLLM<
});
let currentToolCall: PartialToolCall | null = null;
let accumulatedToolInput = "";
for await (const part of stream) {
const textContent =
@@ -607,7 +606,13 @@ export class Anthropic extends ToolCallLLM<
name: part.content_block.name,
input: "",
};
accumulatedToolInput = "";
yield {
raw: part,
delta: "",
options: {
toolCall: [currentToolCall],
},
};
continue;
}
@@ -616,7 +621,14 @@ export class Anthropic extends ToolCallLLM<
part.delta.type === "input_json_delta" &&
currentToolCall
) {
accumulatedToolInput += part.delta.partial_json;
currentToolCall.input += part.delta.partial_json;
yield {
raw: part,
delta: "",
options: {
toolCall: [currentToolCall],
},
};
continue;
}
@@ -625,13 +637,7 @@ export class Anthropic extends ToolCallLLM<
raw: part,
delta: "",
options: {
toolCall: [
{
id: currentToolCall.id,
name: currentToolCall.name,
input: accumulatedToolInput,
},
],
toolCall: [currentToolCall],
},
};
currentToolCall = null;