From a655ccdd06aa9b0ebcb270b789589eba920c7098 Mon Sep 17 00:00:00 2001 From: Danny Liu Date: Tue, 20 Feb 2024 16:35:44 -0800 Subject: [PATCH] only cancel chat completion if the deleted message is the most recently sent --- src/lib/components/chat/Messages.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/components/chat/Messages.svelte b/src/lib/components/chat/Messages.svelte index e8b9a80f..6bb84069 100644 --- a/src/lib/components/chat/Messages.svelte +++ b/src/lib/components/chat/Messages.svelte @@ -227,9 +227,13 @@ history.messages[messageId].deleted = true; history.messages[history.messages[messageId].childrenIds[0]].deleted = true; + const responseId = history.messages[messageId].childrenIds[0]; + if (history.messages[responseId].childrenIds.length === 0) { + await cancelChatCompletion(localStorage.token, chatId); + } + await updateChatById(localStorage.token, chatId, { history }); await chats.set(await getChatList(localStorage.token)); - await cancelChatCompletion(localStorage.token, chatId); };