From 9b12cdcf83f36b65c33989915667c9c4298d3bc8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 13 Dec 2023 16:21:50 -0800 Subject: [PATCH] feat: image upload support --- src/lib/components/chat/MessageInput.svelte | 63 +++++++++++---------- src/lib/components/chat/Messages.svelte | 38 +++++++++---- src/routes/(app)/+page.svelte | 17 +++++- src/routes/(app)/c/[id]/+page.svelte | 23 ++++---- 4 files changed, 84 insertions(+), 57 deletions(-) diff --git a/src/lib/components/chat/MessageInput.svelte b/src/lib/components/chat/MessageInput.svelte index 015e6e3a..bc3a6a9d 100644 --- a/src/lib/components/chat/MessageInput.svelte +++ b/src/lib/components/chat/MessageInput.svelte @@ -14,7 +14,7 @@ export let files = []; - export let fileUploadEnabled = false; + export let fileUploadEnabled = true; export let speechRecognitionEnabled = true; export let speechRecognitionListening = false; @@ -84,40 +84,40 @@ }; -
-
-
- {#if messages.length == 0 && suggestionPrompts.length !== 0} +
+
+ {#if messages.length == 0 && suggestionPrompts.length !== 0} +
- {/if} +
+ {/if} - {#if autoScroll === false && messages.length > 0} -
- -
- {/if} -
+ + + +
+ {/if}
-
+
{ + await tick(); + window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' }); + })(); + } + const speakMessage = (message) => { const speak = new SpeechSynthesisUtterance(message); speechSynthesis.speak(speak); @@ -184,7 +192,8 @@ parentId: history.messages[messageId].parentId, childrenIds: [], role: 'user', - content: userPrompt + content: userPrompt, + ...(history.messages[messageId].files && { files: history.messages[messageId].files }) }; let messageParentId = history.messages[messageId].parentId; @@ -425,6 +434,18 @@ class="prose chat-{message.role} w-full max-w-full dark:prose-invert prose-headings:my-0 prose-p:my-0 prose-p:-mb-4 prose-pre:my-0 prose-table:my-0 prose-blockquote:my-0 prose-img:my-0 prose-ul:-my-4 prose-ol:-my-4 prose-li:-my-3 prose-ul:-mb-6 prose-ol:-mb-6 prose-li:-mb-4 whitespace-pre-line" > {#if message.role == 'user'} + {#if message.files} +
+ {#each message.files as file} +
+ {#if file.type === 'image'} + input + {/if} +
+ {/each} +
+ {/if} + {#if message?.edit === true}