From 421834b2de287b8d5291d4b695ba6ed4528a5e7f Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 26 Jul 2026 17:51:49 -0400 Subject: [PATCH] refac --- .../Settings/Advanced/AdvancedParams.svelte | 543 ++++-------------- src/lib/components/common/Textarea.svelte | 16 +- 2 files changed, 114 insertions(+), 445 deletions(-) diff --git a/src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte b/src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte index a36ccfd2e6..d49091f6f2 100644 --- a/src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte +++ b/src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte @@ -3,9 +3,11 @@ import Textarea from '$lib/components/common/Textarea.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte'; import Plus from '$lib/components/icons/Plus.svelte'; + import type { i18n as i18nType } from 'i18next'; import { getContext } from 'svelte'; + import type { Writable } from 'svelte/store'; - const i18n = getContext('i18n'); + const i18n = getContext>('i18n'); export let onChange: (params: any) => void = () => {}; @@ -48,13 +50,49 @@ num_thread: null, num_gpu: null }; + type RangeParamKey = keyof typeof defaultParams; - export let params = defaultParams; + export let params: any = defaultParams; $: if (params) { onChange(params); } +{#snippet rangeParam( + key: RangeParamKey, + label: string, + min: number, + max: number, + rangeStep: number | string, + numberStep: number | string = 'any', + numberMax: number | undefined = max +)} +
+
+ +
+
+ +
+
+{/snippet} +
{#if (params?.stream_delta_chunk_size ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam( + 'stream_delta_chunk_size', + $i18n.t('Stream Delta Chunk Size'), + 1, + 128, + 1, + 'any', + undefined + )} {/if}
@@ -187,6 +212,7 @@ {#if (params?.temperature ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('temperature', $i18n.t('Temperature'), 0, 2, 0.05)} {/if} @@ -479,6 +487,7 @@ {#if (params?.max_tokens ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('max_tokens', 'max_tokens', -2, 131072, 1, 1, undefined)} {/if} @@ -617,29 +606,7 @@ {#if (params?.top_k ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('top_k', 'top_k', 0, 1000, 0.5, 'any', 100)} {/if} @@ -673,29 +640,7 @@ {#if (params?.top_p ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('top_p', 'top_p', 0, 1, 0.05)} {/if} @@ -728,29 +673,7 @@ {#if (params?.min_p ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('min_p', 'min_p', 0, 1, 0.05)} {/if} @@ -784,29 +707,7 @@ {#if (params?.frequency_penalty ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('frequency_penalty', 'frequency_penalty', -2, 2, 0.05)} {/if} @@ -840,29 +741,7 @@ {#if (params?.presence_penalty ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('presence_penalty', 'presence_penalty', -2, 2, 0.05)} {/if} @@ -893,29 +772,7 @@ {#if (params?.mirostat ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('mirostat', 'mirostat', 0, 2, 1, 1)} {/if} @@ -948,29 +805,7 @@ {#if (params?.mirostat_eta ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('mirostat_eta', 'mirostat_eta', 0, 1, 0.05)} {/if} @@ -1004,29 +839,7 @@ {#if (params?.mirostat_tau ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('mirostat_tau', 'mirostat_tau', 0, 10, 0.5)} {/if} @@ -1058,29 +871,7 @@ {#if (params?.repeat_last_n ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('repeat_last_n', 'repeat_last_n', -1, 128, 1, 1)} {/if} @@ -1114,29 +905,7 @@ {#if (params?.tfs_z ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('tfs_z', 'tfs_z', 0, 2, 0.05)} {/if} @@ -1170,29 +939,7 @@ {#if (params?.repeat_penalty ?? null) !== null} -
-
- -
-
- -
-
+ {@render rangeParam('repeat_penalty', 'repeat_penalty', -2, 2, 0.05)} {/if} @@ -1231,7 +978,7 @@ {params.use_mmap ? $i18n.t('Enabled') : $i18n.t('Disabled')}
- +
{/if} @@ -1273,7 +1020,7 @@
- +
{/if} @@ -1326,6 +1073,7 @@