Only delete message if had successful tool calls

447a7fba68298cdae8becd82acb3b2f97dc785fd

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +5 -5Ignore whitespace
public/script.js+5 -5
@@ -4417,11 +4417,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
44174417 }
44184418
44194419 if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) {
4420- const lastMessage = chat[chat.length - 1];
4421- const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
4422- shouldDeleteMessage && await deleteLastMessage();
44234420 const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
44244421 if (invocationResult.hadToolCalls) {
4422+ const lastMessage = chat[chat.length - 1];
4423+ const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
4424+ shouldDeleteMessage && await deleteLastMessage();
44254425 if (!invocationResult.invocations.length && shouldDeleteMessage) {
44264426 ToolManager.showToolCallError(invocationResult.errors);
44274427 unblockGeneration(type);
@@ -4511,10 +4511,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
45114511 }
45124512
45134513 if (canPerformToolCalls) {
4514- const shouldDeleteMessage = ['', '...'].includes(getMessage);
4515- shouldDeleteMessage && await deleteLastMessage();
45164514 const invocationResult = await ToolManager.invokeFunctionTools(data);
45174515 if (invocationResult.hadToolCalls) {
4516+ const shouldDeleteMessage = ['', '...'].includes(getMessage);
4517+ shouldDeleteMessage && await deleteLastMessage();
45184518 if (!invocationResult.invocations.length && shouldDeleteMessage) {
45194519 ToolManager.showToolCallError(invocationResult.errors);
45204520 unblockGeneration(type);