From 81d54b46bd69c992ffc44d49df6df913428b2ccd Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 27 Oct 2023 23:26:01 -0700 Subject: [PATCH] feat: message edit --- src/routes/+page.svelte | 103 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 99 insertions(+), 4 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 513a10d4e..8d8d9946f 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -260,6 +260,37 @@ showSettings = true; }; + const editMessage = async (messageIdx) => { + messages = messages.map((message, idx) => { + if (messageIdx === idx) { + message.edit = true; + message.editedContent = message.content; + } + return message; + }); + }; + + const confirmEditMessage = async (messageIdx) => { + let user_prompt = messages.at(messageIdx).editedContent; + + messages.splice(messageIdx, messages.length - messageIdx); + messages = messages; + + await submitPrompt(user_prompt); + }; + + const cancelEditMessage = (messageIdx) => { + messages = messages.map((message, idx) => { + if (messageIdx === idx) { + message.edit = undefined; + message.editedContent = undefined; + } + return message; + }); + + console.log(messages); + }; + ////////////////////////// // Ollama functions ////////////////////////// @@ -633,7 +664,7 @@ {:else} {#each messages as message, messageIdx}
-
+
{:else}
- {@html marked.parse(message.content)} + {#if message.role == 'user'} + {#if message?.edit === true} +
+