mirror of
https://github.com/open-webui/open-webui
synced 2025-03-20 20:08:52 +00:00
refac: user valves save handler
This commit is contained in:
parent
bf6b149b8b
commit
c8f44b73f1
@ -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
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
@ -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
|
||||
/>
|
||||
</div>
|
||||
@ -66,7 +63,6 @@
|
||||
}}
|
||||
{models}
|
||||
bind:chatFiles
|
||||
bind:valves
|
||||
bind:params
|
||||
/>
|
||||
</div>
|
||||
|
@ -12,7 +12,6 @@
|
||||
export let models = [];
|
||||
|
||||
export let chatFiles = [];
|
||||
export let valves = {};
|
||||
export let params = {};
|
||||
</script>
|
||||
|
||||
|
@ -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 @@
|
||||
|
||||
<div class="my-2 text-xs">
|
||||
{#if !loading}
|
||||
<Valves {valvesSpec} bind:valves />
|
||||
<Valves
|
||||
{valvesSpec}
|
||||
bind:valves
|
||||
on:change={() => {
|
||||
debounceSubmitHandler();
|
||||
}}
|
||||
/>
|
||||
{:else}
|
||||
<Spinner className="size-5" />
|
||||
{/if}
|
||||
|
@ -1,5 +1,6 @@
|
||||
<script>
|
||||
import { onMount, getContext } from 'svelte';
|
||||
import { onMount, getContext, createEventDispatcher } from 'svelte';
|
||||
const dispatch = createEventDispatcher();
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import Switch from './Switch.svelte';
|
||||
@ -28,6 +29,8 @@
|
||||
(valves[property] ?? null) === null
|
||||
? valvesSpec.properties[property]?.default ?? ''
|
||||
: null;
|
||||
|
||||
dispatch('change');
|
||||
}}
|
||||
>
|
||||
{#if (valves[property] ?? null) === null}
|
||||
@ -52,6 +55,9 @@
|
||||
<select
|
||||
class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none border border-gray-100 dark:border-gray-800"
|
||||
bind:value={valves[property]}
|
||||
on:change={() => {
|
||||
dispatch('change');
|
||||
}}
|
||||
>
|
||||
{#each valvesSpec.properties[property].enum as option}
|
||||
<option value={option} selected={option === valves[property]}>
|
||||
@ -66,7 +72,12 @@
|
||||
</div>
|
||||
|
||||
<div class=" pr-2">
|
||||
<Switch bind:state={valves[property]} />
|
||||
<Switch
|
||||
bind:state={valves[property]}
|
||||
on:change={() => {
|
||||
dispatch('change');
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
@ -77,6 +88,9 @@
|
||||
bind:value={valves[property]}
|
||||
autocomplete="off"
|
||||
required
|
||||
on:change={() => {
|
||||
dispatch('change');
|
||||
}}
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user