From e3ec631ea6cd0b11f4224982cef1385edad329b7 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Wed, 13 Dec 2023 16:34:13 -0800 Subject: [PATCH] feat: openai multimodal support --- src/routes/(app)/+page.svelte | 22 +++++++++++++++++++- src/routes/(app)/c/[id]/+page.svelte | 31 +++++++++++++++++++++------- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 88cbb6ba..7c0c87b4 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -331,7 +331,27 @@ ...messages ] .filter((message) => message) - .map((message) => ({ role: message.role, content: message.content })), + .map((message) => ({ + role: message.role, + ...(message.files + ? { + content: [ + { + type: 'text', + text: message.content + }, + ...message.files + .filter((file) => file.type === 'image') + .map((file) => ({ + type: 'image_url', + image_url: { + url: file.url + } + })) + ] + } + : { content: message.content }) + })), temperature: $settings.temperature ?? undefined, top_p: $settings.top_p ?? undefined, num_ctx: $settings.num_ctx ?? undefined, diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index ff711e8e..f108ba22 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -343,7 +343,27 @@ ...messages ] .filter((message) => message) - .map((message) => ({ role: message.role, content: message.content })), + .map((message) => ({ + role: message.role, + ...(message.files + ? { + content: [ + { + type: 'text', + text: message.content + }, + ...message.files + .filter((file) => file.type === 'image') + .map((file) => ({ + type: 'image_url', + image_url: { + url: file.url + } + })) + ] + } + : { content: message.content }) + })), temperature: $settings.temperature ?? undefined, top_p: $settings.top_p ?? undefined, num_ctx: $settings.num_ctx ?? undefined, @@ -358,12 +378,9 @@ while (true) { const { value, done } = await reader.read(); - if (done || stopResponseFlag) { - if (stopResponseFlag) { - responseMessage.done = true; - messages = messages; - } - + if (done || stopResponseFlag || _chatId !== $chatId) { + responseMessage.done = true; + messages = messages; break; }