feat: 综合平台services多服务支持+SW网络优先缓存修复+适配层/定时任务完善
This commit is contained in:
+35
-5
@@ -100,11 +100,41 @@ class OpenAIAdapter(_AIBase):
|
||||
|
||||
@register("minimax-api")
|
||||
class MinimaxAdapter(_AIBase):
|
||||
# Minimax 需 group_id,余额接口因账号类型而异,此处为骨架待完善
|
||||
required_config = ["api_key", "group_id"]
|
||||
"""Minimax 适配器(余额查询)
|
||||
|
||||
接口:GET https://api.minimax.chat/v1/balance
|
||||
认证:Bearer api_key(group_id 仅部分旧接口需要,余额查询非必需)
|
||||
响应示例:{"balance": 123.45, "currency": "CNY", ...}
|
||||
注:Minimax 国内版端点为 api.minimaxi.com,国际版为 api.minimax.chat,
|
||||
两者 API Key 不通用;默认使用国际版端点,可通过 config["base_url"] 覆盖。
|
||||
"""
|
||||
|
||||
required_config = ["api_key"]
|
||||
BASE = "https://api.minimax.chat/v1"
|
||||
|
||||
def _base_url(self) -> str:
|
||||
return (self.config.get("base_url") or self.BASE).rstrip("/")
|
||||
|
||||
def _balance(self) -> AccountInfo:
|
||||
data = self._get(self._base_url() + "/balance")
|
||||
balance = data.get("balance")
|
||||
try:
|
||||
balance = float(balance) if balance is not None else None
|
||||
except (TypeError, ValueError):
|
||||
balance = None
|
||||
currency = data.get("currency") or "CNY"
|
||||
return AccountInfo(balance=balance, currency=currency, raw=data)
|
||||
|
||||
def test_connection(self) -> dict:
|
||||
if not self.config.get("group_id"):
|
||||
return {"ok": False, "message": "Minimax 需配置 group_id(适配器余额接口待完善)"}
|
||||
return {"ok": False, "message": "Minimax 适配器余额接口待完善(请提供具体接口文档)"}
|
||||
try:
|
||||
acc = self._balance()
|
||||
if acc.balance is not None:
|
||||
return {"ok": True, "message": f"连接成功,余额 {acc.balance} {acc.currency}"}
|
||||
return {"ok": True, "message": "连接成功(未返回余额字段)"}
|
||||
except httpx.HTTPStatusError as e:
|
||||
return self._http_error(e)
|
||||
except Exception as e: # noqa: BLE001
|
||||
return {"ok": False, "message": str(e)}
|
||||
|
||||
def get_account(self) -> AccountInfo:
|
||||
return self._balance()
|
||||
|
||||
Reference in New Issue
Block a user