From c8f44b73f1fe17274c0259658922ac21b5916ee0 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Fri, 2 Aug 2024 17:36:16 +0200 Subject: [PATCH] refac: user valves save handler --- src/lib/components/chat/Chat.svelte | 4 ---- src/lib/components/chat/ChatControls.svelte | 4 ---- .../components/chat/Controls/Controls.svelte | 1 - .../components/chat/Controls/Valves.svelte | 22 ++++++++++++++++++- src/lib/components/common/Valves.svelte | 18 +++++++++++++-- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 24e74e695..53e3b2721 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -109,7 +109,6 @@ }; let params = {}; - let valves = {}; $: if (history.currentId !== null) { let _messages = []; @@ -812,7 +811,6 @@ keep_alive: $settings.keepAlive ?? undefined, tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined, files: files.length > 0 ? files : undefined, - ...(Object.keys(valves).length ? { valves } : {}), session_id: $socket?.id, chat_id: $chatId, id: responseMessageId @@ -1112,7 +1110,6 @@ max_tokens: params?.max_tokens ?? $settings?.params?.max_tokens ?? undefined, tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined, files: files.length > 0 ? files : undefined, - ...(Object.keys(valves).length ? { valves } : {}), session_id: $socket?.id, chat_id: $chatId, id: responseMessageId @@ -1639,7 +1636,6 @@ bind:show={showControls} bind:chatFiles bind:params - bind:valves /> {/if} diff --git a/src/lib/components/chat/ChatControls.svelte b/src/lib/components/chat/ChatControls.svelte index f67e6d6ef..3de095b0d 100644 --- a/src/lib/components/chat/ChatControls.svelte +++ b/src/lib/components/chat/ChatControls.svelte @@ -9,9 +9,7 @@ export let models = []; export let chatId = null; - export let chatFiles = []; - export let valves = {}; export let params = {}; let largeScreen = false; @@ -50,7 +48,6 @@ }} {models} bind:chatFiles - bind:valves bind:params /> @@ -66,7 +63,6 @@ }} {models} bind:chatFiles - bind:valves bind:params /> diff --git a/src/lib/components/chat/Controls/Controls.svelte b/src/lib/components/chat/Controls/Controls.svelte index abecb6a0b..69034a305 100644 --- a/src/lib/components/chat/Controls/Controls.svelte +++ b/src/lib/components/chat/Controls/Controls.svelte @@ -12,7 +12,6 @@ export let models = []; export let chatFiles = []; - export let valves = {}; export let params = {}; diff --git a/src/lib/components/chat/Controls/Valves.svelte b/src/lib/components/chat/Controls/Valves.svelte index 1b2edbb16..17efc019f 100644 --- a/src/lib/components/chat/Controls/Valves.svelte +++ b/src/lib/components/chat/Controls/Valves.svelte @@ -31,6 +31,20 @@ let valvesSpec = null; let valves = {}; + let debounceTimer; + + const debounceSubmitHandler = async () => { + // debounce 1 second + if (debounceTimer) { + clearTimeout(debounceTimer); + } + + // Set a new timer + debounceTimer = setTimeout(() => { + submitHandler(); + }, 1000); // 1 second debounce + }; + const getUserValves = async () => { loading = true; if (tab === 'tools') { @@ -157,7 +171,13 @@
{#if !loading} - + { + debounceSubmitHandler(); + }} + /> {:else} {/if} diff --git a/src/lib/components/common/Valves.svelte b/src/lib/components/common/Valves.svelte index 6de35a83b..cf138082f 100644 --- a/src/lib/components/common/Valves.svelte +++ b/src/lib/components/common/Valves.svelte @@ -1,5 +1,6 @@