mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-29 07:21:37 +08:00
Compare commits
1 Commits
fix/plugin
...
fix/model-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0d3d2a2631 |
18
cli.py
18
cli.py
@@ -5270,24 +5270,22 @@ class HermesCLI:
|
|||||||
# Parse --provider and --global flags
|
# Parse --provider and --global flags
|
||||||
model_input, explicit_provider, persist_global = parse_model_flags(raw_args)
|
model_input, explicit_provider, persist_global = parse_model_flags(raw_args)
|
||||||
|
|
||||||
|
# Load providers for switch_model (picker path needs them below)
|
||||||
user_provs = None
|
user_provs = None
|
||||||
custom_provs = None
|
custom_provs = None
|
||||||
|
try:
|
||||||
|
from hermes_cli.config import get_compatible_custom_providers, load_config
|
||||||
|
cfg = load_config()
|
||||||
|
user_provs = cfg.get("providers")
|
||||||
|
custom_provs = get_compatible_custom_providers(cfg)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
# No args at all: open prompt_toolkit-native picker modal
|
# No args at all: open prompt_toolkit-native picker modal
|
||||||
if not model_input and not explicit_provider:
|
if not model_input and not explicit_provider:
|
||||||
model_display = self.model or "unknown"
|
model_display = self.model or "unknown"
|
||||||
provider_display = get_label(self.provider) if self.provider else "unknown"
|
provider_display = get_label(self.provider) if self.provider else "unknown"
|
||||||
|
|
||||||
user_provs = None
|
|
||||||
custom_provs = None
|
|
||||||
try:
|
|
||||||
from hermes_cli.config import get_compatible_custom_providers, load_config
|
|
||||||
cfg = load_config()
|
|
||||||
user_provs = cfg.get("providers")
|
|
||||||
custom_provs = get_compatible_custom_providers(cfg)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
providers = list_authenticated_providers(
|
providers = list_authenticated_providers(
|
||||||
current_provider=self.provider or "",
|
current_provider=self.provider or "",
|
||||||
|
|||||||
@@ -831,9 +831,14 @@ def switch_model(
|
|||||||
requested=current_provider,
|
requested=current_provider,
|
||||||
target_model=new_model,
|
target_model=new_model,
|
||||||
)
|
)
|
||||||
api_key = runtime.get("api_key", "")
|
# If resolution fell through to "custom" (e.g. named custom provider like
|
||||||
base_url = runtime.get("base_url", "")
|
# "ollama-launch" that resolve_runtime_provider doesn't know), keep existing
|
||||||
api_mode = runtime.get("api_mode", "")
|
# credentials. Otherwise use the resolved values (picks up credential rotation,
|
||||||
|
# base_url adjustments for OpenCode, etc.).
|
||||||
|
if runtime.get("provider") != "custom":
|
||||||
|
api_key = runtime.get("api_key", "")
|
||||||
|
base_url = runtime.get("base_url", "")
|
||||||
|
api_mode = runtime.get("api_mode", "")
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -867,16 +872,31 @@ def switch_model(
|
|||||||
"message": f"Could not validate `{new_model}`: {e}",
|
"message": f"Could not validate `{new_model}`: {e}",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Override rejection if model is in the user's saved provider config.
|
||||||
|
# API /v1/models may not list cloud/aliased models even though the server supports them.
|
||||||
if not validation.get("accepted"):
|
if not validation.get("accepted"):
|
||||||
msg = validation.get("message", "Invalid model")
|
override = False
|
||||||
return ModelSwitchResult(
|
if user_providers:
|
||||||
success=False,
|
for up in user_providers:
|
||||||
new_model=new_model,
|
if isinstance(up, dict) and up.get("provider") == target_provider:
|
||||||
target_provider=target_provider,
|
cfg_models = up.get("models", [])
|
||||||
provider_label=provider_label,
|
if new_model in cfg_models or any(
|
||||||
is_global=is_global,
|
m.get("name") == new_model for m in cfg_models if isinstance(m, dict)
|
||||||
error_message=msg,
|
):
|
||||||
)
|
override = True
|
||||||
|
break
|
||||||
|
if override:
|
||||||
|
validation = {"accepted": True, "persist": True, "recognized": False, "message": validation.get("message", "")}
|
||||||
|
else:
|
||||||
|
msg = validation.get("message", "Invalid model")
|
||||||
|
return ModelSwitchResult(
|
||||||
|
success=False,
|
||||||
|
new_model=new_model,
|
||||||
|
target_provider=target_provider,
|
||||||
|
provider_label=provider_label,
|
||||||
|
is_global=is_global,
|
||||||
|
error_message=msg,
|
||||||
|
)
|
||||||
|
|
||||||
# Apply auto-correction if validation found a closer match
|
# Apply auto-correction if validation found a closer match
|
||||||
if validation.get("corrected_model"):
|
if validation.get("corrected_model"):
|
||||||
|
|||||||
@@ -2571,8 +2571,8 @@ def validate_requested_model(
|
|||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"accepted": False,
|
"accepted": True,
|
||||||
"persist": False,
|
"persist": True,
|
||||||
"recognized": False,
|
"recognized": False,
|
||||||
"message": message,
|
"message": message,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -712,6 +712,18 @@ def _apply_model_switch(sid: str, session: dict, raw_input: str) -> dict:
|
|||||||
current_base_url = str(runtime.get("base_url", "") or "")
|
current_base_url = str(runtime.get("base_url", "") or "")
|
||||||
current_api_key = str(runtime.get("api_key", "") or "")
|
current_api_key = str(runtime.get("api_key", "") or "")
|
||||||
|
|
||||||
|
# Load user-defined providers so switch_model can resolve named custom
|
||||||
|
# endpoints (e.g. "ollama-launch") and validate against saved model lists.
|
||||||
|
user_provs = None
|
||||||
|
custom_provs = None
|
||||||
|
try:
|
||||||
|
from hermes_cli.config import get_compatible_custom_providers, load_config
|
||||||
|
cfg = load_config()
|
||||||
|
user_provs = [{"provider": k, **v} for k, v in (cfg.get("providers") or {}).items()]
|
||||||
|
custom_provs = get_compatible_custom_providers(cfg)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
result = switch_model(
|
result = switch_model(
|
||||||
raw_input=model_input,
|
raw_input=model_input,
|
||||||
current_provider=current_provider,
|
current_provider=current_provider,
|
||||||
@@ -720,6 +732,8 @@ def _apply_model_switch(sid: str, session: dict, raw_input: str) -> dict:
|
|||||||
current_api_key=current_api_key,
|
current_api_key=current_api_key,
|
||||||
is_global=persist_global,
|
is_global=persist_global,
|
||||||
explicit_provider=explicit_provider,
|
explicit_provider=explicit_provider,
|
||||||
|
user_providers=user_provs,
|
||||||
|
custom_providers=custom_provs,
|
||||||
)
|
)
|
||||||
if not result.success:
|
if not result.success:
|
||||||
raise ValueError(result.error_message or "model switch failed")
|
raise ValueError(result.error_message or "model switch failed")
|
||||||
|
|||||||
Reference in New Issue
Block a user