fix(model): Support providers: dict for custom endpoints in /model
Two fixes for user-defined providers in config.yaml: 1. list_authenticated_providers() - now includes full models list from providers.*.models array, not just default_model. This fixes /model showing only one model when multiple are configured. 2. _get_named_custom_provider() - now checks providers: dict (new-style) in addition to custom_providers: list (legacy). This fixes credential resolution errors when switching models via /model command. Both changes are backwards compatible with existing custom_providers list format. Fixes: Only one model appears for custom providers in /model selection
This commit is contained in:
@@ -944,9 +944,16 @@ def list_authenticated_providers(
|
||||
api_url = ep_cfg.get("api", "") or ep_cfg.get("url", "") or ""
|
||||
default_model = ep_cfg.get("default_model", "")
|
||||
|
||||
# Build models list from both default_model and full models array
|
||||
models_list = []
|
||||
if default_model:
|
||||
models_list.append(default_model)
|
||||
# Also include the full models list from config
|
||||
cfg_models = ep_cfg.get("models", [])
|
||||
if isinstance(cfg_models, list):
|
||||
for m in cfg_models:
|
||||
if m and m not in models_list:
|
||||
models_list.append(m)
|
||||
|
||||
# Try to probe /v1/models if URL is set (but don't block on it)
|
||||
# For now just show what we know from config
|
||||
|
||||
@@ -275,6 +275,41 @@ def _get_named_custom_provider(requested_provider: str) -> Optional[Dict[str, An
|
||||
return None
|
||||
|
||||
config = load_config()
|
||||
|
||||
# First check providers: dict (new-style user-defined providers)
|
||||
providers = config.get("providers")
|
||||
if isinstance(providers, dict):
|
||||
for ep_name, entry in providers.items():
|
||||
if not isinstance(entry, dict):
|
||||
continue
|
||||
# Match exact name or normalized name
|
||||
name_norm = _normalize_custom_provider_name(ep_name)
|
||||
if requested_norm in {ep_name, name_norm, f"custom:{name_norm}"}:
|
||||
# Found match by provider key
|
||||
base_url = entry.get("api") or entry.get("url") or entry.get("base_url") or ""
|
||||
if base_url:
|
||||
return {
|
||||
"name": entry.get("name", ep_name),
|
||||
"base_url": base_url.strip(),
|
||||
"api_key": str(entry.get("key_env", "") or "").strip(),
|
||||
"model": entry.get("default_model", ""),
|
||||
}
|
||||
# Also check the 'name' field if present
|
||||
display_name = entry.get("name", "")
|
||||
if display_name:
|
||||
display_norm = _normalize_custom_provider_name(display_name)
|
||||
if requested_norm in {display_name, display_norm, f"custom:{display_norm}"}:
|
||||
# Found match by display name
|
||||
base_url = entry.get("api") or entry.get("url") or entry.get("base_url") or ""
|
||||
if base_url:
|
||||
return {
|
||||
"name": display_name,
|
||||
"base_url": base_url.strip(),
|
||||
"api_key": str(entry.get("key_env", "") or "").strip(),
|
||||
"model": entry.get("default_model", ""),
|
||||
}
|
||||
|
||||
# Fall back to custom_providers: list (legacy format)
|
||||
custom_providers = config.get("custom_providers")
|
||||
if not isinstance(custom_providers, list):
|
||||
if isinstance(custom_providers, dict):
|
||||
|
||||
Reference in New Issue
Block a user