Skip to content

fix: auto-detect provider when switching models via /model#1177

Closed
virtaava wants to merge 1 commit intoNousResearch:mainfrom
virtaava:fix/model-provider-auto-detect
Closed

fix: auto-detect provider when switching models via /model#1177
virtaava wants to merge 1 commit intoNousResearch:mainfrom
virtaava:fix/model-provider-auto-detect

Conversation

@virtaava
Copy link
Contributor

Summary

The /model slash command currently requires explicit provider:model syntax to switch providers (e.g., /model deepseek:deepseek-chat). If the user types just /model deepseek-chat while on a different provider (e.g., openai-codex), the model name changes but the provider stays the same — causing silent API errors because the old provider doesn't serve that model.

This PR adds detect_provider_for_model() which checks static provider catalogs (no network calls) to find which provider serves the requested model and auto-switches. Direct providers are preferred over aggregators (nous, openrouter) that list models from many sources.

Changes:

  • hermes_cli/models.py — Add detect_provider_for_model() function; add deepseek, google, nvidia, ollama to static provider catalogs and aliases
  • gateway/run.py — Call auto-detection after parse_model_input() in _handle_model_command()
  • cli.py — Same auto-detection in the CLI's /model handler
  • tests/hermes_cli/test_models.py — 5 tests covering direct match, aggregator deprioritization, current-provider skip, OpenRouter fallback, and unknown models

Backward-compatible: Explicit provider:model syntax still takes precedence — auto-detection only runs when no provider prefix is given.

Test plan

  • python -m pytest tests/hermes_cli/test_models.py -x -q — all 15 tests pass
  • Manual: /model deepseek-chat from openai-codex provider auto-switches to deepseek
  • Manual: /model deepseek:deepseek-chat still works as before (explicit syntax)
  • Manual: /model gpt-5.2-codex while on openai-codex does NOT trigger auto-switch

🤖 Generated with Claude Code

When a user types `/model deepseek-chat` while on a different provider
(e.g. openai-codex), the model name would change but the provider stayed
the same, causing silent API errors. Now `detect_provider_for_model()`
checks static catalogs to find which provider serves the requested model
and auto-switches. Direct providers are preferred over aggregators (nous,
openrouter) that list models from many sources.

Explicit `provider:model` syntax still takes precedence — auto-detection
only runs when no provider prefix is given.

Also adds deepseek, google, nvidia, and ollama to the static provider
catalogs and aliases.
teknium1 added a commit that referenced this pull request Mar 16, 2026
When typing /model deepseek-chat while on a different provider, the
model name now auto-resolves to the correct provider instead of
silently staying on the wrong one and causing API errors.

Detection priority:
1. Direct provider with credentials (e.g. DEEPSEEK_API_KEY set)
2. OpenRouter catalog match with proper slug remapping
3. Direct provider without creds (clear error beats silent failure)

Also adds DeepSeek as a first-class API-key provider — just set
DEEPSEEK_API_KEY and /model deepseek-chat routes directly.

Bare model names get remapped to proper OpenRouter slugs:
  /model gpt-5.4 → openai/gpt-5.4
  /model claude-opus-4.6 → anthropic/claude-opus-4.6

Salvages the concept from PR #1177 by @virtaava with credential
awareness and OpenRouter slug mapping added.

Co-authored-by: virtaava <virtaava@users.noreply.github.com>
@teknium1
Copy link
Contributor

Merged via PR #1506. Your auto-detection concept was salvaged onto current main with credential awareness and OpenRouter slug mapping added. DeepSeek was also registered as a first-class provider. Thanks for the idea!

@teknium1 teknium1 closed this Mar 16, 2026
teknium1 added a commit that referenced this pull request Mar 16, 2026
When typing /model deepseek-chat while on a different provider, the
model name now auto-resolves to the correct provider instead of
silently staying on the wrong one and causing API errors.

Detection priority:
1. Direct provider with credentials (e.g. DEEPSEEK_API_KEY set)
2. OpenRouter catalog match with proper slug remapping
3. Direct provider without creds (clear error beats silent failure)

Also adds DeepSeek as a first-class API-key provider — just set
DEEPSEEK_API_KEY and /model deepseek-chat routes directly.

Bare model names get remapped to proper OpenRouter slugs:
  /model gpt-5.4 → openai/gpt-5.4
  /model claude-opus-4.6 → anthropic/claude-opus-4.6

Salvages the concept from PR #1177 by @virtaava with credential
awareness and OpenRouter slug mapping added.

Co-authored-by: virtaava <virtaava@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants