From b3271038855337cdd8b58a5a7795db80cb5899d4 Mon Sep 17 00:00:00 2001 From: Nathan Esquenazi Date: Sun, 5 Apr 2026 08:29:40 -0700 Subject: [PATCH] fix: model dropdown missing custom/configured models (#116, #117) 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) --- api/config.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/api/config.py b/api/config.py index c51f624..ae3a92e 100644 --- a/api/config.py +++ b/api/config.py @@ -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,