From 0b1abf164345f774e17c2cbe2c5190c70b4ce597 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 13 Dec 2023 15:35:35 -0800 Subject: [PATCH 1/5] chore: commented code removed --- src/routes/(app)/+page.svelte | 31 ---------------------------- src/routes/(app)/c/[id]/+page.svelte | 31 ---------------------------- 2 files changed, 62 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index c0d210fc..3fbb700a 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -106,7 +106,6 @@ const sendPromptOllama = async (model, userPrompt, parentId, _chatId) => { console.log('sendPromptOllama'); let responseMessageId = uuidv4(); - let responseMessage = { parentId: parentId, id: responseMessageId, @@ -126,38 +125,8 @@ } await tick(); - window.scrollTo({ top: document.body.scrollHeight }); - // const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, { - // method: 'POST', - // headers: { - // 'Content-Type': 'text/event-stream', - // ...($settings.authHeader && { Authorization: $settings.authHeader }), - // ...($user && { Authorization: `Bearer ${localStorage.token}` }) - // }, - // body: JSON.stringify({ - // model: model, - // prompt: userPrompt, - // system: $settings.system ?? undefined, - // options: { - // seed: $settings.seed ?? undefined, - // temperature: $settings.temperature ?? undefined, - // repeat_penalty: $settings.repeat_penalty ?? undefined, - // top_k: $settings.top_k ?? undefined, - // top_p: $settings.top_p ?? undefined, - // num_ctx: $settings.num_ctx ?? undefined, - // ...($settings.options ?? {}) - // }, - // format: $settings.requestFormat ?? undefined, - // context: - // history.messages[parentId] !== null && - // history.messages[parentId].parentId in history.messages - // ? history.messages[history.messages[parentId].parentId]?.context ?? undefined - // : undefined - // }) - // }); - const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/chat`, { method: 'POST', headers: { diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index fd61a4dc..18990997 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -133,7 +133,6 @@ const sendPromptOllama = async (model, userPrompt, parentId, _chatId) => { console.log('sendPromptOllama'); let responseMessageId = uuidv4(); - let responseMessage = { parentId: parentId, id: responseMessageId, @@ -153,38 +152,8 @@ } await tick(); - window.scrollTo({ top: document.body.scrollHeight }); - // const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/generate`, { - // method: 'POST', - // headers: { - // 'Content-Type': 'text/event-stream', - // ...($settings.authHeader && { Authorization: $settings.authHeader }), - // ...($user && { Authorization: `Bearer ${localStorage.token}` }) - // }, - // body: JSON.stringify({ - // model: model, - // prompt: userPrompt, - // system: $settings.system ?? undefined, - // options: { - // seed: $settings.seed ?? undefined, - // temperature: $settings.temperature ?? undefined, - // repeat_penalty: $settings.repeat_penalty ?? undefined, - // top_k: $settings.top_k ?? undefined, - // top_p: $settings.top_p ?? undefined, - // num_ctx: $settings.num_ctx ?? undefined, - // ...($settings.options ?? {}) - // }, - // format: $settings.requestFormat ?? undefined, - // context: - // history.messages[parentId] !== null && - // history.messages[parentId].parentId in history.messages - // ? history.messages[history.messages[parentId].parentId]?.context ?? undefined - // : undefined - // }) - // }); - const res = await fetch(`${$settings?.API_BASE_URL ?? OLLAMA_API_BASE_URL}/chat`, { method: 'POST', headers: { From 9b12cdcf83f36b65c33989915667c9c4298d3bc8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 13 Dec 2023 16:21:50 -0800 Subject: [PATCH 2/5] 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}