mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-17 09:41:58 +00:00
fix(model-switch): probe /v1/models for providers without api_key
Section 3 of list_authenticated_providers (user-defined endpoints from the providers: config section) required an api_key before probing the endpoint's /v1/models for live model discovery. This broke local self-hosted backends (llama.cpp, Ollama, vLLM, etc.) that don't require authentication — they would only ever show the single default_model from config instead of the full model catalog. Section 4 (custom_providers list) already handled this correctly with the policy: probe when api_key is set OR when no explicit models are configured. Apply the same logic to Section 3 so local backends get full model discovery without requiring a placeholder api_key workaround. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
8ed16a7a0c
commit
1039e90b5e
1 changed files with 14 additions and 5 deletions
|
|
@ -1735,10 +1735,15 @@ def list_authenticated_providers(
|
|||
if fb:
|
||||
models_list = list(fb)
|
||||
|
||||
# Prefer the endpoint's live /models list when credentials are
|
||||
# available, unless the provider explicitly opts out via
|
||||
# discover_models: false (e.g. dedicated endpoints that expose
|
||||
# the entire aggregator catalog via /models).
|
||||
# Prefer the endpoint's live /models list when discoverable,
|
||||
# unless the provider explicitly opts out via discover_models: false.
|
||||
# Policy mirrors Section 4's should_probe logic:
|
||||
# - With an api_key: always probe (user opted into the endpoint).
|
||||
# - Without an api_key but with explicit models: skip — the user
|
||||
# is narrowing a public endpoint to a specific subset.
|
||||
# - Without an api_key AND no explicit models: probe anyway so
|
||||
# bare-endpoint providers (local llama.cpp / Ollama servers)
|
||||
# still show their full model catalog.
|
||||
api_key = str(ep_cfg.get("api_key", "") or "").strip()
|
||||
if not api_key:
|
||||
key_env = str(ep_cfg.get("key_env", "") or "").strip()
|
||||
|
|
@ -1746,7 +1751,11 @@ def list_authenticated_providers(
|
|||
discover = ep_cfg.get("discover_models", True)
|
||||
if isinstance(discover, str):
|
||||
discover = discover.lower() not in {"false", "no", "0"}
|
||||
if api_url and api_key and discover:
|
||||
has_explicit_models = bool(models_list)
|
||||
should_probe = bool(api_url) and discover and (
|
||||
bool(api_key) or not has_explicit_models
|
||||
)
|
||||
if should_probe:
|
||||
try:
|
||||
from hermes_cli.models import fetch_api_models
|
||||
live_models = fetch_api_models(api_key, api_url)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue