Reasoning effort is the dashboard's to set, not the client's

One model is loaded at a time under one setting, and that setting belongs next
to the model it applies to -- the same reason the client can't switch models.
So the proxy now takes a client's reasoning settings off the request before
applying the dashboard's: a top-level reasoning_effort, and enable_thinking or
reasoning_effort inside chat_template_kwargs. Other template kwargs, which
llm-host has no opinion about, still pass through.

This reverses the precedence the proxy had (a client's own kwargs won, mirroring
mlx_lm's own rule), which was the wrong model for a single-model server: clients
offer a generic menu -- opencode's low/medium/high -- and a level the template
doesn't define makes it raise, so every request failed with nothing on the
user's screen to explain it.

- opencode: the provider block disables all three of opencode's effort levels
  instead of curating them. A chooser there would be a menu that does nothing.
- Deletes the nearest-effort mapping (EFFORT_SCALE, nearest_effort,
  plan.effort_levels, the effort_levels= parameter through both backends): it
  existed only to rescue a client-supplied level, and none survives now.
- plan.REASONING_KEYS names the knobs this server drives, with a test asserting
  it stays exactly equal to what reasoning_kwargs can emit -- so a new template
  knob can't be added without also taking it away from clients.
- Two strings that still described a menu of models, from before the block held
  a single entry.

Verified against the live MLX server: with the dashboard on xhigh, five request
shapes (nothing, enable_thinking: false, effort low top-level, effort low in
kwargs, and the off-scale "turbo" that used to 404) all answer identically, and
the reply tracks the dashboard alone as it moves off / low / xhigh.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Neil Bantoc 2026-11-03 15:01:26 -08:00
parent e48517b1cf
commit e24c0b7712
10 changed files with 134 additions and 151 deletions

View file

@ -22,7 +22,7 @@ import subprocess
from pathlib import Path
from urllib.parse import urlsplit
from . import hfcache, paths, plan
from . import paths, plan
PROVIDER = "llmhost"
DISPLAY = "LLMHost"
@ -127,28 +127,16 @@ def model_label(active, label, name_it):
# A model's template defines its own set, and one it lacks makes the template raise, so
# the block hides those and adds the model's own. (The proxy also maps a stray level to
# the nearest real one, so a pasted block that predates a switch still works.)
# The reasoning levels opencode offers of its own accord for a model marked `reasoning`.
OPENCODE_EFFORTS = ("low", "medium", "high")
def _effort_levels(choice):
"""The active model's effort levels: from its chat template once downloaded (what the
proxy itself goes by), from the catalog before that."""
try:
entry = plan.catalog_entry(paths.load_catalog(), choice["name"])
except (KeyError, OSError, ValueError):
return ()
if not entry.get("reasoning"):
return ()
if choice.get("repo") and hfcache.repo_dir(choice["repo"]).exists():
return plan.effort_levels(entry, hfcache.template_controls(choice["repo"]))
return tuple((entry.get("effort") or {}).get("levels") or ())
def effort_variants(levels):
"""opencode `variants` for a model accepting `levels`."""
v = {l: {"disabled": True} for l in OPENCODE_EFFORTS if l not in levels}
v.update({l: {"reasoningEffort": l} for l in levels if l not in OPENCODE_EFFORTS})
return v
def effort_variants():
"""opencode `variants` that switch its reasoning menu off. The effort level is set on
llm-host's dashboard and the proxy drops whatever a client asks for, so a chooser here
would be a menu that silently does nothing -- and whose levels this model's template
may not even define. One model, one setting, one place to change it."""
return {level: {"disabled": True} for level in OPENCODE_EFFORTS}
def provider_block(cfg, host, key_path, label, mark_loaded=False):
@ -161,10 +149,10 @@ def provider_block(cfg, host, key_path, label, mark_loaded=False):
entry = {"name": model_label(active, label, mark_loaded), "tool_call": True,
"limit": {"context": ctx, "output": min(65536, ctx // 2)}}
if (active or {}).get("reasoning"):
# `reasoning` so opencode renders the thinking blocks; `variants` so it doesn't
# offer to set the effort itself.
entry["reasoning"] = True
variants = effort_variants(_effort_levels(active))
if variants:
entry["variants"] = variants
entry["variants"] = effort_variants()
models = {plan.SERVED_ALIAS: entry}
return {
"npm": "@ai-sdk/openai-compatible",
@ -393,8 +381,8 @@ def remove(prov_ids=None, local=True, host=None, every=False):
def sync(cfg):
"""Refresh an existing local provider block -- after a model switch, so the "loaded"
marker and the model list keep up. Never adds one: if opencode isn't wired up here,
"""Refresh an existing local provider block -- after a model switch, so the entry's
name and limits keep up with what's loaded. Never adds one: if opencode isn't wired up here,
switching a model is no reason to wire it. Returns the provider id, or None."""
path = config_file()
if not path.exists():