fix: skip model auto-detection for custom/local providers

When the user is on a custom provider (provider=custom, localhost, or
127.0.0.1 endpoint), /model <name> no longer tries to auto-detect a
provider switch. The model name changes on the current endpoint as-is.

To switch away from a custom endpoint, users must use explicit
provider:model syntax (e.g. /model openai-codex:gpt-5.2-codex).
A helpful tip is printed when changing models on a custom endpoint.

This prevents the confusing case where someone on LM Studio types
/model gpt-5.2-codex, the auto-detection tries to switch providers,
fails or partially succeeds, and requests still go to the old endpoint.

Also fixes the missing prompt_toolkit.auto_suggest mock stub in
test_cli_init.py (same issue already fixed in test_cli_new_session.py).
This commit is contained in:
Test 2026-03-19 19:42:11 -07:00
parent 5822711ae6
commit 1055d4356a
2 changed files with 19 additions and 2 deletions

20
cli.py
View file

@ -3517,8 +3517,17 @@ class HermesCLI:
# Parse provider:model syntax (e.g. "openrouter:anthropic/claude-sonnet-4.5")
current_provider = self.provider or self.requested_provider or "openrouter"
target_provider, new_model = parse_model_input(raw_input, current_provider)
# Auto-detect provider when no explicit provider:model syntax was used
if target_provider == current_provider:
# Auto-detect provider when no explicit provider:model syntax was used.
# Skip auto-detection for custom providers — the model name might
# coincidentally match a known provider's catalog, but the user
# intends to use it on their custom endpoint. Require explicit
# provider:model syntax (e.g. /model openai-codex:gpt-5.2-codex)
# to switch away from a custom endpoint.
_base = self.base_url or ""
is_custom = current_provider == "custom" or (
"localhost" in _base or "127.0.0.1" in _base
)
if target_provider == current_provider and not is_custom:
from hermes_cli.models import detect_provider_for_model
detected = detect_provider_for_model(new_model, current_provider)
if detected:
@ -3586,6 +3595,13 @@ class HermesCLI:
if message:
print(f" Reason: {message}")
print(" Note: Model will revert on restart. Use a verified model to save to config.")
# Helpful hint when staying on a custom endpoint
if is_custom and not provider_changed:
endpoint = self.base_url or "custom endpoint"
print(f" Endpoint: {endpoint}")
print(f" Tip: To switch providers, use /model provider:model")
print(f" e.g. /model openai-codex:gpt-5.2-codex")
else:
self._show_model_and_providers()
elif canonical == "provider":