mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-01-19 04:50:12 +01:00
Fix ghost messages
This commit is contained in:
parent
8ff9ef3610
commit
01fc5113d7
@ -4418,11 +4418,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) {
|
if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) {
|
||||||
const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
|
|
||||||
if (invocationResult.hadToolCalls) {
|
|
||||||
const lastMessage = chat[chat.length - 1];
|
const lastMessage = chat[chat.length - 1];
|
||||||
|
const hasToolCalls = ToolManager.hasToolCalls(streamingProcessor.toolCalls);
|
||||||
const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor?.result);
|
const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor?.result);
|
||||||
shouldDeleteMessage && await deleteLastMessage();
|
hasToolCalls && shouldDeleteMessage && await deleteLastMessage();
|
||||||
|
const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
|
||||||
|
if (hasToolCalls) {
|
||||||
if (!invocationResult.invocations.length && shouldDeleteMessage) {
|
if (!invocationResult.invocations.length && shouldDeleteMessage) {
|
||||||
ToolManager.showToolCallError(invocationResult.errors);
|
ToolManager.showToolCallError(invocationResult.errors);
|
||||||
unblockGeneration(type);
|
unblockGeneration(type);
|
||||||
@ -4512,10 +4513,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (canPerformToolCalls) {
|
if (canPerformToolCalls) {
|
||||||
const invocationResult = await ToolManager.invokeFunctionTools(data);
|
const hasToolCalls = ToolManager.hasToolCalls(data);
|
||||||
if (invocationResult.hadToolCalls) {
|
|
||||||
const shouldDeleteMessage = ['', '...'].includes(getMessage);
|
const shouldDeleteMessage = ['', '...'].includes(getMessage);
|
||||||
shouldDeleteMessage && await deleteLastMessage();
|
hasToolCalls && shouldDeleteMessage && await deleteLastMessage();
|
||||||
|
const invocationResult = await ToolManager.invokeFunctionTools(data);
|
||||||
|
if (hasToolCalls) {
|
||||||
if (!invocationResult.invocations.length && shouldDeleteMessage) {
|
if (!invocationResult.invocations.length && shouldDeleteMessage) {
|
||||||
ToolManager.showToolCallError(invocationResult.errors);
|
ToolManager.showToolCallError(invocationResult.errors);
|
||||||
unblockGeneration(type);
|
unblockGeneration(type);
|
||||||
|
@ -14,7 +14,6 @@ import { Popup } from './popup.js';
|
|||||||
/**
|
/**
|
||||||
* @typedef {object} ToolInvocationResult
|
* @typedef {object} ToolInvocationResult
|
||||||
* @property {ToolInvocation[]} invocations Successful tool invocations
|
* @property {ToolInvocation[]} invocations Successful tool invocations
|
||||||
* @property {boolean} hadToolCalls Whether any tool calls were found
|
|
||||||
* @property {Error[]} errors Errors that occurred during tool invocation
|
* @property {Error[]} errors Errors that occurred during tool invocation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -322,7 +321,7 @@ export class ToolManager {
|
|||||||
const choiceIndex = 0;
|
const choiceIndex = 0;
|
||||||
const toolCallIndex = parsed?.index ?? 0;
|
const toolCallIndex = parsed?.index ?? 0;
|
||||||
const targetToolCall = toolCalls[choiceIndex]?.[toolCallIndex];
|
const targetToolCall = toolCalls[choiceIndex]?.[toolCallIndex];
|
||||||
if (targetToolCall){
|
if (targetToolCall) {
|
||||||
if (parsed?.delta?.type === 'input_json_delta') {
|
if (parsed?.delta?.type === 'input_json_delta') {
|
||||||
const jsonDelta = parsed?.delta?.partial_json;
|
const jsonDelta = parsed?.delta?.partial_json;
|
||||||
if (!targetToolCall[this.#INPUT_DELTA_KEY]) {
|
if (!targetToolCall[this.#INPUT_DELTA_KEY]) {
|
||||||
@ -454,6 +453,15 @@ export class ToolManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the response data contains tool calls.
|
||||||
|
* @param {object} data Response data
|
||||||
|
* @returns {boolean} Whether the response data contains tool calls
|
||||||
|
*/
|
||||||
|
static hasToolCalls(data) {
|
||||||
|
return Array.isArray(ToolManager.#getToolCallsFromData(data));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for function tool calls in the response data and invoke them.
|
* Check for function tool calls in the response data and invoke them.
|
||||||
* @param {any} data Reply data
|
* @param {any} data Reply data
|
||||||
@ -463,7 +471,6 @@ export class ToolManager {
|
|||||||
/** @type {ToolInvocationResult} */
|
/** @type {ToolInvocationResult} */
|
||||||
const result = {
|
const result = {
|
||||||
invocations: [],
|
invocations: [],
|
||||||
hadToolCalls: false,
|
|
||||||
errors: [],
|
errors: [],
|
||||||
};
|
};
|
||||||
const toolCalls = ToolManager.#getToolCallsFromData(data);
|
const toolCalls = ToolManager.#getToolCallsFromData(data);
|
||||||
@ -482,7 +489,6 @@ export class ToolManager {
|
|||||||
const parameters = toolCall.function.arguments;
|
const parameters = toolCall.function.arguments;
|
||||||
const name = toolCall.function.name;
|
const name = toolCall.function.name;
|
||||||
const displayName = ToolManager.getDisplayName(name);
|
const displayName = ToolManager.getDisplayName(name);
|
||||||
result.hadToolCalls = true;
|
|
||||||
|
|
||||||
const message = ToolManager.formatToolCallMessage(name, parameters);
|
const message = ToolManager.formatToolCallMessage(name, parameters);
|
||||||
const toast = message && toastr.info(message, 'Tool Calling', { timeOut: 0 });
|
const toast = message && toastr.info(message, 'Tool Calling', { timeOut: 0 });
|
||||||
|
Loading…
Reference in New Issue
Block a user