mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-21 10:22:18 +00:00
fix(model): clear stale endpoint credentials across switches
This commit is contained in:
parent
95a3affc2e
commit
c253b07380
9 changed files with 187 additions and 17 deletions
|
|
@ -24,6 +24,8 @@ import argparse
|
|||
import os
|
||||
import subprocess
|
||||
|
||||
from hermes_cli.config import clear_model_endpoint_credentials
|
||||
|
||||
|
||||
def _prompt_auth_credentials_choice(title: str) -> str:
|
||||
"""Prompt for reuse / reauthenticate / cancel with the standard radio UI.
|
||||
|
|
@ -123,6 +125,7 @@ def _model_flow_openrouter(config, current_model=""):
|
|||
model["provider"] = "openrouter"
|
||||
model["base_url"] = OPENROUTER_BASE_URL
|
||||
model["api_mode"] = "chat_completions"
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
save_config(cfg)
|
||||
deactivate_provider()
|
||||
print(f"Default model set to: {selected} (via OpenRouter)")
|
||||
|
|
@ -341,6 +344,7 @@ def _model_flow_nous(config, current_model="", args=None):
|
|||
model_cfg["base_url"] = inference_url.rstrip("/")
|
||||
else:
|
||||
model_cfg.pop("base_url", None)
|
||||
clear_model_endpoint_credentials(model_cfg)
|
||||
config["model"] = model_cfg
|
||||
# Clear any custom endpoint that might conflict
|
||||
if get_env_value("OPENAI_BASE_URL"):
|
||||
|
|
@ -1249,6 +1253,7 @@ def _model_flow_azure_foundry(config, current_model=""):
|
|||
model["api_mode"] = api_mode
|
||||
model["default"] = effective_model
|
||||
model["auth_mode"] = auth_mode_label
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
if use_entra:
|
||||
# Persist only the non-default Entra scope so config.yaml stays tidy.
|
||||
# Azure identity selection stays in standard AZURE_* env vars.
|
||||
|
|
@ -1670,6 +1675,7 @@ def _model_flow_copilot(config, current_model=""):
|
|||
catalog=catalog,
|
||||
api_key=api_key,
|
||||
)
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
if selected_effort is not None:
|
||||
_set_reasoning_effort(cfg, selected_effort)
|
||||
save_config(cfg)
|
||||
|
|
@ -1795,6 +1801,7 @@ def _model_flow_copilot_acp(config, current_model=""):
|
|||
model["provider"] = provider_id
|
||||
model["base_url"] = effective_base
|
||||
model["api_mode"] = "chat_completions"
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
save_config(cfg)
|
||||
deactivate_provider()
|
||||
|
||||
|
|
@ -1884,6 +1891,7 @@ def _model_flow_kimi(config, current_model=""):
|
|||
model["provider"] = provider_id
|
||||
model["base_url"] = effective_base
|
||||
model.pop("api_mode", None) # let runtime auto-detect from URL
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
save_config(cfg)
|
||||
deactivate_provider()
|
||||
|
||||
|
|
@ -1997,6 +2005,7 @@ def _model_flow_stepfun(config, current_model=""):
|
|||
model["provider"] = provider_id
|
||||
model["base_url"] = effective_base
|
||||
model.pop("api_mode", None)
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
save_config(cfg)
|
||||
deactivate_provider()
|
||||
|
||||
|
|
@ -2080,6 +2089,7 @@ def _model_flow_bedrock_api_key(config, region, current_model=""):
|
|||
model["provider"] = "custom"
|
||||
model["base_url"] = mantle_base_url
|
||||
model.pop("api_mode", None) # chat_completions is the default
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
|
||||
# Also save region in bedrock config for reference
|
||||
bedrock_cfg = cfg.get("bedrock", {})
|
||||
|
|
@ -2273,6 +2283,7 @@ def _model_flow_bedrock(config, current_model=""):
|
|||
model["provider"] = "bedrock"
|
||||
model["base_url"] = f"https://bedrock-runtime.{region}.amazonaws.com"
|
||||
model.pop("api_mode", None) # bedrock_converse is auto-detected
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
|
||||
bedrock_cfg = cfg.get("bedrock", {})
|
||||
if not isinstance(bedrock_cfg, dict):
|
||||
|
|
@ -2566,6 +2577,7 @@ def _model_flow_api_key_provider(config, provider_id, current_model=""):
|
|||
cfg["model"] = model
|
||||
model["provider"] = provider_id
|
||||
model["base_url"] = effective_base
|
||||
clear_model_endpoint_credentials(model, clear_api_mode=False)
|
||||
if provider_id in {"opencode-zen", "opencode-go"}:
|
||||
model["api_mode"] = opencode_model_api_mode(provider_id, selected)
|
||||
else:
|
||||
|
|
@ -2720,6 +2732,7 @@ def _model_flow_anthropic(config, current_model=""):
|
|||
cfg["model"] = model
|
||||
model["provider"] = "anthropic"
|
||||
model.pop("base_url", None)
|
||||
clear_model_endpoint_credentials(model)
|
||||
save_config(cfg)
|
||||
deactivate_provider()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue