fix(cli): omit empty api_mode when probing custom models

This commit is contained in:
LeonSGP43 2026-04-25 00:53:07 +08:00 committed by Teknium
parent 52c539d53a
commit 0df7e61d2c
2 changed files with 11 additions and 7 deletions

View file

@ -3413,10 +3413,10 @@ def _model_flow_named_custom(config, provider_info):
print() print()
print("Fetching available models...") print("Fetching available models...")
models = fetch_api_models( fetch_kwargs = {"timeout": 8.0}
api_key, base_url, timeout=8.0, if api_mode:
api_mode=api_mode or None, fetch_kwargs["api_mode"] = api_mode
) models = fetch_api_models(api_key, base_url, **fetch_kwargs)
if models: if models:
default_idx = 0 default_idx = 0

View file

@ -56,7 +56,6 @@ class TestCustomProviderModelSwitch:
"sk-test", "sk-test",
"https://vllm.example.com/v1", "https://vllm.example.com/v1",
timeout=8.0, timeout=8.0,
api_mode=None,
) )
def test_can_switch_to_different_model(self, config_home): def test_can_switch_to_different_model(self, config_home):
@ -141,12 +140,18 @@ class TestCustomProviderModelSwitch:
"api_mode": "anthropic_messages", "api_mode": "anthropic_messages",
} }
with patch("hermes_cli.models.fetch_api_models", return_value=["claude-3"]), \ with patch("hermes_cli.models.fetch_api_models", return_value=["claude-3"]) as mock_fetch, \
patch.dict("sys.modules", {"simple_term_menu": None}), \ patch.dict("sys.modules", {"simple_term_menu": None}), \
patch("builtins.input", return_value="1"), \ patch("builtins.input", return_value="1"), \
patch("builtins.print"): patch("builtins.print"):
_model_flow_named_custom({}, provider_info) _model_flow_named_custom({}, provider_info)
mock_fetch.assert_called_once_with(
"***",
"https://proxy.example.com/anthropic",
timeout=8.0,
api_mode="anthropic_messages",
)
config = yaml.safe_load((config_home / "config.yaml").read_text()) or {} config = yaml.safe_load((config_home / "config.yaml").read_text()) or {}
model = config.get("model") model = config.get("model")
assert isinstance(model, dict) assert isinstance(model, dict)
@ -215,7 +220,6 @@ class TestCustomProviderModelSwitch:
"sk-live-example-provider", "sk-live-example-provider",
"https://api.example-provider.test/v1", "https://api.example-provider.test/v1",
timeout=8.0, timeout=8.0,
api_mode=None,
) )
config = yaml.safe_load(config_path.read_text()) or {} config = yaml.safe_load(config_path.read_text()) or {}
assert config["model"]["api_key"] == "${EXAMPLE_PROVIDER_API_KEY}" assert config["model"]["api_key"] == "${EXAMPLE_PROVIDER_API_KEY}"