mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2026-10-11 15:00:00 +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
@@ -30,6 +30,23 @@ class CodeExecutionTool(ServerSideTool):
|
||||
self.timeout = timeout
|
||||
|
||||
|
||||
class XSearchTool(ServerSideTool):
|
||||
"""原生 X (推特) 搜索工具 (Grok独占)"""
|
||||
|
||||
type_id = "x_search"
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
allowed_x_handles: list[str] | None = None,
|
||||
excluded_x_handles: list[str] | None = None,
|
||||
):
|
||||
super().__init__(
|
||||
name="x_search", description="在 X (Twitter) 上搜索推文、用户资料和时间线。"
|
||||
)
|
||||
self.allowed_x_handles = allowed_x_handles
|
||||
self.excluded_x_handles = excluded_x_handles
|
||||
|
||||
|
||||
class ComputerUseTool(ServerSideTool):
|
||||
"""原生的桌面环境控制工具"""
|
||||
|
||||
@@ -70,10 +87,7 @@ class UrlContextTool(ServerSideTool):
|
||||
|
||||
class Native:
|
||||
"""
|
||||
云端原生工具命名空间工厂 (Namespace Factory)。
|
||||
|
||||
为开发者提供统一的云端内置工具调用入口,享受顶级 IDE 补全体验。
|
||||
此类工具仅会向大模型提供描述,物理执行发生在各大模型厂商的服务端。
|
||||
云端原生工具命名空间工厂
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
@@ -89,6 +103,17 @@ class Native:
|
||||
"""
|
||||
return WebSearchTool(name, description, dynamic_threshold, domain_filters)
|
||||
|
||||
@classmethod
|
||||
def x_search(
|
||||
cls,
|
||||
allowed_x_handles: list[str] | None = None,
|
||||
excluded_x_handles: list[str] | None = None,
|
||||
) -> XSearchTool:
|
||||
"""
|
||||
原生 X (Twitter) 检索工具 (Grok 独占)。
|
||||
"""
|
||||
return XSearchTool(allowed_x_handles, excluded_x_handles)
|
||||
|
||||
@classmethod
|
||||
def code_execution(
|
||||
cls, name: str = "code_execution", timeout: int | None = None
|
||||
|
||||
@@ -64,8 +64,10 @@ class MCPServerConfig(BaseModel):
|
||||
values["transport"] = values.pop("type")
|
||||
|
||||
transport_val = values.get("transport")
|
||||
if isinstance(transport_val, str) and transport_val.lower() == "streamablehttp":
|
||||
values["transport"] = "streamable-http"
|
||||
if isinstance(transport_val, str):
|
||||
t_lower = transport_val.lower()
|
||||
if t_lower in ("streamablehttp", "http"):
|
||||
values["transport"] = "streamable-http"
|
||||
|
||||
headers = values.get("headers")
|
||||
if isinstance(headers, dict):
|
||||
|
||||
@@ -98,8 +98,15 @@ async def filtered_stdio_client(
|
||||
await filtered_send.send(item)
|
||||
except anyio.ClosedResourceError:
|
||||
pass
|
||||
except BaseException as e:
|
||||
logger.debug(
|
||||
f"🔇 [MCP Stdout Filter] 捕获到底层流异常: {type(e).__name__}: {e}"
|
||||
)
|
||||
finally:
|
||||
await filtered_send.aclose()
|
||||
try:
|
||||
await filtered_send.aclose()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async with anyio.create_task_group() as tg:
|
||||
tg.start_soon(_forward_stdout)
|
||||
@@ -540,7 +547,12 @@ class MCPToolkit(BaseToolkit):
|
||||
await self._stop_event.wait()
|
||||
return
|
||||
|
||||
except Exception as e:
|
||||
except BaseException as e:
|
||||
if isinstance(
|
||||
e, asyncio.CancelledError | KeyboardInterrupt | SystemExit
|
||||
):
|
||||
raise e
|
||||
|
||||
from zhenxun.services.ai.core.exceptions import SandboxFatalError
|
||||
|
||||
if isinstance(e, SandboxFatalError):
|
||||
@@ -548,23 +560,30 @@ class MCPToolkit(BaseToolkit):
|
||||
|
||||
if attempt < max_attempts:
|
||||
logger.warning(
|
||||
f"⚠️ [{self.server_name}] 进程启动或运行异常崩溃,"
|
||||
f"⚠️ [{self.server_name}] 进程启动或"
|
||||
f"底层流异常崩溃 ({type(e).__name__}),"
|
||||
"疑似环境损坏。触发自愈机制 (准备重试)..."
|
||||
)
|
||||
self._init_exception = e
|
||||
self._init_exception = (
|
||||
e if isinstance(e, Exception) else Exception(str(e))
|
||||
)
|
||||
self._shared_session = None
|
||||
if not self._is_initialized:
|
||||
self._is_initialized = False
|
||||
continue
|
||||
|
||||
if not isinstance(e, Exception):
|
||||
raise Exception(f"底层致命异常: {e}") from e
|
||||
raise e
|
||||
|
||||
except Exception as e:
|
||||
self._init_exception = e
|
||||
except BaseException as e:
|
||||
if isinstance(e, asyncio.CancelledError | KeyboardInterrupt | SystemExit):
|
||||
raise e
|
||||
self._init_exception = e if isinstance(e, Exception) else Exception(str(e))
|
||||
logger.error(
|
||||
f"MCP 服务器 '{self.server_name}' "
|
||||
f"初始化连接失败(模式: {self.transport})。"
|
||||
f"错误原因: {e}"
|
||||
f"初始化连接或运行期间发生底层故障(模式: {self.transport})。"
|
||||
f"错误类型: {type(e).__name__}, 原因: {e}"
|
||||
)
|
||||
if "Connection closed" in str(e):
|
||||
logger.error(
|
||||
|
||||
Reference in New Issue
Block a user