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:
parent
5822711ae6
commit
1055d4356a
2 changed files with 19 additions and 2 deletions
20
cli.py
20
cli.py
|
|
@ -3517,8 +3517,17 @@ class HermesCLI:
|
||||||
# Parse provider:model syntax (e.g. "openrouter:anthropic/claude-sonnet-4.5")
|
# Parse provider:model syntax (e.g. "openrouter:anthropic/claude-sonnet-4.5")
|
||||||
current_provider = self.provider or self.requested_provider or "openrouter"
|
current_provider = self.provider or self.requested_provider or "openrouter"
|
||||||
target_provider, new_model = parse_model_input(raw_input, current_provider)
|
target_provider, new_model = parse_model_input(raw_input, current_provider)
|
||||||
# Auto-detect provider when no explicit provider:model syntax was used
|
# Auto-detect provider when no explicit provider:model syntax was used.
|
||||||
if target_provider == current_provider:
|
# 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
|
from hermes_cli.models import detect_provider_for_model
|
||||||
detected = detect_provider_for_model(new_model, current_provider)
|
detected = detect_provider_for_model(new_model, current_provider)
|
||||||
if detected:
|
if detected:
|
||||||
|
|
@ -3586,6 +3595,13 @@ class HermesCLI:
|
||||||
if message:
|
if message:
|
||||||
print(f" Reason: {message}")
|
print(f" Reason: {message}")
|
||||||
print(" Note: Model will revert on restart. Use a verified model to save to config.")
|
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:
|
else:
|
||||||
self._show_model_and_providers()
|
self._show_model_and_providers()
|
||||||
elif canonical == "provider":
|
elif canonical == "provider":
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,7 @@ def _make_cli(env_overrides=None, config_overrides=None, **kwargs):
|
||||||
"prompt_toolkit.key_binding": MagicMock(),
|
"prompt_toolkit.key_binding": MagicMock(),
|
||||||
"prompt_toolkit.completion": MagicMock(),
|
"prompt_toolkit.completion": MagicMock(),
|
||||||
"prompt_toolkit.formatted_text": MagicMock(),
|
"prompt_toolkit.formatted_text": MagicMock(),
|
||||||
|
"prompt_toolkit.auto_suggest": MagicMock(),
|
||||||
}
|
}
|
||||||
with patch.dict(sys.modules, prompt_toolkit_stubs), \
|
with patch.dict(sys.modules, prompt_toolkit_stubs), \
|
||||||
patch.dict("os.environ", clean_env, clear=False):
|
patch.dict("os.environ", clean_env, clear=False):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue