Add Claude streamed tool parser
This commit is contained in:
parent
c3c10a629e
commit
0cab91e0f8
|
@ -256,9 +256,7 @@ export class ToolManager {
|
|||
* @returns {void}
|
||||
*/
|
||||
static parseToolCalls(toolCalls, parsed) {
|
||||
if (!Array.isArray(parsed?.choices)) {
|
||||
return;
|
||||
}
|
||||
if (Array.isArray(parsed?.choices)) {
|
||||
for (const choice of parsed.choices) {
|
||||
const choiceIndex = (typeof choice.index === 'number') ? choice.index : null;
|
||||
const choiceDelta = choice.delta;
|
||||
|
@ -294,6 +292,25 @@ export class ToolManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (typeof parsed?.content_block === 'object') {
|
||||
const choiceIndex = 0;
|
||||
|
||||
if (parsed?.content_block?.type === 'tool_use') {
|
||||
if (!Array.isArray(toolCalls[choiceIndex])) {
|
||||
toolCalls[choiceIndex] = [];
|
||||
}
|
||||
|
||||
const toolCallIndex = toolCalls[choiceIndex].length;
|
||||
|
||||
if (toolCalls[choiceIndex][toolCallIndex] === undefined) {
|
||||
toolCalls[choiceIndex][toolCallIndex] = {};
|
||||
}
|
||||
|
||||
const targetToolCall = toolCalls[choiceIndex][toolCallIndex];
|
||||
Object.assign(targetToolCall, parsed.content_block);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static #applyToolCallDelta(target, delta) {
|
||||
for (const key in delta) {
|
||||
|
|
Loading…
Reference in New Issue