feat: add cmhub settings panel
This commit is contained in:
@@ -491,6 +491,30 @@ def fetch_cmhub_models(base_url, api_key, connect_timeout=10, read_timeout=30):
|
||||
return [copy.deepcopy(model) for model in models if isinstance(model, dict)]
|
||||
|
||||
|
||||
def fetch_cmhub_balance(base_url, api_key, connect_timeout=10, read_timeout=30):
|
||||
"""Fetch cmhub point balance for settings UI."""
|
||||
|
||||
base_url = str(base_url or "").strip()
|
||||
api_key = str(api_key or "")
|
||||
if not base_url:
|
||||
raise CMHubError("cmhub_not_configured", "请去⑤设置配置 cmhub Base URL")
|
||||
if not api_key:
|
||||
raise CMHubError("cmhub_not_configured", "请去⑤设置配置 cmhub API Key")
|
||||
data = _cmhub_call_with_retry(
|
||||
"GET",
|
||||
appconfig.cmhub_request_url(base_url, "/api/v1/balance"),
|
||||
api_key,
|
||||
payload=None,
|
||||
connect_timeout=max(1, int(connect_timeout or 10)),
|
||||
read_timeout=max(1, int(read_timeout or 30)),
|
||||
attempts=1,
|
||||
on_retry=None,
|
||||
)
|
||||
if "points_balance" not in data:
|
||||
raise CMHubError("bad_response", "cmhub 余额返回格式错误")
|
||||
return copy.deepcopy(data)
|
||||
|
||||
|
||||
def _ai_backend(ai_cfg):
|
||||
backend = str(ai_cfg.get("backend", "direct") or "direct").strip().lower()
|
||||
if backend not in appconfig.AI_BACKENDS:
|
||||
|
||||
Reference in New Issue
Block a user