From 68104358d0c042abccba0f1a919e407576a7c01f Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sun, 19 May 2024 05:01:29 -0700 Subject: [PATCH] fix: many model regeneration --- .../components/chat/Messages/CompareMessages.svelte | 11 +++++++---- .../components/chat/Messages/ResponseMessage.svelte | 2 +- src/routes/(app)/+page.svelte | 10 ++++------ src/routes/(app)/c/[id]/+page.svelte | 10 ++++------ 4 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/lib/components/chat/Messages/CompareMessages.svelte b/src/lib/components/chat/Messages/CompareMessages.svelte index 0b5d0e464..8ab0a65ba 100644 --- a/src/lib/components/chat/Messages/CompareMessages.svelte +++ b/src/lib/components/chat/Messages/CompareMessages.svelte @@ -58,14 +58,17 @@
-
+
{#each Object.keys(groupedMessages) as model} {#if groupedMessagesIdx[model] !== undefined && groupedMessages[model].messages.length > 0}
{ - regenerateResponse(model); + regenerateResponse={async (message) => { + regenerateResponse(message); await tick(); groupedMessagesIdx[model] = groupedMessages[model].messages.length - 1; }} diff --git a/src/lib/components/chat/Messages/ResponseMessage.svelte b/src/lib/components/chat/Messages/ResponseMessage.svelte index 0b1038bd9..71227989b 100644 --- a/src/lib/components/chat/Messages/ResponseMessage.svelte +++ b/src/lib/components/chat/Messages/ResponseMessage.svelte @@ -895,7 +895,7 @@ ? 'visible' : 'invisible group-hover:visible'} p-1.5 hover:bg-black/5 dark:hover:bg-white/5 rounded-lg dark:hover:text-white hover:text-black transition regenerate-response-button" on:click={() => { - regenerateResponse(message.model); + regenerateResponse(message); }} > { + const regenerateResponse = async (message) => { console.log('regenerateResponse'); - if (messages.length != 0 && messages.at(-1).done == true) { - messages.splice(messages.length - 1, 1); - messages = messages; - let userMessage = messages.at(-1); + if (messages.length != 0) { + let userMessage = history.messages[message.parentId]; let userPrompt = userMessage.content; - await sendPrompt(userPrompt, userMessage.id, modelId); + await sendPrompt(userPrompt, userMessage.id, message.model); } }; diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index 996d37047..b002d9971 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -764,16 +764,14 @@ console.log('stopResponse'); }; - const regenerateResponse = async (modelId = null) => { + const regenerateResponse = async (message) => { console.log('regenerateResponse'); - if (messages.length != 0 && messages.at(-1).done == true) { - messages.splice(messages.length - 1, 1); - messages = messages; - let userMessage = messages.at(-1); + if (messages.length != 0) { + let userMessage = history.messages[message.parentId]; let userPrompt = userMessage.content; - await sendPrompt(userPrompt, userMessage.id, modelId); + await sendPrompt(userPrompt, userMessage.id, message.model); } };