fix: do not build phantom Custom group when active provider is set (#206)
* fix: do not build phantom "Custom" group when active provider is set
When model.provider is a real provider (e.g. openai-codex) and model.base_url
is configured, hermes_cli reports 'custom' as an authenticated provider. The
WebUI model picker was building a separate "Custom" group for it and parking
the configured default_model there instead of under the active provider's
group — diverging from the TUI which correctly shows the model under its
configured provider.
Two fixes in api/config.py get_available_models():
1. Discard 'custom' from detected_providers when active_provider is set and
isn't 'custom' itself. The base_url belongs to the active provider.
2. Replace the substring-based default-model injection check with an exact
match against _PROVIDER_DISPLAY. The old check `active_provider.lower() in
g.get('provider', '').lower()` silently failed for hyphenated IDs like
'openai-codex' vs display name 'OpenAI Codex' (hyphen vs. space),
falling through to groups[0] and landing the model in the alphabetical
first group instead.
Adds two regression tests in tests/test_model_resolver.py covering both
conditions.
* fix: do not build phantom Custom group when active provider is set
Two bugs in get_available_models():
1. Phantom Custom group: hermes_cli reports 'custom' as authenticated
whenever model.base_url is set. With provider=openai-codex + base_url,
detected_providers contained both 'openai-codex' and 'custom', producing
a duplicate group. Fixed by discarding 'custom' from detected_providers
when the active provider is any real named provider.
2. Hyphen/space mismatch in default_model injection: the substring check
'openai-codex' in 'openai codex' is False (hyphen vs space), causing the
default model to fall through to groups[0] (alphabetically first provider)
instead of the active provider group. Fixed by using _PROVIDER_DISPLAY
for exact display-name comparison.
Also fixes test helper _available_models_with_full_cfg to clear model env
vars during the call, preventing real hermes profile env from leaking into
the test assertions.
---------
Co-authored-by: mbac <marco.baciarello@gmail.com>
Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
This commit is contained in:
@@ -680,6 +680,14 @@ def get_available_models() -> dict:
|
||||
_seen_custom_ids.add(_cp_model)
|
||||
detected_providers.add('custom')
|
||||
|
||||
# If the user configured a real model.provider, the base_url belongs to
|
||||
# THAT provider, not to a separate "Custom" group. hermes_cli reports
|
||||
# 'custom' as authenticated whenever base_url is set, which would otherwise
|
||||
# build a phantom "Custom" bucket next to the real provider's group. Drop
|
||||
# it unless the user explicitly chose 'custom' as their active provider.
|
||||
if active_provider and active_provider != 'custom':
|
||||
detected_providers.discard('custom')
|
||||
|
||||
# 5. Build model groups
|
||||
if detected_providers:
|
||||
for pid in sorted(detected_providers):
|
||||
@@ -741,11 +749,21 @@ def get_available_models() -> dict:
|
||||
_norm = lambda mid: mid.split('/', 1)[-1] if '/' in mid else mid
|
||||
all_ids_norm = {_norm(m['id']) for g in groups for m in g.get('models', [])}
|
||||
if _norm(default_model) not in all_ids_norm:
|
||||
# Determine which group to inject into
|
||||
# Determine which group to inject into. Compare against the
|
||||
# provider's display name from _PROVIDER_DISPLAY rather than
|
||||
# doing a substring match on active_provider — substring
|
||||
# matching breaks on hyphenated provider IDs like 'openai-codex'
|
||||
# vs display name 'OpenAI Codex' (hyphen vs. space), which
|
||||
# silently falls through to groups[0] and lands the model in
|
||||
# the wrong group.
|
||||
label = default_model.split('/')[-1] if '/' in default_model else default_model
|
||||
target_display = (
|
||||
_PROVIDER_DISPLAY.get(active_provider, active_provider or '').lower()
|
||||
if active_provider else ''
|
||||
)
|
||||
injected = False
|
||||
for g in groups:
|
||||
if active_provider and active_provider.lower() in g.get('provider', '').lower():
|
||||
if target_display and g.get('provider', '').lower() == target_display:
|
||||
g['models'].insert(0, {'id': default_model, 'label': label})
|
||||
injected = True
|
||||
break
|
||||
|
||||
Reference in New Issue
Block a user