Browse Source

Add presence penalty (openAi/ollama/others) and repeat penalty (ollama only?)

- Add Presence Penalty, which I believe most providers have.
- Add repeat_penalty, an Ollama / Llama.cpp only parameter
- Widen temperature range to 2 (supported by many providers and similar front ends)
- Widen Top K range (supported by many providers and similar front ends)
- Adjust description of freqency_penalty in line with OpenAI documentation
- Add presence_penalty with an OpenAI documentation based description
- Add repeat_penalty with an Ollama documentation based description
ferret99gt 2 months ago
parent
commit
941c787806

+ 119 - 6
src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte

@@ -235,7 +235,7 @@
 						id="steps-range"
 						type="range"
 						min="0"
-						max="1"
+						max="2"
 						step="0.05"
 						bind:value={params.temperature}
 						class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
@@ -247,7 +247,7 @@
 						type="number"
 						class=" bg-transparent text-center w-14"
 						min="0"
-						max="1"
+						max="2"
 						step="any"
 					/>
 				</div>
@@ -499,7 +499,7 @@
 						id="steps-range"
 						type="range"
 						min="0"
-						max="100"
+						max="1000"
 						step="0.5"
 						bind:value={params.top_k}
 						class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
@@ -633,7 +633,7 @@
 	<div class=" py-0.5 w-full justify-between">
 		<Tooltip
 			content={$i18n.t(
-				'Sets how strongly to penalize repetitions. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. (Default: 1.1)'
+				'Sets a scaling bias against tokens to penalize repetitions, based on how many times they have appeared. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. At 0, it is disabled. (Default: 1.1)'
 			)}
 			placement="top-start"
 			className="inline-tooltip"
@@ -665,7 +665,7 @@
 					<input
 						id="steps-range"
 						type="range"
-						min="0"
+						min="-2"
 						max="2"
 						step="0.05"
 						bind:value={params.frequency_penalty}
@@ -677,7 +677,120 @@
 						bind:value={params.frequency_penalty}
 						type="number"
 						class=" bg-transparent text-center w-14"
-						min="0"
+						min="-2"
+						max="2"
+						step="any"
+					/>
+				</div>
+			</div>
+		{/if}
+	</div>
+
+	<div class=" py-0.5 w-full justify-between">
+		<Tooltip
+			content={$i18n.t(
+				'Sets a flat bias against tokens that have appeared at least once. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 0.9) will be more lenient. At 0, it is disabled. (Default: 0)'
+			)}
+			placement="top-start"
+			className="inline-tooltip"
+		>
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">
+					{$i18n.t('Presence Penalty')}
+				</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
+					type="button"
+					on:click={() => {
+						params.presence_penalty = (params?.presence_penalty ?? null) === null ? 0.0 : null;
+					}}
+				>
+					{#if (params?.presence_penalty ?? 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>
+		</Tooltip>
+
+		{#if (params?.presence_penalty ?? null) !== null}
+			<div class="flex mt-0.5 space-x-2">
+				<div class=" flex-1">
+					<input
+						id="steps-range"
+						type="range"
+						min="-2"
+						max="2"
+						step="0.05"
+						bind:value={params.presence_penalty}
+						class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
+					/>
+				</div>
+				<div>
+					<input
+						bind:value={params.presence_penalty}
+						type="number"
+						class=" bg-transparent text-center w-14"
+						min="-2"
+						max="2"
+						step="any"
+					/>
+				</div>
+			</div>
+		{/if}
+	</div>
+
+
+	<div class=" py-0.5 w-full justify-between">
+		<Tooltip
+			content={$i18n.t(
+				'Ollama only. Control the repetition of token sequences in the generated text. A higher value (e.g., 1.5) will penalize repetitions more strongly, while a lower value (e.g., 1.1) will be more lenient. At 1, it is disabled. (Default: 1.1)'
+			)}
+			placement="top-start"
+			className="inline-tooltip"
+		>
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">
+					{$i18n.t('Repeat Penalty')}
+				</div>
+
+				<button
+					class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
+					type="button"
+					on:click={() => {
+						params.repeat_penalty = (params?.repeat_penalty ?? null) === null ? 1.1 : null;
+					}}
+				>
+					{#if (params?.repeat_penalty ?? 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>
+		</Tooltip>
+
+		{#if (params?.repeat_penalty ?? null) !== null}
+			<div class="flex mt-0.5 space-x-2">
+				<div class=" flex-1">
+					<input
+						id="steps-range"
+						type="range"
+						min="-2"
+						max="2"
+						step="0.05"
+						bind:value={params.repeat_penalty}
+						class="w-full h-2 rounded-lg appearance-none cursor-pointer dark:bg-gray-700"
+					/>
+				</div>
+				<div>
+					<input
+						bind:value={params.repeat_penalty}
+						type="number"
+						class=" bg-transparent text-center w-14"
+						min="-2"
 						max="2"
 						step="any"
 					/>

+ 4 - 0
src/lib/components/chat/Settings/General.svelte

@@ -51,6 +51,8 @@
 		temperature: null,
 		reasoning_effort: null,
 		frequency_penalty: null,
+		presence_penalty: null,
+		repeat_penalty: null,
 		repeat_last_n: null,
 		mirostat: null,
 		mirostat_eta: null,
@@ -343,6 +345,8 @@
 							params.reasoning_effort !== null ? params.reasoning_effort : 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,

+ 2 - 0
src/lib/i18n/locales/en-US/translation.json

@@ -759,6 +759,7 @@
 	"Positive attitude": "",
 	"Prefix ID": "",
 	"Prefix ID is used to avoid conflicts with other connections by adding a prefix to the model IDs - leave empty to disable": "",
+	"Presence Penalty": "",
 	"Previous 30 days": "",
 	"Previous 7 days": "",
 	"Profile Image": "",
@@ -795,6 +796,7 @@
 	"Rename": "",
 	"Reorder Models": "",
 	"Repeat Last N": "",
+	"Repeat Penalty": "",
 	"Reply in Thread": "",
 	"Request Mode": "",
 	"Reranking Model": "",