From d97b34500192880d9b7645bb5ad7545e02211295 Mon Sep 17 00:00:00 2001 From: mcjoys Date: Thu, 2 Jul 2026 21:54:44 +0800 Subject: [PATCH] fix: preserve user-defined providers when assigning model via GUI/API _normalize_main_model_assignment() had a blind spot: when a user-defined provider (configured via config.yaml -> providers section) was used to assign a model through the desktop GUI or /api/model/set, the function checked only built-in _KNOWN_PROVIDER_NAMES and _AGGREGATOR_PROVIDERS - custom providers like open.cherryin.net matched neither, so the code unconditionally fell back to openrouter, silently overwriting the user configured provider. Fix: before falling back to openrouter, check whether the provider slug exists in config.yaml -> providers section (the user-defined provider registry). If it does, return immediately - custom provider namespaces are opaque to the built-in normalizer and should be preserved verbatim. This aligns the HTTP API behavior with what the CLI hermes model picker already does (which skips _normalize_main_model_assignment entirely for user-defined providers). --- hermes_cli/web_server.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/hermes_cli/web_server.py b/hermes_cli/web_server.py index ae53511d41b84..9cc6ac07389c1 100644 --- a/hermes_cli/web_server.py +++ b/hermes_cli/web_server.py @@ -1000,11 +1000,19 @@ def _normalize_main_model_assignment(provider: str, model: str) -> tuple[str, st # against the user's current provider when it's an aggregator that # serves vendor-prefixed slugs; otherwise default to openrouter. try: - cur_cfg = load_config().get("model", {}) + cfg = load_config() + cur_cfg = cfg.get("model", {}) cur_provider = ( str(cur_cfg.get("provider", "") or "").strip().lower() if isinstance(cur_cfg, dict) else "" ) + # User-defined providers (config.yaml providers: section) are NOT + # in _KNOWN_PROVIDER_NAMES but are real providers — preserve them + # instead of falling back to openrouter. This fixes the desktop GUI + # where model selection overwrites a custom provider with openrouter. + user_provs = cfg.get("providers", {}) + if isinstance(user_provs, dict) and canonical in user_provs: + return prov_in, model_in except Exception: cur_provider = "" from hermes_cli.models import _AGGREGATOR_PROVIDERS