From 2e0bf3b957ed37431d3ad096c033e356a0b71cc8 Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Sat, 4 Nov 2023 20:00:17 -0700 Subject: [PATCH] feat: advanced params support --- src/lib/components/chat/SettingsModal.svelte | 136 ++++++++++++++++--- src/routes/+page.svelte | 29 +++- 2 files changed, 140 insertions(+), 25 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index 17558c2b..4ec3f8bf 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -22,7 +22,11 @@ let pullProgress = null; // Advanced + let seed = 0; let temperature = 0.8; + let repeat_penalty = 1.1; + let top_k = 40; + let top_p = 0.9; const splitStream = (splitOn) => { let buffer = ''; @@ -164,7 +168,12 @@ API_BASE_URL = settings.API_BASE_URL ?? BUILD_TIME_API_BASE_URL; OPENAI_API_KEY = settings.OPENAI_API_KEY ?? ''; system = settings.system ?? ''; + + seed = settings.seed ?? 0; temperature = settings.temperature ?? 0.8; + repeat_penalty = settings.repeat_penalty ?? 1.1; + top_k = settings.top_k ?? 40; + top_p = settings.top_p ?? 0.9; } @@ -324,7 +333,7 @@ OpenAI API Key (optional)
-
+
{:else if selectedTab === 'advanced'}
-
- - +
+
+
Seed
+
+
+ +
+
+
+ +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
@@ -483,7 +566,11 @@ class=" px-4 py-2 bg-emerald-600 hover:bg-emerald-700 transition rounded" on:click={() => { saveSettings({ - temperature: temperature !== 0.8 ? temperature : undefined + seed: (seed !== 0 ? seed : undefined) ?? undefined, + temperature: temperature !== 0.8 ? temperature : undefined, + repeat_penalty: repeat_penalty !== 1.1 ? repeat_penalty : undefined, + top_k: top_k !== 40 ? top_k : undefined, + top_p: top_p !== 0.9 ? top_p : undefined }); show = false; }} @@ -497,3 +584,16 @@
+ + diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 16503e62..6a3e80fb 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -233,6 +233,7 @@ }; const saveSettings = async (updated) => { + console.log(updated); settings = { ...settings, ...updated }; localStorage.setItem('settings', JSON.stringify(settings)); await getModelTags(); @@ -458,12 +459,13 @@ model: selectedModel, prompt: userPrompt, system: settings.system ?? undefined, - options: - settings.temperature != null - ? { - temperature: settings.temperature - } - : undefined, + options: { + seed: settings.seed ?? undefined, + temperature: settings.temperature ?? undefined, + repeat_penalty: settings.repeat_penalty ?? undefined, + top_k: settings.top_k ?? undefined, + top_p: settings.top_p ?? undefined + }, context: messages.length > 3 && messages.at(-3).context != undefined ? messages.at(-3).context @@ -566,7 +568,20 @@ body: JSON.stringify({ model: selectedModel, stream: true, - messages: messages.map((message) => ({ ...message, done: undefined })) + messages: [ + settings.system + ? { + role: 'system', + content: settings.system + } + : undefined, + ...messages + ] + .filter((message) => message) + .map((message) => ({ ...message, done: undefined })), + temperature: settings.temperature ?? undefined, + top_p: settings.top_p ?? undefined, + frequency_penalty: settings.repeat_penalty ?? undefined }) });