fix(cli): use custom provider default_model when --provider is set

hermes chat --provider <name> without -m sent the global model.default
to the custom endpoint. Named custom entries already expose
default_model via _get_named_custom_provider(); honor that when the
user selected the provider and did not pass an explicit model.

Fixes #86978
This commit is contained in:
Christopher
2026-08-15 15:15:27 +02:00
committed by Teknium
parent b7936c892d
commit d6688adcc2
2 changed files with 75 additions and 0 deletions
+15
View File
@@ -4856,6 +4856,21 @@ class HermesCLI(CLIAgentSetupMixin, CLICommandsMixin, CLIBillingMixin):
or os.getenv("HERMES_INFERENCE_PROVIDER")
or "auto"
)
# `--provider <custom>` without `-m` must use that entry's
# default_model. Otherwise the global model.default is sent to the
# custom endpoint and the compressor inherits the wrong context
# length (#86978). Explicit `-m` still wins.
if not model and provider:
try:
from hermes_cli.runtime_provider import _get_named_custom_provider
_named_custom = _get_named_custom_provider(provider)
except Exception:
_named_custom = None
_provider_default = str((_named_custom or {}).get("model") or "").strip()
if _provider_default:
self.model = _provider_default
self._model_is_default = False
self._provider_source: Optional[str] = None
self.provider = self.requested_provider
self.api_mode = "chat_completions"
+60
View File
@@ -123,6 +123,66 @@ def _import_cli():
return importlib.import_module("cli")
def test_provider_flag_uses_named_custom_default_model(monkeypatch):
"""`--provider <custom>` without `-m` uses that entry's default_model (#86978)."""
cli = _import_cli()
monkeypatch.setitem(
cli.CLI_CONFIG,
"model",
{"default": "tencent/hy3:free", "provider": "nous"},
)
config = {
"model": {"default": "tencent/hy3:free", "provider": "nous"},
"providers": {
"gmk-lan": {
"name": "GMK Local",
"base_url": "http://gmk.lan:9931/v1",
"api_key": "not-needed",
"default_model": "/models/gemma.gguf",
}
},
}
monkeypatch.setattr("hermes_cli.config.load_config", lambda: config)
monkeypatch.setattr("hermes_cli.runtime_provider.load_config", lambda: config)
shell = cli.HermesCLI(provider="gmk-lan", compact=True, max_turns=1)
assert shell.model == "/models/gemma.gguf"
assert shell.requested_provider == "gmk-lan"
def test_explicit_model_wins_over_provider_default_model(monkeypatch):
"""`-m` still wins when `--provider` also names a custom default_model."""
cli = _import_cli()
monkeypatch.setitem(
cli.CLI_CONFIG,
"model",
{"default": "tencent/hy3:free", "provider": "nous"},
)
config = {
"model": {"default": "tencent/hy3:free", "provider": "nous"},
"providers": {
"gmk-lan": {
"name": "GMK Local",
"base_url": "http://gmk.lan:9931/v1",
"api_key": "not-needed",
"default_model": "/models/gemma.gguf",
}
},
}
monkeypatch.setattr("hermes_cli.config.load_config", lambda: config)
monkeypatch.setattr("hermes_cli.runtime_provider.load_config", lambda: config)
shell = cli.HermesCLI(
provider="gmk-lan",
model="explicit-id",
compact=True,
max_turns=1,
)
assert shell.model == "explicit-id"
def test_hermes_cli_init_does_not_eagerly_resolve_runtime_provider(monkeypatch):
cli = _import_cli()
calls = {"count": 0}