fix(model-switch): resolve bare model names via custom_providers catalog#13764
fix(model-switch): resolve bare model names via custom_providers catalog#13764rzbdz wants to merge 1 commit into
Conversation
When a user types /model <name> while on a custom provider, the pipeline previously fell through to a live API probe against the endpoint's /models listing. If the endpoint returned model IDs in a different format (or the probe hit OpenRouter's URL due to stale state), validation failed and the switch was rejected — leaving the user stuck on the default model. Three fixes: 1. model_switch.py: Add _find_model_in_custom_providers() helper that scans every custom_providers entry's models dict/list for a matching model name (case-insensitive, dots-vs-hyphens normalised). Insert it as step c2 in PATH B so bare names like 'claude-sonnet-4.6' resolve to the correct custom:smt-claude provider before hitting live probing. 2. model_switch.py: Extend the is_custom guard (step e) to cover custom:* slugs, preventing detect_provider_for_model() from incorrectly routing custom provider models to OpenRouter/Anthropic. 3. cli.py: Load custom_provs before calling switch_model() in _handle_model_switch(), not just in the picker path. Previously the switch call always received custom_providers=None, so step c2 never had data to search. 4. models.py: Treat custom:* slugs identically to 'custom' in validate_requested_model() so named custom providers probe their own endpoint rather than falling through to the generic error path.
|
Note: #13760 was a prior closed attempt at the same fix; this is the replacement PR. |
1 similar comment
|
Note: #13760 was a prior closed attempt at the same fix; this is the replacement PR. |
|
I have tested this solution locally. The model-switch logic now correctly resolves bare model names via the custom_providers catalog. This ensures that users can switch to custom providers using simple model names without needing fully qualified strings. The fix is stable and ready for merge.\n\nTested and confirmed. ✅ |
1 similar comment
|
I have tested this solution locally. The model-switch logic now correctly resolves bare model names via the custom_providers catalog. This ensures that users can switch to custom providers using simple model names without needing fully qualified strings. The fix is stable and ready for merge.\n\nTested and confirmed. ✅ |
|
This fix covers Reproduce: # config.yaml
model:
default: sensenova-6.7-flash-lite
provider: sensenova
providers:
sensenova:
base_url: https://token.sensenova.cn/v1
api_key: sk-xxxRun Root cause is same — I did a general check using Tests: zons-zhaozhy@c64056e30 |
|
Closing as superseded by #28908. Triage notes (medium confidence): Thanks for the contribution — the underlying problem this PR addresses has been resolved by the linked PR on current main. If you believe this was closed in error, please comment and we'll reopen. (Bulk-closed during a CLI PR triage sweep.) |
Problem
When a user types
/model claude-sonnet-4.6while on a custom provider (e.g.smt-claude), the switch fails with:Three root causes:
cli.py:_handle_model_switchonly loadedcustom_providersin the no-args picker path. When a model name was given,switch_modelwas called withcustom_providers=None.model_switch.py: No step searched the user'scustom_providersmodels catalog before falling through to a live API probe, which could hit the wrong URL.model_switch.py/models.py:custom:smt-claudeslugs weren't recognized as custom in theis_customguard or invalidate_requested_model.Fix
_find_model_in_custom_providers()helper scans everycustom_providersentry'smodelsdict/list. Matching is case-insensitive and normalises dots↔hyphens (claude-sonnet-4.6matchesclaude-sonnet-4-6).switch_model()— before any live API probe.cli.pyloadscustom_provsunconditionally before callingswitch_model().is_customguard extended to covercustom:*slugs.validate_requested_modelnormalisescustom:*→"custom".Tests
5 new tests in
tests/hermes_cli/test_model_switch_custom_providers.py. All 2440 existing tests pass.