From 30e2ec75446ca9148e5ea3da242a47fc79765911 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Mon, 8 Jul 2024 19:26:31 -0700 Subject: [PATCH] feat: chat controls integration --- src/lib/components/chat/Chat.svelte | 64 ++++++++++--------- src/lib/components/chat/ChatControls.svelte | 10 ++- .../components/chat/Controls/Controls.svelte | 55 +++++++++++----- .../Settings/Advanced/AdvancedParams.svelte | 38 +++++------ src/lib/components/common/Modal.svelte | 2 +- .../components/common/Tags/TagInput.svelte | 2 +- 6 files changed, 102 insertions(+), 69 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 56659652f..2d31b1462 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -97,6 +97,8 @@ currentId: null }; + let params = {}; + $: if (history.currentId !== null) { let _messages = []; @@ -230,6 +232,7 @@ messages: {}, currentId: null }; + params = {}; if ($page.url.searchParams.get('models')) { selectedModels = $page.url.searchParams.get('models')?.split(','); @@ -299,11 +302,7 @@ await settings.set(JSON.parse(localStorage.getItem('settings') ?? '{}')); } - await settings.set({ - ...$settings, - system: chatContent.system ?? $settings.system, - params: chatContent.options ?? $settings.params - }); + params = chatContent?.params ?? {}; autoScroll = true; await tick(); @@ -516,9 +515,7 @@ title: $i18n.t('New Chat'), models: selectedModels, system: $settings.system ?? undefined, - options: { - ...($settings.params ?? {}) - }, + params: params, messages: messages, history: history, tags: [], @@ -616,11 +613,11 @@ scrollToBottom(); const messagesBody = [ - $settings.system || (responseMessage?.userContext ?? null) + params?.system || $settings.system || (responseMessage?.userContext ?? null) ? { role: 'system', content: `${promptTemplate( - $settings?.system ?? '', + params?.system ?? $settings?.system ?? '', $user.name, $settings?.userLocation ? await getAndUpdateUserLocation(localStorage.token) @@ -705,15 +702,16 @@ model: model.id, messages: messagesBody, options: { - ...($settings.params ?? {}), + ...(params ?? $settings.params ?? {}), stop: - $settings?.params?.stop ?? undefined - ? $settings.params.stop.map((str) => + params?.stop ?? $settings?.params?.stop ?? undefined + ? (params?.stop ?? $settings.params.stop).map((str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) ) : undefined, - num_predict: $settings?.params?.max_tokens ?? undefined, - repeat_penalty: $settings?.params?.frequency_penalty ?? undefined + num_predict: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined, + repeat_penalty: + params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined }, format: $settings.requestFormat ?? undefined, keep_alive: $settings.keepAlive ?? undefined, @@ -849,7 +847,8 @@ chat = await updateChatById(localStorage.token, _chatId, { messages: messages, history: history, - models: selectedModels + models: selectedModels, + params: params }); await chats.set(await getChatList(localStorage.token)); } @@ -959,11 +958,11 @@ } : undefined, messages: [ - $settings.system || (responseMessage?.userContext ?? null) + params?.system || $settings.system || (responseMessage?.userContext ?? null) ? { role: 'system', content: `${promptTemplate( - $settings?.system ?? '', + params?.system ?? $settings?.system ?? '', $user.name, $settings?.userLocation ? await getAndUpdateUserLocation(localStorage.token) @@ -1008,17 +1007,18 @@ : message?.raContent ?? message.content }) })), - seed: $settings?.params?.seed ?? undefined, + seed: params?.seed ?? $settings?.params?.seed ?? undefined, stop: - $settings?.params?.stop ?? undefined - ? $settings.params.stop.map((str) => + params?.stop ?? $settings?.params?.stop ?? undefined + ? (params?.stop ?? $settings.params.stop).map((str) => decodeURIComponent(JSON.parse('"' + str.replace(/\"/g, '\\"') + '"')) ) : undefined, - temperature: $settings?.params?.temperature ?? undefined, - top_p: $settings?.params?.top_p ?? undefined, - frequency_penalty: $settings?.params?.frequency_penalty ?? undefined, - max_tokens: $settings?.params?.max_tokens ?? undefined, + temperature: params?.temperature ?? $settings?.params?.temperature ?? undefined, + top_p: params?.top_p ?? $settings?.params?.top_p ?? undefined, + frequency_penalty: + params?.frequency_penalty ?? $settings?.params?.frequency_penalty ?? undefined, + max_tokens: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined, tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined, files: files.length > 0 ? files : undefined, session_id: $socket?.id, @@ -1124,7 +1124,8 @@ chat = await updateChatById(localStorage.token, _chatId, { models: selectedModels, messages: messages, - history: history + history: history, + params: params }); await chats.set(await getChatList(localStorage.token)); } @@ -1460,9 +1461,11 @@ {/if} -
+
-
+
- + +
{/if} diff --git a/src/lib/components/chat/ChatControls.svelte b/src/lib/components/chat/ChatControls.svelte index da84ece01..4e0b9293a 100644 --- a/src/lib/components/chat/ChatControls.svelte +++ b/src/lib/components/chat/ChatControls.svelte @@ -6,8 +6,10 @@ export let show = false; - let largeScreen = false; + export let chatId = null; + export let params = {}; + let largeScreen = false; onMount(() => { // listen to resize 1024px const mediaQuery = window.matchMedia('(min-width: 1024px)'); @@ -35,12 +37,13 @@
{ show = false; }} + bind:params />
@@ -48,11 +51,12 @@ {/if} {:else} -
+
{ show = false; }} + bind:params />
diff --git a/src/lib/components/chat/Controls/Controls.svelte b/src/lib/components/chat/Controls/Controls.svelte index 96ddf8389..9433e46f5 100644 --- a/src/lib/components/chat/Controls/Controls.svelte +++ b/src/lib/components/chat/Controls/Controls.svelte @@ -1,24 +1,49 @@
-
-
Chat Controls
- -
- -
+
+
{$i18n.t('Chat Controls')}
+
-
coming soon
+
+
+
System Prompt
+ +
+