Delete empty message before tool invocations

2dad86e0769f803f674995a3b15ca48369144c36

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

1 files changed, +5 -7Showing whitespace changes
public/script.js+5 -7
@@ -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 invocations = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
4413- if (Array.isArray(invocations) && invocations.length) {
44144412 const lastMessage = chat[chat.length - 1];
44154413 const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result);
4416- if (shouldDeleteMessage) {
4414+ shouldDeleteMessage && await deleteLastMessage();
4417- await deleteLastMessage();
4415+ const invocations = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls);
4416+ if (Array.isArray(invocations) && invocations.length) {
44184417 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) {
4500- const invocations = await ToolManager.invokeFunctionTools(data);
4501- if (Array.isArray(invocations) && invocations.length) {
45024498 const shouldDeleteMessage = ['', '...'].includes(getMessage);
45034499 shouldDeleteMessage && await deleteLastMessage();
4500+ const invocations = await ToolManager.invokeFunctionTools(data);
4501+ if (Array.isArray(invocations) && invocations.length) {
45044502 ToolManager.saveFunctionToolInvocations(invocations);
45054503 return Generate(type, { automatic_trigger, force_name2, quiet_prompt, quietToLoud, skipWIAN, force_chid, signal, quietImage, quietName }, dryRun);
45064504 }