fix(model): preserve custom endpoint credentials and accept cloud models not in /v1/models

When switching models on a custom endpoint (ollama-launch):
- Same-provider switches no longer re-resolve credentials (fixes base_url
  being lost for 'custom' provider on subsequent switches)
- Named providers (ollama-launch) are resolved via user_providers so
  switch_model can find their base_url from config
- Models not in the /v1/models probe but present in the user's saved
  provider config are accepted with a warning instead of rejected
- CLI /model and TUI /model both pass user_providers/custom_providers
  to switch_model so the config model list is available for validation

Closes #15088
This commit is contained in:
kshitijk4poor
2026-04-25 14:10:42 +05:30
committed by Teknium
parent 01cf2c65cc
commit 2c56dce0ed
4 changed files with 56 additions and 24 deletions

View File

@@ -750,6 +750,18 @@ def _apply_model_switch(sid: str, session: dict, raw_input: str) -> dict:
current_base_url = str(runtime.get("base_url", "") or "")
current_api_key = str(runtime.get("api_key", "") or "")
# Load user-defined providers so switch_model can resolve named custom
# endpoints (e.g. "ollama-launch") and validate against saved model lists.
user_provs = None
custom_provs = None
try:
from hermes_cli.config import get_compatible_custom_providers, load_config
cfg = load_config()
user_provs = [{"provider": k, **v} for k, v in (cfg.get("providers") or {}).items()]
custom_provs = get_compatible_custom_providers(cfg)
except Exception:
pass
result = switch_model(
raw_input=model_input,
current_provider=current_provider,
@@ -758,6 +770,8 @@ def _apply_model_switch(sid: str, session: dict, raw_input: str) -> dict:
current_api_key=current_api_key,
is_global=persist_global,
explicit_provider=explicit_provider,
user_providers=user_provs,
custom_providers=custom_provs,
)
if not result.success:
raise ValueError(result.error_message or "model switch failed")