Sfoglia il codice sorgente

enh: reasoning_effort param support for openai

Timothy Jaeryang Baek 3 mesi fa
parent
commit
aaf97b85dc

+ 4 - 0
backend/open_webui/utils/middleware.py

@@ -671,6 +671,10 @@ def apply_params_to_form_data(form_data, model):
 
         if "frequency_penalty" in params:
             form_data["frequency_penalty"] = params["frequency_penalty"]
+
+        if "reasoning_effort" in params:
+            form_data["reasoning_effort"] = params["reasoning_effort"]
+
     return form_data
 
 

+ 1 - 0
backend/open_webui/utils/payload.py

@@ -47,6 +47,7 @@ def apply_model_params_to_body_openai(params: dict, form_data: dict) -> dict:
         "top_p": float,
         "max_tokens": int,
         "frequency_penalty": float,
+        "reasoning_effort": str,
         "seed": lambda x: x,
         "stop": lambda x: [bytes(s, "utf-8").decode("unicode_escape") for s in x],
     }

+ 43 - 1
src/lib/components/chat/Settings/Advanced/AdvancedParams.svelte

@@ -15,6 +15,7 @@
 		seed: null,
 		stop: null,
 		temperature: null,
+		reasoning_effort: null,
 		frequency_penalty: null,
 		repeat_last_n: null,
 		mirostat: null,
@@ -158,7 +159,7 @@
 			<div class="flex mt-0.5 space-x-2">
 				<div class=" flex-1">
 					<input
-						class="w-full rounded-lg py-2 px-4 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
+						class="w-full rounded-lg py-2 px-1 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
 						type="text"
 						placeholder={$i18n.t('Enter stop sequence')}
 						bind:value={params.stop}
@@ -224,6 +225,47 @@
 		{/if}
 	</div>
 
+	<div class=" py-0.5 w-full justify-between">
+		<Tooltip
+			content={$i18n.t('Constrains effort on reasoning for reasoning models. (Default: medium)')}
+			placement="top-start"
+			className="inline-tooltip"
+		>
+			<div class="flex w-full justify-between">
+				<div class=" self-center text-xs font-medium">
+					{$i18n.t('Reasoning Effort')}
+				</div>
+				<button
+					class="p-1 px-3 text-xs flex rounded transition flex-shrink-0 outline-none"
+					type="button"
+					on:click={() => {
+						params.reasoning_effort = (params?.reasoning_effort ?? null) === null ? 'medium' : null;
+					}}
+				>
+					{#if (params?.reasoning_effort ?? 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?.reasoning_effort ?? null) !== null}
+			<div class="flex mt-0.5 space-x-2">
+				<div class=" flex-1">
+					<input
+						class="w-full rounded-lg py-2 px-1 text-sm dark:text-gray-300 dark:bg-gray-850 outline-none"
+						type="text"
+						placeholder={$i18n.t('Enter reasoning effort')}
+						bind:value={params.reasoning_effort}
+						autocomplete="off"
+					/>
+				</div>
+			</div>
+		{/if}
+	</div>
+
 	<div class=" py-0.5 w-full justify-between">
 		<Tooltip
 			content={$i18n.t(