diff --git a/llmhost/cli.py b/llmhost/cli.py index afbcdda..99f7036 100644 --- a/llmhost/cli.py +++ b/llmhost/cli.py @@ -111,6 +111,15 @@ def cmd_plan(a): say("\nNothing fits. " + (p.get("reason") or "")) +def carried_settings(old, names): + """Settings setup must not reset. The plan is setup's to rebuild, but the reasoning + setting belongs to the dashboard, which writes it into the same file -- without this an + `llmhost update` would quietly put every model back to "Model default". Models that no + longer fit lose their setting along with their plan.""" + kept = {k: v for k, v in (old.get("reasoning") or {}).items() if k in names} + return {"reasoning": kept} if kept else {} + + def cmd_setup(a): info = hw.detect() cat = paths.load_catalog() @@ -169,6 +178,7 @@ def cmd_setup(a): "models": p["models"], "excluded": p["excluded"], "active": active, p["backend"]: {**old.get(p["backend"], {}), **backend_info}, } + cfg.update(carried_settings(old, names)) paths.save_config(cfg) key = paths.api_key(create=True) diff --git a/tests/test_reasoning.py b/tests/test_reasoning.py index 6e17ddd..4ed7cba 100644 --- a/tests/test_reasoning.py +++ b/tests/test_reasoning.py @@ -88,4 +88,23 @@ check("no server default -> client kwargs preserved", check("a non-dict from the client isn't merged into", inject({"reasoning_effort": "low"}, {"chat_template_kwargs": "nope"}) == {"reasoning_effort": "low"}) +print("\n5. the setting survives a setup re-run (`llmhost update`)") +from llmhost import cli +NAMES = ["qwen3.8-27b", "ornith-1.5-9b"] +check("a set choice is carried over", + cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh"}}, NAMES) + == {"reasoning": {"qwen3.8-27b": "xhigh"}}) +check("every model's choice is kept, not just the active one", + cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh", "ornith-1.5-9b": "off"}}, NAMES) + == {"reasoning": {"qwen3.8-27b": "xhigh", "ornith-1.5-9b": "off"}}) +check("a model that no longer fits is dropped", + cli.carried_settings({"reasoning": {"qwen3.8-27b": "xhigh", "gone-70b": "low"}}, NAMES) + == {"reasoning": {"qwen3.8-27b": "xhigh"}}) +check("nothing set -> no key written", cli.carried_settings({}, NAMES) == {}) +check("empty setting -> no key written", cli.carried_settings({"reasoning": {}}, NAMES) == {}) +check("no model still fits -> no key written", + cli.carried_settings({"reasoning": {"gone-70b": "low"}}, NAMES) == {}) +check("setup's own keys are not touched", + set(cli.carried_settings({"reasoning": {"qwen3.8-27b": "low"}}, NAMES)) == {"reasoning"}) + check.done(ROOT)