|
@@ -9,6 +9,7 @@
|
|
const i18n = getContext('i18n');
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
import AdvancedParams from './Advanced/AdvancedParams.svelte';
|
|
import AdvancedParams from './Advanced/AdvancedParams.svelte';
|
|
|
|
+ import Textarea from '$lib/components/common/Textarea.svelte';
|
|
|
|
|
|
export let saveSettings: Function;
|
|
export let saveSettings: Function;
|
|
export let getModels: Function;
|
|
export let getModels: Function;
|
|
@@ -40,7 +41,7 @@
|
|
};
|
|
};
|
|
|
|
|
|
// Advanced
|
|
// Advanced
|
|
- let requestFormat = '';
|
|
|
|
|
|
+ let requestFormat = null;
|
|
let keepAlive: string | null = null;
|
|
let keepAlive: string | null = null;
|
|
|
|
|
|
let params = {
|
|
let params = {
|
|
@@ -70,14 +71,74 @@
|
|
num_gpu: null
|
|
num_gpu: null
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+ const validateJSON = (json) => {
|
|
|
|
+ try {
|
|
|
|
+ const obj = JSON.parse(json);
|
|
|
|
+
|
|
|
|
+ if (obj && typeof obj === 'object') {
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+ } catch (e) {}
|
|
|
|
+ return false;
|
|
|
|
+ };
|
|
|
|
+
|
|
const toggleRequestFormat = async () => {
|
|
const toggleRequestFormat = async () => {
|
|
- if (requestFormat === '') {
|
|
|
|
|
|
+ if (requestFormat === null) {
|
|
requestFormat = 'json';
|
|
requestFormat = 'json';
|
|
} else {
|
|
} else {
|
|
- requestFormat = '';
|
|
|
|
|
|
+ requestFormat = null;
|
|
}
|
|
}
|
|
|
|
|
|
- saveSettings({ requestFormat: requestFormat !== '' ? requestFormat : undefined });
|
|
|
|
|
|
+ saveSettings({ requestFormat: requestFormat !== null ? requestFormat : undefined });
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const saveHandler = async () => {
|
|
|
|
+ if (requestFormat !== null && requestFormat !== 'json') {
|
|
|
|
+ if (validateJSON(requestFormat) === false) {
|
|
|
|
+ toast.error($i18n.t('Invalid JSON schema'));
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ requestFormat = JSON.parse(requestFormat);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ saveSettings({
|
|
|
|
+ system: system !== '' ? system : undefined,
|
|
|
|
+ params: {
|
|
|
|
+ stream_response: params.stream_response !== null ? params.stream_response : undefined,
|
|
|
|
+ function_calling: params.function_calling !== null ? params.function_calling : undefined,
|
|
|
|
+ seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
|
|
|
|
+ stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
|
|
|
|
+ temperature: params.temperature !== null ? params.temperature : undefined,
|
|
|
|
+ reasoning_effort: params.reasoning_effort !== null ? params.reasoning_effort : undefined,
|
|
|
|
+ logit_bias: params.logit_bias !== null ? params.logit_bias : undefined,
|
|
|
|
+ frequency_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
+ presence_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
+ repeat_penalty: params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
+ repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
|
|
|
|
+ mirostat: params.mirostat !== null ? params.mirostat : undefined,
|
|
|
|
+ mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
|
|
|
|
+ mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
|
|
|
|
+ top_k: params.top_k !== null ? params.top_k : undefined,
|
|
|
|
+ top_p: params.top_p !== null ? params.top_p : undefined,
|
|
|
|
+ min_p: params.min_p !== null ? params.min_p : undefined,
|
|
|
|
+ tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
|
|
|
|
+ num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
|
|
|
|
+ num_batch: params.num_batch !== null ? params.num_batch : undefined,
|
|
|
|
+ num_keep: params.num_keep !== null ? params.num_keep : undefined,
|
|
|
|
+ max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
|
|
|
|
+ use_mmap: params.use_mmap !== null ? params.use_mmap : undefined,
|
|
|
|
+ use_mlock: params.use_mlock !== null ? params.use_mlock : undefined,
|
|
|
|
+ num_thread: params.num_thread !== null ? params.num_thread : undefined,
|
|
|
|
+ num_gpu: params.num_gpu !== null ? params.num_gpu : undefined
|
|
|
|
+ },
|
|
|
|
+ keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined,
|
|
|
|
+ requestFormat: requestFormat !== null ? requestFormat : undefined
|
|
|
|
+ });
|
|
|
|
+ dispatch('save');
|
|
|
|
+
|
|
|
|
+ requestFormat =
|
|
|
|
+ typeof requestFormat === 'object' ? JSON.stringify(requestFormat, null, 2) : requestFormat;
|
|
};
|
|
};
|
|
|
|
|
|
onMount(async () => {
|
|
onMount(async () => {
|
|
@@ -88,7 +149,12 @@
|
|
notificationEnabled = $settings.notificationEnabled ?? false;
|
|
notificationEnabled = $settings.notificationEnabled ?? false;
|
|
system = $settings.system ?? '';
|
|
system = $settings.system ?? '';
|
|
|
|
|
|
- requestFormat = $settings.requestFormat ?? '';
|
|
|
|
|
|
+ requestFormat = $settings.requestFormat ?? null;
|
|
|
|
+ if (requestFormat !== null && requestFormat !== 'json') {
|
|
|
|
+ requestFormat =
|
|
|
|
+ typeof requestFormat === 'object' ? JSON.stringify(requestFormat, null, 2) : requestFormat;
|
|
|
|
+ }
|
|
|
|
+
|
|
keepAlive = $settings.keepAlive ?? null;
|
|
keepAlive = $settings.keepAlive ?? null;
|
|
|
|
|
|
params = { ...params, ...$settings.params };
|
|
params = { ...params, ...$settings.params };
|
|
@@ -270,7 +336,7 @@
|
|
<AdvancedParams admin={$user?.role === 'admin'} bind:params />
|
|
<AdvancedParams admin={$user?.role === 'admin'} bind:params />
|
|
<hr class=" border-gray-100 dark:border-gray-850" />
|
|
<hr class=" border-gray-100 dark:border-gray-850" />
|
|
|
|
|
|
- <div class=" py-1 w-full justify-between">
|
|
|
|
|
|
+ <div class=" w-full justify-between">
|
|
<div class="flex w-full justify-between">
|
|
<div class="flex w-full justify-between">
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Keep Alive')}</div>
|
|
<div class=" self-center text-xs font-medium">{$i18n.t('Keep Alive')}</div>
|
|
|
|
|
|
@@ -302,8 +368,8 @@
|
|
</div>
|
|
</div>
|
|
|
|
|
|
<div>
|
|
<div>
|
|
- <div class=" py-1 flex w-full justify-between">
|
|
|
|
- <div class=" self-center text-sm font-medium">{$i18n.t('Request Mode')}</div>
|
|
|
|
|
|
+ <div class=" flex w-full justify-between">
|
|
|
|
+ <div class=" self-center text-xs font-medium">{$i18n.t('Request Mode')}</div>
|
|
|
|
|
|
<button
|
|
<button
|
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
|
class="p-1 px-3 text-xs flex rounded-sm transition"
|
|
@@ -311,9 +377,9 @@
|
|
toggleRequestFormat();
|
|
toggleRequestFormat();
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
- {#if requestFormat === ''}
|
|
|
|
|
|
+ {#if requestFormat === null}
|
|
<span class="ml-2 self-center"> {$i18n.t('Default')} </span>
|
|
<span class="ml-2 self-center"> {$i18n.t('Default')} </span>
|
|
- {:else if requestFormat === 'json'}
|
|
|
|
|
|
+ {:else}
|
|
<!-- <svg
|
|
<!-- <svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 20 20"
|
|
viewBox="0 0 20 20"
|
|
@@ -328,6 +394,16 @@
|
|
{/if}
|
|
{/if}
|
|
</button>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
+
|
|
|
|
+ {#if requestFormat !== null}
|
|
|
|
+ <div class="flex mt-1 space-x-2">
|
|
|
|
+ <Textarea
|
|
|
|
+ className="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-hidden"
|
|
|
|
+ placeholder={$i18n.t('e.g. "json" or a JSON schema')}
|
|
|
|
+ bind:value={requestFormat}
|
|
|
|
+ />
|
|
|
|
+ </div>
|
|
|
|
+ {/if}
|
|
</div>
|
|
</div>
|
|
{/if}
|
|
{/if}
|
|
</div>
|
|
</div>
|
|
@@ -338,44 +414,7 @@
|
|
<button
|
|
<button
|
|
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
|
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-900 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full"
|
|
on:click={() => {
|
|
on:click={() => {
|
|
- saveSettings({
|
|
|
|
- system: system !== '' ? system : undefined,
|
|
|
|
- params: {
|
|
|
|
- stream_response: params.stream_response !== null ? params.stream_response : undefined,
|
|
|
|
- function_calling:
|
|
|
|
- params.function_calling !== null ? params.function_calling : undefined,
|
|
|
|
- seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
|
|
|
|
- stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
|
|
|
|
- temperature: params.temperature !== null ? params.temperature : undefined,
|
|
|
|
- reasoning_effort:
|
|
|
|
- params.reasoning_effort !== null ? params.reasoning_effort : undefined,
|
|
|
|
- logit_bias: params.logit_bias !== null ? params.logit_bias : undefined,
|
|
|
|
- frequency_penalty:
|
|
|
|
- params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
- presence_penalty:
|
|
|
|
- params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
- repeat_penalty:
|
|
|
|
- params.frequency_penalty !== null ? params.frequency_penalty : undefined,
|
|
|
|
- repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
|
|
|
|
- mirostat: params.mirostat !== null ? params.mirostat : undefined,
|
|
|
|
- mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
|
|
|
|
- mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
|
|
|
|
- top_k: params.top_k !== null ? params.top_k : undefined,
|
|
|
|
- top_p: params.top_p !== null ? params.top_p : undefined,
|
|
|
|
- min_p: params.min_p !== null ? params.min_p : undefined,
|
|
|
|
- tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
|
|
|
|
- num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
|
|
|
|
- num_batch: params.num_batch !== null ? params.num_batch : undefined,
|
|
|
|
- num_keep: params.num_keep !== null ? params.num_keep : undefined,
|
|
|
|
- max_tokens: params.max_tokens !== null ? params.max_tokens : undefined,
|
|
|
|
- use_mmap: params.use_mmap !== null ? params.use_mmap : undefined,
|
|
|
|
- use_mlock: params.use_mlock !== null ? params.use_mlock : undefined,
|
|
|
|
- num_thread: params.num_thread !== null ? params.num_thread : undefined,
|
|
|
|
- num_gpu: params.num_gpu !== null ? params.num_gpu : undefined
|
|
|
|
- },
|
|
|
|
- keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined
|
|
|
|
- });
|
|
|
|
- dispatch('save');
|
|
|
|
|
|
+ saveHandler();
|
|
}}
|
|
}}
|
|
>
|
|
>
|
|
{$i18n.t('Save')}
|
|
{$i18n.t('Save')}
|