mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Add Claude streamed tool parser
This commit is contained in:
@ -256,9 +256,7 @@ export class ToolManager {
|
|||||||
* @returns {void}
|
* @returns {void}
|
||||||
*/
|
*/
|
||||||
static parseToolCalls(toolCalls, parsed) {
|
static parseToolCalls(toolCalls, parsed) {
|
||||||
if (!Array.isArray(parsed?.choices)) {
|
if (Array.isArray(parsed?.choices)) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (const choice of parsed.choices) {
|
for (const choice of parsed.choices) {
|
||||||
const choiceIndex = (typeof choice.index === 'number') ? choice.index : null;
|
const choiceIndex = (typeof choice.index === 'number') ? choice.index : null;
|
||||||
const choiceDelta = choice.delta;
|
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) {
|
static #applyToolCallDelta(target, delta) {
|
||||||
for (const key in delta) {
|
for (const key in delta) {
|
||||||
|
Reference in New Issue
Block a user