Only delete message if had successful tool calls

This commit is contained in:
Cohee 2024-10-04 01:45:37 +03:00
parent 777b2518bd
commit 447a7fba68
1 changed files with 5 additions and 5 deletions

View File

@ -4417,11 +4417,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
}
if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) {
const lastMessage = chat[chat.length - 1];
const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
shouldDeleteMessage && await deleteLastMessage();
const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
if (invocationResult.hadToolCalls) {
const lastMessage = chat[chat.length - 1];
const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
shouldDeleteMessage && await deleteLastMessage();
if (!invocationResult.invocations.length && shouldDeleteMessage) {
ToolManager.showToolCallError(invocationResult.errors);
unblockGeneration(type);
@ -4511,10 +4511,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
}
if (canPerformToolCalls) {
const shouldDeleteMessage = ['', '...'].includes(getMessage);
shouldDeleteMessage && await deleteLastMessage();
const invocationResult = await ToolManager.invokeFunctionTools(data);
if (invocationResult.hadToolCalls) {
const shouldDeleteMessage = ['', '...'].includes(getMessage);
shouldDeleteMessage && await deleteLastMessage();
if (!invocationResult.invocations.length && shouldDeleteMessage) {
ToolManager.showToolCallError(invocationResult.errors);
unblockGeneration(type);