mirror of
https://github.com/run-llama/LlamaIndexTS.git
synced 2026-07-16 07:14:29 -04:00
feat(anthropic): stream partial tool calls (#2100)
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@llamaindex/anthropic": patch
|
||||
---
|
||||
|
||||
anthropic: stream partial tool calls
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user