Two related bugs in get_available_models(): 1. cfg_base_url undefined for string model configs (#117): cfg_base_url was defined inside 'elif isinstance(model_cfg, dict)' but referenced unconditionally at line 506. If model config was a plain string, NameError crashed model detection. Fix: initialize cfg_base_url='' before the conditional. 2. Configured default_model missing from dropdown (#116): The OpenRouter branch substituted _FALLBACK_MODELS without checking if the user's model.default was in the list. Models like 'openrouter/free' or custom local models were invisible. Fix: after building all groups, check if default_model is present. If not, inject it at the top of the matching provider group. Closes #116, closes #117 Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -426,6 +426,7 @@ def get_available_models() -> dict:
|
||||
groups = []
|
||||
|
||||
# 1. Read config.yaml model section
|
||||
cfg_base_url = '' # must be defined before conditional blocks (#117)
|
||||
model_cfg = cfg.get('model', {})
|
||||
cfg_base_url = ''
|
||||
if isinstance(model_cfg, str):
|
||||
@@ -607,6 +608,25 @@ def get_available_models() -> dict:
|
||||
for provider_name, models in by_provider.items():
|
||||
groups.append({'provider': provider_name, 'models': models})
|
||||
|
||||
# Ensure the user's configured default_model always appears in the dropdown.
|
||||
# It may be missing if the model isn't in any hardcoded list (e.g. openrouter/free,
|
||||
# a custom local model, or any model.default not in _FALLBACK_MODELS).
|
||||
if default_model:
|
||||
all_ids = {m['id'] for g in groups for m in g.get('models', [])}
|
||||
if default_model not in all_ids:
|
||||
# Determine which group to inject into
|
||||
label = default_model.split('/')[-1] if '/' in default_model else default_model
|
||||
injected = False
|
||||
for g in groups:
|
||||
if active_provider and active_provider.lower() in g.get('provider', '').lower():
|
||||
g['models'].insert(0, {'id': default_model, 'label': label})
|
||||
injected = True
|
||||
break
|
||||
if not injected and groups:
|
||||
groups[0]['models'].insert(0, {'id': default_model, 'label': label})
|
||||
elif not groups:
|
||||
groups.append({'provider': active_provider or 'Default', 'models': [{'id': default_model, 'label': label}]})
|
||||
|
||||
return {
|
||||
'active_provider': active_provider,
|
||||
'default_model': default_model,
|
||||
|
||||
Reference in New Issue
Block a user