Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

feat(settings): add a per-model reasoning effort selector (#736)

Dongyu74004c412513
diff --git a/deeptutor/services/llm/provider_core/anthropic_provider.py b/deeptutor/services/llm/provider_core/anthropic_provider.py
index a3f61834e..003abeabe 100644
--- a/deeptutor/services/llm/provider_core/anthropic_provider.py
+++ b/deeptutor/services/llm/provider_core/anthropic_provider.py
@@ -381,7 +381,12 @@ class AnthropicProvider(LLMProvider):
)
max_tokens = max(1, max_tokens)
- thinking_enabled = bool(reasoning_effort)
+ effort = (reasoning_effort or "").strip().lower()
+ # An off-sentinel means "thinking off" on every family, not "an effort
+ # level I don't recognise": the budget branch below treats an unknown
+ # value as the default budget, so a plain `bool(reasoning_effort)`
+ # turned `none` into thinking ON with 4096 tokens.
+ thinking_enabled = bool(effort) and effort not in _THINKING_OFF_EFFORTS
effort_based = any(family in model_name for family in _EFFORT_BASED_FAMILIES)
kwargs: dict[str, Any] = {
@@ -393,20 +398,18 @@ class AnthropicProvider(LLMProvider):
if system:
kwargs["system"] = system
- if reasoning_effort == "adaptive":
- kwargs["thinking"] = {"type": "adaptive"}
- if not effort_based:
- kwargs["temperature"] = 1.0
- elif thinking_enabled and effort_based:
+ if thinking_enabled and effort_based:
# These families reject enabled+budget_tokens with a 400 —
# adaptive is their only on-mode, so any real effort level maps
# to adaptive (no budget headroom needed). Off-sentinels omit
# the param entirely.
- if reasoning_effort.lower() not in _THINKING_OFF_EFFORTS:
- kwargs["thinking"] = {"type": "adaptive"}
+ kwargs["thinking"] = {"type": "adaptive"}
elif thinking_enabled:
+ # The older families are the mirror image: they take
+ # enabled+budget_tokens and reject `adaptive`, so a stored
+ # `adaptive` lands on the default budget rather than a 400.
budget_map = {"low": 1024, "medium": 4096, "high": max(8192, max_tokens)}
- budget = budget_map.get(reasoning_effort.lower(), 4096)
+ budget = budget_map.get(effort, 4096)
kwargs["thinking"] = {"type": "enabled", "budget_tokens": budget}
kwargs["max_tokens"] = max(max_tokens, budget + 4096)
kwargs["temperature"] = 1.0
diff --git a/tests/services/llm/test_anthropic_provider_fixes.py b/tests/services/llm/test_anthropic_provider_fixes.py
index 4761a27f0..87a8e1c69 100644
--- a/tests/services/llm/test_anthropic_provider_fixes.py
+++ b/tests/services/llm/test_anthropic_provider_fixes.py
@@ -139,3 +139,37 @@ def test_older_models_keep_budget_tokens_thinking() -> None:
assert kwargs["thinking"]["type"] == "enabled"
assert kwargs["thinking"]["budget_tokens"] >= 8192
assert kwargs["temperature"] == 1.0
+
+
+def test_older_models_omit_thinking_for_off_sentinels() -> None:
+ """An off-sentinel used to fall through to the budget branch, where an
+ unrecognised value means "default budget" — so `none` turned thinking ON."""
+ provider = _provider()
+ for effort in ("none", "minimal", "minimum"):
+ kwargs = _kwargs_with_effort(provider, "claude-opus-4-6", effort)
+ assert "thinking" not in kwargs, effort
+ assert kwargs["temperature"] == 0.7, effort
+
+
+def test_older_models_translate_adaptive_into_budget_thinking() -> None:
+ """The older families reject `thinking: {type: adaptive}`, so a stored
+ adaptive selection has to land on the budget form instead of a 400."""
+ provider = _provider()
+ kwargs = _kwargs_with_effort(provider, "claude-sonnet-4-5", "adaptive")
+ assert kwargs["thinking"] == {"type": "enabled", "budget_tokens": 4096}
+ assert kwargs["temperature"] == 1.0
+
+
+def test_off_sentinels_leave_tool_choice_to_the_caller() -> None:
+ """Extended thinking forces tool_choice=auto; thinking-off must not."""
+ provider = _provider()
+ kwargs = provider._build_kwargs(
+ messages=[{"role": "user", "content": "hi"}],
+ tools=[{"function": {"name": "t", "description": "", "parameters": {}}}],
+ model="claude-opus-4-6",
+ max_tokens=1024,
+ temperature=0.7,
+ reasoning_effort="none",
+ tool_choice="required",
+ )
+ assert kwargs["tool_choice"] == {"type": "any"}
diff --git a/web/components/settings/ServiceConfigEditor.tsx b/web/components/settings/ServiceConfigEditor.tsx
index add1cd155..aae8ad702 100644
--- a/web/components/settings/ServiceConfigEditor.tsx
+++ b/web/components/settings/ServiceConfigEditor.tsx
@@ -16,6 +16,7 @@ import {
import { useTranslation } from "react-i18next";
import ProviderIcon from "@/components/common/ProviderIcon";
+import { reasoningEffortOptions } from "@/lib/reasoning-effort";
import { CodexOAuthCard } from "./CodexOAuthCard";
import { isCodexOAuthProfile, isManagedCodexProfile } from "./codex-profile";
import {
@@ -72,6 +73,7 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {
updateModelField,
updateModelBoolField,
updateContextWindowField,
+ updateReasoningEffort,
llmContextDetection,
applyDetectedContextWindow,
runDetailedTest,
@@ -133,6 +135,14 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {
llmContextDetection?.modelId === draft.services.llm.active_model_id
? llmContextDetection
: null;
+ const reasoningOptions =
+ service === "llm" && activeModel
+ ? reasoningEffortOptions(
+ activeProfile?.binding,
+ activeModel.model,
+ activeModel.reasoning_effort,
+ )
+ : [];
const startModelRename = (model: CatalogModel) => {
setEditingModelId(model.id);
@@ -521,6 +531,38 @@ export function ServiceConfigEditor({ service }: { service: ServiceName }) {
detection={activeLlmDetection}
onApply={applyDetectedContextWindow}
/>
+ {reasoningOptions.length > 0 && (
+ <div>
+ <div className="mb-1.5 text-[12px] text-[var(--muted-foreground)]">
+ {t("Reasoning effort")}
+ </div>
+ <div className="relative">
+ <select
+ className={selectClass}
+ value={activeModel.reasoning_effort || ""}
+ onChange={(event) =>
+ updateReasoningEffort(event.target.value)
+ }
+ >
+ {reasoningOptions.map((option) => (
+ <option
+ className={selectOptionClass}
+ key={option.value || "auto"}
+ value={option.value}
+ >
+ {t(option.label)}
+ </option>
+ ))}
+ </select>
+ <ChevronDown className="pointer-events-none absolute right-3 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-[var(--muted-foreground)]" />
+ </div>
+ <p className="mt-1.5 text-[11px] leading-relaxed text-[var(--muted-foreground)]">
+ {t(
+ "Sets this model's default reasoning depth. Auto leaves the choice to the provider.",
+ )}
+ </p>
+ </div>
+ )}
</>
)}
{service === "embedding" && (
diff --git a/web/components/settings/SettingsContext.tsx b/web/components/settings/SettingsContext.tsx
index 1f348bdc5..4baf7de3b 100644
--- a/web/components/settings/SettingsContext.tsx
+++ b/web/components/settings/SettingsContext.tsx
@@ -24,6 +24,7 @@ import {
import { useAppShell } from "@/context/AppShellContext";
import { apiFetch, apiUrl } from "@/lib/api";
import { invalidateLLMOptionsCache } from "@/lib/llm-options";
+import { setModelReasoningEffort } from "@/lib/reasoning-effort";
import { setTheme as applyThemePreference } from "@/lib/theme";
// ─── Domain types ─────────────────────────────────────────────────────────
@@ -48,6 +49,7 @@ export type CatalogModel = {
context_window?: string;
context_window_source?: string;
context_window_detected_at?: string;
+ reasoning_effort?: string;
// Voice (TTS): free-form provider/model-specific voice string, e.g.
// "alloy", "autumn", "model:voice". `response_format` is the TTS output
// codec (mp3/wav/...) and is reused by imagegen ("url"/"b64_json").
@@ -480,6 +482,7 @@ type SettingsContextValue = {
value: boolean,
) => void;
updateContextWindowField: (value: string) => void;
+ updateReasoningEffort: (value: string) => void;
llmContextDetection: LlmContextWindowDetection | null;
applyDetectedContextWindow: () => void;
@@ -940,6 +943,17 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
[mutateCatalog],
);
+ const updateReasoningEffort = useCallback(
+ (value: string) => {
+ mutateCatalog((next) => {
+ const model = getActiveModel(next, "llm");
+ if (!model) return;
+ setModelReasoningEffort(model, value);
+ });
+ },
+ [mutateCatalog],
+ );
+
const applyDetectedContextWindow = useCallback(() => {
if (!llmContextDetection) return;
mutateCatalog((next) => {
@@ -1269,6 +1283,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
updateModelField,
updateModelBoolField,
updateContextWindowField,
+ updateReasoningEffort,
llmContextDetection,
applyDetectedContextWindow,
saving,
@@ -1331,6 +1346,7 @@ export function SettingsProvider({ children }: { children: ReactNode }) {
updateCodeBlockTheme,
updateCodeBlockWrapLongLines,
updateContextWindowField,
+ updateReasoningEffort,
updateLanguage,
updateModelBoolField,
updateModelField,
diff --git a/web/lib/reasoning-effort.ts b/web/lib/reasoning-effort.ts
new file mode 100644
index 000000000..3f95223d6
--- /dev/null
+++ b/web/lib/reasoning-effort.ts
@@ -0,0 +1,179 @@
+export type ReasoningEffortOption = {
+ value: string;
+ label: string;
+};
+
+const LABELS: Record<string, string> = {
+ "": "Provider default (Auto)",
+ none: "None",
+ minimal: "Minimal",
+ low: "Low",
+ medium: "Medium",
+ high: "High",
+ xhigh: "Extra high",
+ adaptive: "Adaptive",
+};
+
+// Mirrors the reasoning-relevant half of PROVIDER_ALIASES in
+// deeptutor/services/provider_registry.py. A profile stored as "azure" or
+// "openai-compatible" resolves to the same adapter as its canonical name, so
+// the lookup below has to see the canonical name or the selector vanishes.
+const PROVIDER_ALIASES: Record<string, string> = {
+ azure: "azure_openai",
+ azureopenai: "azure_openai",
+ google: "gemini",
+ google_genai: "gemini",
+ claude: "anthropic",
+ openai_compatible: "custom",
+ anthropic_compatible: "custom_anthropic",
+};
+
+const OPENAI_PROVIDERS = new Set([
+ "openai",
+ "azure_openai",
+ "openai_codex",
+ "github_copilot",
+]);
+const BINARY_THINKING_PROVIDERS = new Set([
+ "deepseek",
+ "volcengine",
+ "volcengine_coding_plan",
+ "byteplus",
+ "byteplus_coding_plan",
+ "dashscope",
+ "minimax",
+]);
+
+function includesAny(value: string, patterns: string[]): boolean {
+ return patterns.some((pattern) => value.includes(pattern));
+}
+
+function options(values: string[], current: string): ReasoningEffortOption[] {
+ const normalizedCurrent = current.trim().toLowerCase();
+ const resolved = [...values];
+ if (normalizedCurrent && !resolved.includes(normalizedCurrent)) {
+ resolved.push(normalizedCurrent);
+ }
+ if (resolved.length === 0) return [];
+ return ["", ...resolved].map((value) => ({
+ value,
+ label: LABELS[value] ?? value,
+ }));
+}
+
+/**
+ * Return conservative reasoning-effort choices for a provider/model pair.
+ *
+ * The provider adapters do not share one universal enum. In particular,
+ * Gemini 3 and Gemini 2.5 Pro reject `none`, while several OpenAI-compatible
+ * providers only expose an on/off thinking switch. Unknown model families stay
+ * hidden unless a catalog already contains an explicit value.
+ *
+ * A value already stored for the model is always listed even when this table
+ * excludes it, so a hand-edited or newly-invalidated setting stays visible and
+ * can be reset to Auto — that is the recovery path for a profile that is
+ * currently sending a value its provider rejects.
+ */
+export function reasoningEffortOptions(
+ binding: string | null | undefined,
+ model: string | null | undefined,
+ current = "",
+): ReasoningEffortOption[] {
+ const canonical = (binding ?? "").trim().toLowerCase().replaceAll("-", "_");
+ const provider = PROVIDER_ALIASES[canonical] ?? canonical;
+ const modelName = (model ?? "").trim().toLowerCase();
+
+ if (provider === "gemini" || modelName.includes("gemini")) {
+ if (
+ modelName.includes("gemini-3") ||
+ modelName.includes("gemini-2.5-pro")
+ ) {
+ return options(["minimal", "low", "medium", "high"], current);
+ }
+ if (modelName.includes("gemini-2.5")) {
+ return options(["none", "low", "medium", "high"], current);
+ }
+ return options(["low", "medium", "high"], current);
+ }
+
+ if (
+ provider === "anthropic" ||
+ provider === "custom_anthropic" ||
+ modelName.includes("claude")
+ ) {
+ // Effort-based families (Opus 4.7 onward) take `thinking: {type:
+ // "adaptive"}` and reject enabled+budget_tokens; the older thinking
+ // families are the mirror image and 400 on adaptive. Keep the two lists
+ // aligned with _EFFORT_BASED_FAMILIES in
+ // deeptutor/services/llm/provider_core/anthropic_provider.py.
+ const effortBased = includesAny(modelName, [
+ "opus-4-7",
+ "opus-4-8",
+ "opus-5",
+ "sonnet-5",
+ "fable-5",
+ "mythos-5",
+ ]);
+ if (effortBased) {
+ return options(["none", "adaptive"], current);
+ }
+ const supportsThinking = includesAny(modelName, [
+ "claude-3-7",
+ "claude-4",
+ "claude-sonnet-4",
+ "claude-opus-4",
+ "claude-haiku-4",
+ ]);
+ return supportsThinking
+ ? options(["none", "low", "medium", "high"], current)
+ : options([], current);
+ }
+
+ if (BINARY_THINKING_PROVIDERS.has(provider) || provider === "custom") {
+ const supported =
+ provider === "minimax" ||
+ includesAny(modelName, [
+ "deepseek-reasoner",
+ "deepseek-v4-pro",
+ "qwen3",
+ "qwen-3",
+ "qwq",
+ "qwen-plus",
+ ]);
+ if (supported) {
+ return options(["minimal", "high"], current);
+ }
+ if (BINARY_THINKING_PROVIDERS.has(provider)) {
+ // Deliberately no selector for the rest — VolcEngine/BytePlus thinking
+ // models are switched on by the backend from the spec's
+ // reasoning_model_patterns, so an explicit per-model choice here would
+ // duplicate a decision the registry already owns.
+ return options([], current);
+ }
+ }
+
+ if (OPENAI_PROVIDERS.has(provider) || provider === "custom") {
+ const isGpt5OrCodex = includesAny(modelName, ["gpt-5", "codex"]);
+ if (isGpt5OrCodex) {
+ return options(["minimal", "low", "medium", "high", "xhigh"], current);
+ }
+ if (includesAny(modelName, ["o1", "o3", "o4"])) {
+ return options(["low", "medium", "high"], current);
+ }
+ return options([], current);
+ }
+
+ return options([], current);
+}
+
+export function setModelReasoningEffort(
+ model: { reasoning_effort?: string },
+ value: string,
+): void {
+ const normalized = value.trim();
+ if (normalized) {
+ model.reasoning_effort = normalized;
+ } else {
+ delete model.reasoning_effort;
+ }
+}
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 1fd8706db..515c3de9a 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -1019,6 +1019,12 @@
"Video": "Video",
"Low": "Low",
"High": "High",
+ "Reasoning effort": "Reasoning effort",
+ "Provider default (Auto)": "Provider default (Auto)",
+ "Minimal": "Minimal",
+ "Extra high": "Extra high",
+ "Adaptive": "Adaptive",
+ "Sets this model's default reasoning depth. Auto leaves the choice to the provider.": "Sets this model's default reasoning depth. Auto leaves the choice to the provider.",
"Style, pacing, color...": "Style, pacing, color...",
"Fullscreen": "Fullscreen",
"View Manim Code": "View Manim Code",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 826cf9b57..910832194 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -1053,6 +1053,12 @@
"Video": "视频",
"Low": "低",
"High": "高",
+ "Reasoning effort": "推理强度",
+ "Provider default (Auto)": "跟随供应商默认值(自动)",
+ "Minimal": "最小",
+ "Extra high": "超高",
+ "Adaptive": "自适应",
+ "Sets this model's default reasoning depth. Auto leaves the choice to the provider.": "设置此模型的默认推理深度;选择“自动”时由供应商决定。",
"Style, pacing, color...": "风格、节奏、配色…",
"Fullscreen": "全屏",
"View Manim Code": "查看 Manim 代码",
diff --git a/web/tests/reasoning-effort.test.ts b/web/tests/reasoning-effort.test.ts
new file mode 100644
index 000000000..a5a29066b
--- /dev/null
+++ b/web/tests/reasoning-effort.test.ts
@@ -0,0 +1,126 @@
+import assert from "node:assert/strict";
+import test from "node:test";
+
+import {
+ reasoningEffortOptions,
+ setModelReasoningEffort,
+} from "../lib/reasoning-effort";
+
+const values = (
+ binding: string,
+ model: string,
+ current = "",
+): string[] =>
+ reasoningEffortOptions(binding, model, current).map((option) => option.value);
+
+test("Gemini 3 and 2.5 Pro do not list the invalid none effort", () => {
+ assert.deepEqual(values("gemini", "gemini-3.6-flash"), [
+ "",
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ ]);
+ assert.equal(values("gemini", "gemini-2.5-pro").includes("none"), false);
+});
+
+test("a stored value this table excludes stays visible so it can be reset", () => {
+ // The recovery path for a profile already sending a rejected value: it has
+ // to be selectable to be switched back to Auto.
+ assert.deepEqual(values("gemini", "gemini-3.6-flash", "none"), [
+ "",
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "none",
+ ]);
+});
+
+test("provider aliases resolve to the canonical adapter", () => {
+ assert.deepEqual(values("google", "gemini-2.5-flash"), [
+ "",
+ "none",
+ "low",
+ "medium",
+ "high",
+ ]);
+ assert.deepEqual(values("azure", "gpt-5.2"), [
+ "",
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "xhigh",
+ ]);
+ assert.deepEqual(values("claude", "claude-opus-5"), ["", "none", "adaptive"]);
+});
+
+test("effort-based Claude families offer adaptive, older ones do not", () => {
+ // Opus 4.7+ reject enabled+budget_tokens and every real level collapses to
+ // adaptive; the older families 400 on adaptive instead.
+ for (const model of ["claude-opus-4-7", "claude-opus-5", "claude-fable-5"]) {
+ assert.deepEqual(values("anthropic", model), ["", "none", "adaptive"]);
+ }
+ assert.equal(
+ values("anthropic", "claude-opus-4-6").includes("adaptive"),
+ false,
+ );
+});
+
+test("Gemini 2.5 Flash can explicitly disable reasoning", () => {
+ assert.deepEqual(values("gemini", "gemini-2.5-flash"), [
+ "",
+ "none",
+ "low",
+ "medium",
+ "high",
+ ]);
+});
+
+test("known reasoning families get conservative provider-specific choices", () => {
+ assert.deepEqual(values("openai", "gpt-5.2"), [
+ "",
+ "minimal",
+ "low",
+ "medium",
+ "high",
+ "xhigh",
+ ]);
+ assert.deepEqual(values("anthropic", "claude-sonnet-4-5"), [
+ "",
+ "none",
+ "low",
+ "medium",
+ "high",
+ ]);
+ assert.deepEqual(values("dashscope", "qwen3-max"), [
+ "",
+ "minimal",
+ "high",
+ ]);
+ assert.deepEqual(values("custom", "deepseek-reasoner"), [
+ "",
+ "minimal",
+ "high",
+ ]);
+});
+
+test("unknown models stay hidden unless they already carry an override", () => {
+ assert.deepEqual(values("openai", "gpt-4o"), []);
+ assert.deepEqual(values("unknown", "model", "vendor-level"), [
+ "",
+ "vendor-level",
+ ]);
+});
+
+test("Auto removes the catalog field instead of persisting an empty string", () => {
+ const model: { reasoning_effort?: string } = {
+ reasoning_effort: "high",
+ };
+ setModelReasoningEffort(model, "");
+ assert.equal("reasoning_effort" in model, false);
+
+ setModelReasoningEffort(model, " medium ");
+ assert.equal(model.reasoning_effort, "medium");
+});