Only delete message if had successful tool calls
| @@ -4417,11 +4417,11 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4417 | 4417 | } |
| 4418 | 4418 | |
| 4419 | 4419 | if (canPerformToolCalls && Array.isArray(streamingProcessor.toolCalls) && streamingProcessor.toolCalls.length) { |
| 4420 | + const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls); | |
| 4421 | + if (invocationResult.hadToolCalls) { | |
| 4420 | 4422 | const lastMessage = chat[chat.length - 1]; |
| 4421 | 4423 | const shouldDeleteMessage = ['', '...'].includes(lastMessage?.mes) && ['', '...'].includes(streamingProcessor.result); |
| 4422 | 4424 | shouldDeleteMessage && await deleteLastMessage(); |
| 4423 | - const invocationResult = await ToolManager.invokeFunctionTools(streamingProcessor.toolCalls); | |
| 4424 | - if (invocationResult.hadToolCalls) { | |
| 4425 | 4425 | if (!invocationResult.invocations.length && shouldDeleteMessage) { |
| 4426 | 4426 | ToolManager.showToolCallError(invocationResult.errors); |
| 4427 | 4427 | unblockGeneration(type); |
| @@ -4511,10 +4511,10 @@ export async function Generate(type, { automatic_trigger, force_name2, quiet_pro | ||
| 4511 | 4511 | } |
| 4512 | 4512 | |
| 4513 | 4513 | if (canPerformToolCalls) { |
| 4514 | - const shouldDeleteMessage = ['', '...'].includes(getMessage); | |
| 4515 | - shouldDeleteMessage && await deleteLastMessage(); | |
| 4516 | 4514 | const invocationResult = await ToolManager.invokeFunctionTools(data); |
| 4517 | 4515 | if (invocationResult.hadToolCalls) { |
| 4516 | + const shouldDeleteMessage = ['', '...'].includes(getMessage); | |
| 4517 | + shouldDeleteMessage && await deleteLastMessage(); | |
| 4518 | 4518 | if (!invocationResult.invocations.length && shouldDeleteMessage) { |
| 4519 | 4519 | ToolManager.showToolCallError(invocationResult.errors); |
| 4520 | 4520 | unblockGeneration(type); |