Fix duplicate CHARACTER_MESSAGE_RENDERED events during streaming (#4584) Refer to line 5771, where is correct, but the branch is not added, resulting in the branch being triggered once here when the streaming is completed, and finally the streaming is triggered again. In fact, it should not be triggered here

58a294639a2a40886bb0fe04caf733f09280ab0d

shanmaocc <47207787+shanmaocc@users.noreply.github.com>

Signed
1 files changed, +6 -6Showing whitespace changes
public/script.js+6 -6
@@ -5719,9 +5719,9 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
5719 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);5719 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
5720 }5720 }
5721 const chat_id = (chat.length - 1);5721 const chat_id = (chat.length - 1);
5722 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);5722 !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
5723 addOneMessage(chat[chat_id], { type: 'swipe' });5723 addOneMessage(chat[chat_id], { type: 'swipe' });
5724 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);5724 !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
5725 } else {5725 } else {
5726 chat[chat.length - 1]['mes'] = getMessage;5726 chat[chat.length - 1]['mes'] = getMessage;
5727 }5727 }
@@ -5743,9 +5743,9 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
5743 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);5743 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
5744 }5744 }
5745 const chat_id = (chat.length - 1);5745 const chat_id = (chat.length - 1);
5746 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);5746 !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
5747 addOneMessage(chat[chat_id], { type: 'swipe' });5747 addOneMessage(chat[chat_id], { type: 'swipe' });
5748 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);5748 !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
5749 } else if (type === 'appendFinal') {5749 } else if (type === 'appendFinal') {
5750 oldMessage = chat[chat.length - 1]['mes'];5750 oldMessage = chat[chat.length - 1]['mes'];
5751 console.debug('Trying to appendFinal.');5751 console.debug('Trying to appendFinal.');
@@ -5764,9 +5764,9 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title
5764 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);5764 chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0);
5765 }5765 }
5766 const chat_id = (chat.length - 1);5766 const chat_id = (chat.length - 1);
5767 await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);5767 !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type);
5768 addOneMessage(chat[chat_id], { type: 'swipe' });5768 addOneMessage(chat[chat_id], { type: 'swipe' });
5769 await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);5769 !fromStreaming && await eventSource.emit(event_types.CHARACTER_MESSAGE_RENDERED, chat_id, type);
57705770
5771 } else {5771 } else {
5772 console.debug('entering chat update routine for non-swipe post');5772 console.debug('entering chat update routine for non-swipe post');