refac: params

This commit is contained in:
Timothy J. Baek 2024-06-10 13:29:09 -07:00
parent fcf8f2a704
commit 547b990041
4 changed files with 193 additions and 190 deletions

View File

@ -5,21 +5,23 @@
const i18n = getContext('i18n'); const i18n = getContext('i18n');
export let admin = false;
export let params = { export let params = {
// Advanced // Advanced
seed: 0, seed: null,
stop: null, stop: null,
temperature: '', temperature: null,
frequency_penalty: '', frequency_penalty: null,
repeat_last_n: '', repeat_last_n: null,
mirostat: '', mirostat: null,
mirostat_eta: '', mirostat_eta: null,
mirostat_tau: '', mirostat_tau: null,
top_k: '', top_k: null,
top_p: '', top_p: null,
tfs_z: '', tfs_z: null,
num_ctx: '', num_ctx: null,
max_tokens: '', max_tokens: null,
use_mmap: null, use_mmap: null,
use_mlock: null, use_mlock: null,
num_thread: null, num_thread: null,
@ -112,10 +114,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.temperature = (params?.temperature ?? '') === '' ? 0.8 : ''; params.temperature = (params?.temperature ?? null) === null ? 0.8 : null;
}} }}
> >
{#if (params?.temperature ?? '') === ''} {#if (params?.temperature ?? null) === null}
<span class="ml-2 self-center"> {$i18n.t('Default')} </span> <span class="ml-2 self-center"> {$i18n.t('Default')} </span>
{:else} {:else}
<span class="ml-2 self-center"> {$i18n.t('Custom')} </span> <span class="ml-2 self-center"> {$i18n.t('Custom')} </span>
@ -123,7 +125,7 @@
</button> </button>
</div> </div>
{#if (params?.temperature ?? '') !== ''} {#if (params?.temperature ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -157,10 +159,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.mirostat = (params?.mirostat ?? '') === '' ? 0 : ''; params.mirostat = (params?.mirostat ?? null) === null ? 0 : null;
}} }}
> >
{#if (params?.mirostat ?? '') === ''} {#if (params?.mirostat ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -168,7 +170,7 @@
</button> </button>
</div> </div>
{#if (params?.mirostat ?? '') !== ''} {#if (params?.mirostat ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -203,10 +205,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.mirostat_eta = (params?.mirostat_eta ?? '') === '' ? 0.1 : ''; params.mirostat_eta = (params?.mirostat_eta ?? null) === null ? 0.1 : null;
}} }}
> >
{#if (params?.mirostat_eta ?? '') === ''} {#if (params?.mirostat_eta ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -214,7 +216,7 @@
</button> </button>
</div> </div>
{#if (params?.mirostat_eta ?? '') !== ''} {#if (params?.mirostat_eta ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -248,10 +250,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.mirostat_tau = (params?.mirostat_tau ?? '') === '' ? 5.0 : ''; params.mirostat_tau = (params?.mirostat_tau ?? null) === null ? 5.0 : null;
}} }}
> >
{#if (params?.mirostat_tau ?? '') === ''} {#if (params?.mirostat_tau ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -259,7 +261,7 @@
</button> </button>
</div> </div>
{#if (params?.mirostat_tau ?? '') !== ''} {#if (params?.mirostat_tau ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -293,10 +295,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.top_k = (params?.top_k ?? '') === '' ? 40 : ''; params.top_k = (params?.top_k ?? null) === null ? 40 : null;
}} }}
> >
{#if (params?.top_k ?? '') === ''} {#if (params?.top_k ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -304,7 +306,7 @@
</button> </button>
</div> </div>
{#if (params?.top_k ?? '') !== ''} {#if (params?.top_k ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -338,10 +340,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.top_p = (params?.top_p ?? '') === '' ? 0.9 : ''; params.top_p = (params?.top_p ?? null) === null ? 0.9 : null;
}} }}
> >
{#if (params?.top_p ?? '') === ''} {#if (params?.top_p ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -349,7 +351,7 @@
</button> </button>
</div> </div>
{#if (params?.top_p ?? '') !== ''} {#if (params?.top_p ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -383,10 +385,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.frequency_penalty = (params?.frequency_penalty ?? '') === '' ? 1.1 : ''; params.frequency_penalty = (params?.frequency_penalty ?? null) === null ? 1.1 : null;
}} }}
> >
{#if (params?.frequency_penalty ?? '') === ''} {#if (params?.frequency_penalty ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -394,7 +396,7 @@
</button> </button>
</div> </div>
{#if (params?.frequency_penalty ?? '') !== ''} {#if (params?.frequency_penalty ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -428,10 +430,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.repeat_last_n = (params?.repeat_last_n ?? '') === '' ? 64 : ''; params.repeat_last_n = (params?.repeat_last_n ?? null) === null ? 64 : null;
}} }}
> >
{#if (params?.repeat_last_n ?? '') === ''} {#if (params?.repeat_last_n ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -439,7 +441,7 @@
</button> </button>
</div> </div>
{#if (params?.repeat_last_n ?? '') !== ''} {#if (params?.repeat_last_n ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -474,10 +476,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.tfs_z = (params?.tfs_z ?? '') === '' ? 1 : ''; params.tfs_z = (params?.tfs_z ?? null) === null ? 1 : null;
}} }}
> >
{#if (params?.tfs_z ?? '') === ''} {#if (params?.tfs_z ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -485,7 +487,7 @@
</button> </button>
</div> </div>
{#if (params?.tfs_z ?? '') !== ''} {#if (params?.tfs_z ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -519,10 +521,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.num_ctx = (params?.num_ctx ?? '') === '' ? 2048 : ''; params.num_ctx = (params?.num_ctx ?? null) === null ? 2048 : null;
}} }}
> >
{#if (params?.num_ctx ?? '') === ''} {#if (params?.num_ctx ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -530,7 +532,7 @@
</button> </button>
</div> </div>
{#if (params?.num_ctx ?? '') !== ''} {#if (params?.num_ctx ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -564,10 +566,10 @@
class="p-1 px-3 text-xs flex rounded transition" class="p-1 px-3 text-xs flex rounded transition"
type="button" type="button"
on:click={() => { on:click={() => {
params.max_tokens = (params?.max_tokens ?? '') === '' ? 128 : ''; params.max_tokens = (params?.max_tokens ?? null) === null ? 128 : null;
}} }}
> >
{#if (params?.max_tokens ?? '') === ''} {#if (params?.max_tokens ?? null) === null}
<span class="ml-2 self-center">{$i18n.t('Default')}</span> <span class="ml-2 self-center">{$i18n.t('Default')}</span>
{:else} {:else}
<span class="ml-2 self-center">{$i18n.t('Custom')}</span> <span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@ -575,7 +577,7 @@
</button> </button>
</div> </div>
{#if (params?.max_tokens ?? '') !== ''} {#if (params?.max_tokens ?? null) !== null}
<div class="flex mt-0.5 space-x-2"> <div class="flex mt-0.5 space-x-2">
<div class=" flex-1"> <div class=" flex-1">
<input <input
@ -602,6 +604,7 @@
{/if} {/if}
</div> </div>
{#if admin}
<div class=" py-0.5 w-full justify-between"> <div class=" py-0.5 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('use_mmap (Ollama)')}</div> <div class=" self-center text-xs font-medium">{$i18n.t('use_mmap (Ollama)')}</div>
@ -688,7 +691,7 @@
{/if} {/if}
</div> </div>
<div class=" py-0.5 w-full justify-between"> <!-- <div class=" py-0.5 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('Template')}</div> <div class=" self-center text-xs font-medium">{$i18n.t('Template')}</div>
@ -719,5 +722,6 @@
</div> </div>
</div> </div>
{/if} {/if}
</div> </div> -->
{/if}
</div> </div>

View File

@ -4,7 +4,7 @@
import { getLanguages } from '$lib/i18n'; import { getLanguages } from '$lib/i18n';
const dispatch = createEventDispatcher(); const dispatch = createEventDispatcher();
import { models, settings, theme } from '$lib/stores'; import { models, settings, theme, user } from '$lib/stores';
const i18n = getContext('i18n'); const i18n = getContext('i18n');
@ -43,19 +43,19 @@
let params = { let params = {
// Advanced // Advanced
seed: 0, seed: null,
temperature: '', temperature: null,
frequency_penalty: '', frequency_penalty: null,
repeat_last_n: '', repeat_last_n: null,
mirostat: '', mirostat: null,
mirostat_eta: '', mirostat_eta: null,
mirostat_tau: '', mirostat_tau: null,
top_k: '', top_k: null,
top_p: '', top_p: null,
stop: null, stop: null,
tfs_z: '', tfs_z: null,
num_ctx: '', num_ctx: null,
max_tokens: '' max_tokens: null
}; };
const toggleRequestFormat = async () => { const toggleRequestFormat = async () => {
@ -79,12 +79,6 @@
requestFormat = $settings.requestFormat ?? ''; requestFormat = $settings.requestFormat ?? '';
keepAlive = $settings.keepAlive ?? null; keepAlive = $settings.keepAlive ?? null;
params.seed = $settings.seed ?? 0;
params.temperature = $settings.temperature ?? '';
params.frequency_penalty = $settings.frequency_penalty ?? '';
params.top_k = $settings.top_k ?? '';
params.top_p = $settings.top_p ?? '';
params.num_ctx = $settings.num_ctx ?? '';
params = { ...params, ...$settings.params }; params = { ...params, ...$settings.params };
params.stop = $settings?.params?.stop ? ($settings?.params?.stop ?? []).join(',') : null; params.stop = $settings?.params?.stop ? ($settings?.params?.stop ?? []).join(',') : null;
}); });
@ -227,7 +221,7 @@
</div> </div>
{#if showAdvanced} {#if showAdvanced}
<AdvancedParams bind:params /> <AdvancedParams admin={$user?.role === 'admin'} bind:params />
<hr class=" dark:border-gray-850" /> <hr class=" dark:border-gray-850" />
<div class=" py-1 w-full justify-between"> <div class=" py-1 w-full justify-between">
@ -300,20 +294,23 @@
saveSettings({ saveSettings({
system: system !== '' ? system : undefined, system: system !== '' ? system : undefined,
params: { params: {
seed: (params.seed !== 0 ? params.seed : undefined) ?? undefined, seed: (params.seed !== null ? params.seed : undefined) ?? undefined,
stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined, stop: params.stop ? params.stop.split(',').filter((e) => e) : undefined,
temperature: params.temperature !== '' ? params.temperature : undefined, temperature: params.temperature !== null ? params.temperature : undefined,
frequency_penalty: frequency_penalty:
params.frequency_penalty !== '' ? params.frequency_penalty : undefined, params.frequency_penalty !== null ? params.frequency_penalty : undefined,
repeat_last_n: params.repeat_last_n !== '' ? params.repeat_last_n : undefined, repeat_last_n: params.repeat_last_n !== null ? params.repeat_last_n : undefined,
mirostat: params.mirostat !== '' ? params.mirostat : undefined, mirostat: params.mirostat !== null ? params.mirostat : undefined,
mirostat_eta: params.mirostat_eta !== '' ? params.mirostat_eta : undefined, mirostat_eta: params.mirostat_eta !== null ? params.mirostat_eta : undefined,
mirostat_tau: params.mirostat_tau !== '' ? params.mirostat_tau : undefined, mirostat_tau: params.mirostat_tau !== null ? params.mirostat_tau : undefined,
top_k: params.top_k !== '' ? params.top_k : undefined, top_k: params.top_k !== null ? params.top_k : undefined,
top_p: params.top_p !== '' ? params.top_p : undefined, top_p: params.top_p !== null ? params.top_p : undefined,
tfs_z: params.tfs_z !== '' ? params.tfs_z : undefined, tfs_z: params.tfs_z !== null ? params.tfs_z : undefined,
num_ctx: params.num_ctx !== '' ? params.num_ctx : undefined, num_ctx: params.num_ctx !== null ? params.num_ctx : undefined,
max_tokens: params.max_tokens !== '' ? params.max_tokens : 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
}, },
keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined keepAlive: keepAlive ? (isNaN(keepAlive) ? keepAlive : parseInt(keepAlive)) : undefined
}); });

View File

@ -445,6 +445,7 @@
{#if showAdvanced} {#if showAdvanced}
<div class="my-2"> <div class="my-2">
<AdvancedParams <AdvancedParams
admin={true}
bind:params bind:params
on:change={(e) => { on:change={(e) => {
info.params = { ...info.params, ...params }; info.params = { ...info.params, ...params };

View File

@ -408,6 +408,7 @@
{#if showAdvanced} {#if showAdvanced}
<div class="my-2"> <div class="my-2">
<AdvancedParams <AdvancedParams
admin={true}
bind:params bind:params
on:change={(e) => { on:change={(e) => {
info.params = { ...info.params, ...params }; info.params = { ...info.params, ...params };