Fix ghost messages

This commit is contained in:
Cohee
2024-10-04 23:13:56 +03:00
parent 8ff9ef3610
commit 01fc5113d7
2 changed files with 19 additions and 11 deletions

View File

@ -4418,11 +4418,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 hasToolCalls = ToolManager.hasToolCalls(streamingProcessor.toolCalls);
const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor?.result);
hasToolCalls && 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 (hasToolCalls) {
if (!invocationResult.invocations.length && shouldDeleteMessage) {
ToolManager.showToolCallError(invocationResult.errors);
unblockGeneration(type);
@ -4512,10 +4513,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro
}
if (canPerformToolCalls) {
const hasToolCalls = ToolManager.hasToolCalls(data);
const shouldDeleteMessage = ['', '...'].includes(getMessage);
hasToolCalls && shouldDeleteMessage && await deleteLastMessage();
const invocationResult = await ToolManager.invokeFunctionTools(data);
if (invocationResult.hadToolCalls) {
const shouldDeleteMessage = ['', '...'].includes(getMessage);
shouldDeleteMessage && await deleteLastMessage();
if (hasToolCalls) {
if (!invocationResult.invocations.length && shouldDeleteMessage) {
ToolManager.showToolCallError(invocationResult.errors);
unblockGeneration(type);