mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-06-05 21:59:27 +02:00
Group tool calls in the result
This commit is contained in:
@ -580,6 +580,19 @@ export class ToolManager {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Groups tool names by count.
|
||||||
|
* @param {string[]} toolNames Tool names
|
||||||
|
* @returns {string} Grouped tool names
|
||||||
|
*/
|
||||||
|
static #groupToolNames(toolNames) {
|
||||||
|
const toolCounts = toolNames.reduce((acc, name) => {
|
||||||
|
acc[name] = (acc[name] || 0) + 1;
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
return Object.entries(toolCounts).map(([name, count]) => count > 1 ? `${name} (${count})` : name).join(', ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a message with tool invocations.
|
* Formats a message with tool invocations.
|
||||||
* @param {ToolInvocation[]} invocations Tool invocations.
|
* @param {ToolInvocation[]} invocations Tool invocations.
|
||||||
@ -597,8 +610,8 @@ export class ToolManager {
|
|||||||
i.result = tryParse(i.result);
|
i.result = tryParse(i.result);
|
||||||
});
|
});
|
||||||
codeElement.textContent = JSON.stringify(data, null, 2);
|
codeElement.textContent = JSON.stringify(data, null, 2);
|
||||||
const toolNames = data.map(i => i.displayName || i.name).join(', ');
|
const toolNames = data.map(i => i.displayName || i.name);
|
||||||
summaryElement.textContent = `Tool calls: ${toolNames}`;
|
summaryElement.textContent = `Tool calls: ${this.#groupToolNames(toolNames)}`;
|
||||||
preElement.append(codeElement);
|
preElement.append(codeElement);
|
||||||
detailsElement.append(summaryElement, preElement);
|
detailsElement.append(summaryElement, preElement);
|
||||||
return detailsElement.outerHTML;
|
return detailsElement.outerHTML;
|
||||||
|
Reference in New Issue
Block a user