From 2dad86e0769f803f674995a3b15ca48369144c36 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:12:49 +0300 Subject: [PATCH] Delete empty message before tool invocations --- public/script.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/public/script.js b/public/script.js index c3aa593e8..3a38a04a9 100644 --- a/public/script.js +++ b/public/script.js @@ -4409,14 +4409,12 @@ 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 invocations = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls); if (Array.isArray(invocations) && invocations.length) { - const lastMessage = chat[chat.length - 1]; - const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result); - if (shouldDeleteMessage) { - await deleteLastMessage(); - streamingProcessor = null; - } + streamingProcessor = null; ToolManager.saveFunctionToolInvocations(invocations); return Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName }, dryRun); } @@ -4497,10 +4495,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro } if (canPerformToolCalls) { + const shouldDeleteMessage = ['', '...'].includes(getMessage); + shouldDeleteMessage && await deleteLastMessage(); const invocations = await ToolManager.invokeFunctionTools(data); if (Array.isArray(invocations) && invocations.length) { - const shouldDeleteMessage = ['', '...'].includes(getMessage); - shouldDeleteMessage && await deleteLastMessage(); ToolManager.saveFunctionToolInvocations(invocations); return Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName }, dryRun); }