Delete empty message before tool invocations

2dad86e0769f803f674995a3b15ca48369144c36

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

1 files changed, +6 -8Ignore whitespace
public/script.js+6 -8
@@ -4409,14 +4409,12 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
44094409 }
44104410
44114411 if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) {
4412+ const lastMessage = chat[chat.length - 1];
4413+ const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
4414+ shouldDeleteMessage && await deleteLastMessage();
44124415 const invocations = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
44134416 if (Array.isArray(invocations) && invocations.length) {
4414- const lastMessage = chat[chat.length - 1];
4417+ streamingProcessor = null;
4415- const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
4416- if (shouldDeleteMessage) {
4417- await deleteLastMessage();
4418- streamingProcessor = null;
4419- }
44204418 ToolManager.saveFunctionToolInvocations(invocations);
44214419 return Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName }, dryRun);
44224420 }
@@ -4497,10 +4495,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
44974495 }
44984496
44994497 if (canPerformToolCalls) {
4498+ const shouldDeleteMessage = ['', '...'].includes(getMessage);
4499+ shouldDeleteMessage && await deleteLastMessage();
45004500 const invocations = await ToolManager.invokeFunctionTools(data);
45014501 if (Array.isArray(invocations) && invocations.length) {
4502- const shouldDeleteMessage = ['', '...'].includes(getMessage);
4503- shouldDeleteMessage && await deleteLastMessage();
45044502 ToolManager.saveFunctionToolInvocations(invocations);
45054503 return Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName }, dryRun);
45064504 }