mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-05 03:39:59 +08:00
✨ feat(llm): 优化 DeepSeek 适配器 (#2160)
检查bot是否运行正常 / bot check (push) Canceled after 0s
CodeQL Code Security Analysis / Analyze (python) (push) Canceled after 0s
Ruff Lint / Ruff Lint (push) Canceled after 0s
Sequential Lint and Type Check / ruff-call (push) Canceled after 0s
Release Drafter / Update Release Draft (push) Canceled after 0s
Force Sync to Aliyun / sync (push) Canceled after 0s
Update Version / update-version (push) Canceled after 0s
Sequential Lint and Type Check / pyright-call (push) Canceled after 0s
检查bot是否运行正常 / bot check (push) Canceled after 0s
CodeQL Code Security Analysis / Analyze (python) (push) Canceled after 0s
Ruff Lint / Ruff Lint (push) Canceled after 0s
Sequential Lint and Type Check / ruff-call (push) Canceled after 0s
Release Drafter / Update Release Draft (push) Canceled after 0s
Force Sync to Aliyun / sync (push) Canceled after 0s
Update Version / update-version (push) Canceled after 0s
Sequential Lint and Type Check / pyright-call (push) Canceled after 0s
* ✨ feat(llm): 新增 Grok 适配器及 API 密钥重置指令 - 新增 Grok 适配器并支持原生推特检索工具 `x_search` - 优化 DeepSeek 适配器以迁移至 Responses 协议,增强多模态支持 - 在 LLM 管理插件中新增 `llm reset` 子命令以重置 Key 状态 - 增强 MCP 连接异常处理及流关闭容错能力 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: webjoin111 <455457521@qq.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
webjoin111
pre-commit-ci[bot]
parent
39ed1ade14
commit
33d6ea1335
@@ -44,6 +44,11 @@ __plugin_meta__ = PluginMetadata(
|
||||
llm keys <ProviderName>
|
||||
- 查看指定提供商的所有API Key状态。
|
||||
|
||||
llm reset [ProviderName]
|
||||
- 重置 API Key 的熔断与冷却状态。
|
||||
- 带参数: 仅重置指定提供商的所有 Key。
|
||||
- 不带参数: 全局重置所有提供商的所有 Key。
|
||||
|
||||
llm mcp [action] [targets...]
|
||||
- 管理 MCP (Model Context Protocol) 服务。
|
||||
- 不带参数: 查看当前配置的 MCP 服务列表及序号。
|
||||
@@ -74,6 +79,9 @@ llm_cmd = on_alconna(
|
||||
"test", Args["model_name", str], alias=["ping"], help_text="测试模型连通性"
|
||||
),
|
||||
Subcommand("keys", Args["provider_name", str], help_text="查看API密钥状态"),
|
||||
Subcommand(
|
||||
"reset", Args["provider_name", str, ""], help_text="重置API密钥状态"
|
||||
),
|
||||
Subcommand(
|
||||
"mcp",
|
||||
Option("添加", Args["json_strs", MultiVar(str)], alias=["add"]),
|
||||
@@ -173,6 +181,22 @@ async def handle_keys(arp: Arparma, provider_name: Match[str]):
|
||||
await llm_cmd.finish(MessageUtils.build_message(image))
|
||||
|
||||
|
||||
@llm_cmd.assign("reset")
|
||||
async def handle_reset(arp: Arparma):
|
||||
"""处理 'llm reset' 命令"""
|
||||
provider_name = arp.query("reset.provider_name", "").strip()
|
||||
target_log = provider_name if provider_name else "ALL"
|
||||
logger.info(
|
||||
f"执行 API Key 重置操作: {target_log}",
|
||||
command="LLM Manage",
|
||||
session=arp.header_result,
|
||||
)
|
||||
_success, msg = await DataSource.reset_keys(
|
||||
provider_name if provider_name else None
|
||||
)
|
||||
await llm_cmd.finish(msg)
|
||||
|
||||
|
||||
@llm_cmd.assign("mcp")
|
||||
async def handle_mcp(arp: Arparma, event: Event):
|
||||
"""处理 'llm mcp' 命令"""
|
||||
|
||||
@@ -6,8 +6,10 @@ from zhenxun.configs.path_config import DATA_PATH
|
||||
from zhenxun.services.ai.core.exceptions import LLMException
|
||||
from zhenxun.services.ai.llm.api import chat
|
||||
from zhenxun.services.ai.llm.manager import (
|
||||
get_configured_providers,
|
||||
get_model_instance,
|
||||
list_available_models,
|
||||
reset_key_status,
|
||||
)
|
||||
from zhenxun.services.ai.tools.providers.mcp.provider import mcp_provider
|
||||
|
||||
@@ -105,6 +107,34 @@ class DataSource:
|
||||
|
||||
return sorted_stats_list
|
||||
|
||||
@staticmethod
|
||||
async def reset_keys(provider_name: str | None = None) -> tuple[bool, str]:
|
||||
"""重置指定或所有提供商的 API Key 状态"""
|
||||
providers = get_configured_providers()
|
||||
|
||||
if provider_name:
|
||||
target = next(
|
||||
(p for p in providers if p.name.lower() == provider_name.lower()), None
|
||||
)
|
||||
if not target:
|
||||
return False, f"❌ 未找到提供商 '{provider_name}',请检查名称是否正确。"
|
||||
await reset_key_status(target.name)
|
||||
return (
|
||||
True,
|
||||
f"✅ 已成功重置提供商 '{target.name}'"
|
||||
"的所有 API Key 状态为健康 (HEALTHY)。",
|
||||
)
|
||||
else:
|
||||
count = 0
|
||||
for p in providers:
|
||||
await reset_key_status(p.name)
|
||||
count += 1
|
||||
return (
|
||||
True,
|
||||
f"✅ 已成功重置所有提供商 (共 {count} 个) "
|
||||
"的 API Key 状态为健康 (HEALTHY)。",
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
async def get_mcp_list() -> list[dict[str, Any]]:
|
||||
"""获取排序后的 MCP 列表"""
|
||||
|
||||
Reference in New Issue
Block a user