Browse Source

refac: params

Timothy J. Baek 1 year ago
parent
commit
547b990041

+ 157 - 153
src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte

@@ -5,21 +5,23 @@
 
 	const i18n = getContext('i18n');
 
+	export let admin = false;
+
 	export let params = {
 		// Advanced
-		seed: 0,
+		seed: null,
 		stop: null,
-		temperature: '',
-		frequency_penalty: '',
-		repeat_last_n: '',
-		mirostat: '',
-		mirostat_eta: '',
-		mirostat_tau: '',
-		top_k: '',
-		top_p: '',
-		tfs_z: '',
-		num_ctx: '',
-		max_tokens: '',
+		temperature: null,
+		frequency_penalty: null,
+		repeat_last_n: null,
+		mirostat: null,
+		mirostat_eta: null,
+		mirostat_tau: null,
+		top_k: null,
+		top_p: null,
+		tfs_z: null,
+		num_ctx: null,
+		max_tokens: null,
 		use_mmap: null,
 		use_mlock: null,
 		num_thread: null,
@@ -112,10 +114,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center"> {$i18n.t('Custom')} </span>
@@ -123,7 +125,7 @@
 			</button>
 		</div>
 
-		{#if (params?.temperature ?? '') !== ''}
+		{#if (params?.temperature ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -157,10 +159,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -168,7 +170,7 @@
 			</button>
 		</div>
 
-		{#if (params?.mirostat ?? '') !== ''}
+		{#if (params?.mirostat ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -203,10 +205,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -214,7 +216,7 @@
 			</button>
 		</div>
 
-		{#if (params?.mirostat_eta ?? '') !== ''}
+		{#if (params?.mirostat_eta ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -248,10 +250,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -259,7 +261,7 @@
 			</button>
 		</div>
 
-		{#if (params?.mirostat_tau ?? '') !== ''}
+		{#if (params?.mirostat_tau ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -293,10 +295,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -304,7 +306,7 @@
 			</button>
 		</div>
 
-		{#if (params?.top_k ?? '') !== ''}
+		{#if (params?.top_k ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -338,10 +340,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -349,7 +351,7 @@
 			</button>
 		</div>
 
-		{#if (params?.top_p ?? '') !== ''}
+		{#if (params?.top_p ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -383,10 +385,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -394,7 +396,7 @@
 			</button>
 		</div>
 
-		{#if (params?.frequency_penalty ?? '') !== ''}
+		{#if (params?.frequency_penalty ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -428,10 +430,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -439,7 +441,7 @@
 			</button>
 		</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-1">
 					<input
@@ -474,10 +476,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -485,7 +487,7 @@
 			</button>
 		</div>
 
-		{#if (params?.tfs_z ?? '') !== ''}
+		{#if (params?.tfs_z ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -519,10 +521,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -530,7 +532,7 @@
 			</button>
 		</div>
 
-		{#if (params?.num_ctx ?? '') !== ''}
+		{#if (params?.num_ctx ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -564,10 +566,10 @@
 				class="p-1 px-3 text-xs flex rounded transition"
 				type="button"
 				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>
 				{:else}
 					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
@@ -575,7 +577,7 @@
 			</button>
 		</div>
 
-		{#if (params?.max_tokens ?? '') !== ''}
+		{#if (params?.max_tokens ?? null) !== null}
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
@@ -602,122 +604,124 @@
 		{/if}
 	</div>
 
-	<div class=" py-0.5 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>
-
-			<button
-				class="p-1 px-3 text-xs flex rounded transition"
-				type="button"
-				on:click={() => {
-					params.use_mmap = (params?.use_mmap ?? null) === null ? true : null;
-				}}
-			>
-				{#if (params?.use_mmap ?? null) === null}
-					<span class="ml-2 self-center">{$i18n.t('Default')}</span>
-				{:else}
-					<span class="ml-2 self-center">{$i18n.t('On')}</span>
-				{/if}
-			</button>
+	{#if admin}
+		<div class=" py-0.5 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>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					type="button"
+					on:click={() => {
+						params.use_mmap = (params?.use_mmap ?? null) === null ? true : null;
+					}}
+				>
+					{#if (params?.use_mmap ?? null) === null}
+						<span class="ml-2 self-center">{$i18n.t('Default')}</span>
+					{:else}
+						<span class="ml-2 self-center">{$i18n.t('On')}</span>
+					{/if}
+				</button>
+			</div>
 		</div>
-	</div>
 
-	<div class=" py-0.5 w-full justify-between">
-		<div class="flex w-full justify-between">
-			<div class=" self-center text-xs font-medium">{$i18n.t('use_mlock (Ollama)')}</div>
-
-			<button
-				class="p-1 px-3 text-xs flex rounded transition"
-				type="button"
-				on:click={() => {
-					params.use_mlock = (params?.use_mlock ?? null) === null ? true : null;
-				}}
-			>
-				{#if (params?.use_mlock ?? null) === null}
-					<span class="ml-2 self-center">{$i18n.t('Default')}</span>
-				{:else}
-					<span class="ml-2 self-center">{$i18n.t('On')}</span>
-				{/if}
-			</button>
+		<div class=" py-0.5 w-full justify-between">
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">{$i18n.t('use_mlock (Ollama)')}</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					type="button"
+					on:click={() => {
+						params.use_mlock = (params?.use_mlock ?? null) === null ? true : null;
+					}}
+				>
+					{#if (params?.use_mlock ?? null) === null}
+						<span class="ml-2 self-center">{$i18n.t('Default')}</span>
+					{:else}
+						<span class="ml-2 self-center">{$i18n.t('On')}</span>
+					{/if}
+				</button>
+			</div>
 		</div>
-	</div>
 
-	<div class=" py-0.5 w-full justify-between">
-		<div class="flex w-full justify-between">
-			<div class=" self-center text-xs font-medium">{$i18n.t('num_thread (Ollama)')}</div>
+		<div class=" py-0.5 w-full justify-between">
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">{$i18n.t('num_thread (Ollama)')}</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					type="button"
+					on:click={() => {
+						params.num_thread = (params?.num_thread ?? null) === null ? 2 : null;
+					}}
+				>
+					{#if (params?.num_thread ?? null) === null}
+						<span class="ml-2 self-center">{$i18n.t('Default')}</span>
+					{:else}
+						<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
+					{/if}
+				</button>
+			</div>
 
-			<button
-				class="p-1 px-3 text-xs flex rounded transition"
-				type="button"
-				on:click={() => {
-					params.num_thread = (params?.num_thread ?? null) === null ? 2 : null;
-				}}
-			>
-				{#if (params?.num_thread ?? null) === null}
-					<span class="ml-2 self-center">{$i18n.t('Default')}</span>
-				{:else}
-					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
-				{/if}
-			</button>
+			{#if (params?.num_thread ?? null) !== null}
+				<div class="flex mt-0.5 space-x-2">
+					<div class=" flex-1">
+						<input
+							id="steps-range"
+							type="range"
+							min="1"
+							max="256"
+							step="1"
+							bind:value={params.num_thread}
+							class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
+						/>
+					</div>
+					<div class="">
+						<input
+							bind:value={params.num_thread}
+							type="number"
+							class=" bg-transparent text-center w-14"
+							min="1"
+							max="256"
+							step="1"
+						/>
+					</div>
+				</div>
+			{/if}
 		</div>
 
-		{#if (params?.num_thread ?? null) !== null}
-			<div class="flex mt-0.5 space-x-2">
-				<div class=" flex-1">
-					<input
-						id="steps-range"
-						type="range"
-						min="1"
-						max="256"
-						step="1"
-						bind:value={params.num_thread}
-						class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
-					/>
-				</div>
-				<div class="">
-					<input
-						bind:value={params.num_thread}
-						type="number"
-						class=" bg-transparent text-center w-14"
-						min="1"
-						max="256"
-						step="1"
-					/>
-				</div>
+		<!-- <div class=" py-0.5 w-full justify-between">
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">{$i18n.t('Template')}</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition"
+					type="button"
+					on:click={() => {
+						params.template = (params?.template ?? null) === null ? '' : null;
+					}}
+				>
+					{#if (params?.template ?? null) === null}
+						<span class="ml-2 self-center">{$i18n.t('Default')}</span>
+					{:else}
+						<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
+					{/if}
+				</button>
 			</div>
-		{/if}
-	</div>
 
-	<div class=" py-0.5 w-full justify-between">
-		<div class="flex w-full justify-between">
-			<div class=" self-center text-xs font-medium">{$i18n.t('Template')}</div>
-
-			<button
-				class="p-1 px-3 text-xs flex rounded transition"
-				type="button"
-				on:click={() => {
-					params.template = (params?.template ?? null) === null ? '' : null;
-				}}
-			>
-				{#if (params?.template ?? null) === null}
-					<span class="ml-2 self-center">{$i18n.t('Default')}</span>
-				{:else}
-					<span class="ml-2 self-center">{$i18n.t('Custom')}</span>
-				{/if}
-			</button>
-		</div>
-
-		{#if (params?.template ?? null) !== null}
-			<div class="flex mt-0.5 space-x-2">
-				<div class=" flex-1">
-					<textarea
-						class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg -mb-1"
-						placeholder="Write your model template content here"
-						rows="4"
-						bind:value={params.template}
-					/>
+			{#if (params?.template ?? null) !== null}
+				<div class="flex mt-0.5 space-x-2">
+					<div class=" flex-1">
+						<textarea
+							class="px-3 py-1.5 text-sm w-full bg-transparent border dark:border-gray-600 outline-none rounded-lg -mb-1"
+							placeholder="Write your model template content here"
+							rows="4"
+							bind:value={params.template}
+						/>
+					</div>
 				</div>
-			</div>
-		{/if}
-	</div>
+			{/if}
+		</div> -->
+	{/if}
 </div>

+ 29 - 32
src/lib/components/chat/Settings/General.svelte

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

+ 1 - 0
src/routes/(app)/workspace/models/create/+page.svelte

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

+ 1 - 0
src/routes/(app)/workspace/models/edit/+page.svelte

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