diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index df1328d50..b5db7d078 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -483,11 +483,12 @@ } } + await tick(); + if ($chatId == chatId) { if (!$temporaryChatEnabled) { chat = await updateChatById(localStorage.token, chatId, { models: selectedModels, - messages: messages, history: history, params: params, files: chatFiles @@ -1134,13 +1135,6 @@ } } } - - await chatCompletedHandler( - _chatId, - model.id, - responseMessageId, - createMessagesList(responseMessageId) - ); } else { if (res !== null) { const error = await res.json(); @@ -1169,11 +1163,18 @@ (status) => status.action !== 'knowledge_search' ); } - - history.messages[responseMessageId] = responseMessage; } await saveChatHandler(_chatId); + history.messages[responseMessageId] = responseMessage; + + await chatCompletedHandler( + _chatId, + model.id, + responseMessageId, + createMessagesList(responseMessageId) + ); + stopResponseFlag = false; await tick(); @@ -1430,13 +1431,6 @@ } } - await chatCompletedHandler( - _chatId, - model.id, - responseMessageId, - createMessagesList(responseMessageId) - ); - if ($settings.notificationEnabled && !document.hasFocus()) { const notification = new Notification(`${model.id}`, { body: responseMessage.content, @@ -1464,6 +1458,13 @@ history.messages[responseMessageId] = responseMessage; + await chatCompletedHandler( + _chatId, + model.id, + responseMessageId, + createMessagesList(responseMessageId) + ); + stopResponseFlag = false; await tick();