From d121d08d0568c3035096ab6065cc58453c823776 Mon Sep 17 00:00:00 2001 From: advent259141 <2968474907@qq.com> Date: Sun, 29 Jun 2025 09:57:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=A7=E8=87=B4=E5=87=AD=E5=80=9F=E8=87=AA?= =?UTF-8?q?=E5=B7=B1=E7=90=86=E8=A7=A3=E4=BF=AE=E5=A4=8D=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=E6=95=B4=E4=B8=AA=E6=A3=80=E6=9F=A5=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E9=98=B2=E6=AD=A2=E9=92=A9=E5=AD=90=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pipeline/process_stage/method/llm_request.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index e352953aa..d6542da88 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -89,6 +89,11 @@ class LLMRequestSubStage(Stage): "provider_request 必须是 ProviderRequest 类型。" ) + # 检查会话级别的LLM启停状态(防止事件钩子绕过会话级别限制) + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,拒绝事件钩子/插件的 LLM 请求。") + return + if req.conversation: all_contexts = json.loads(req.conversation.history) req.contexts = self._process_tool_message_pairs( @@ -189,6 +194,12 @@ class LLMRequestSubStage(Stage): need_loop = True while need_loop: need_loop = False + + # 在每次实际请求 LLM 前检查会话级别的启停状态,这可以防止插件或函数工具调用时绕过会话级别的限制 + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,终止 LLM 请求。") + return + logger.debug(f"提供商请求 Payload: {req}") final_llm_response = None @@ -303,6 +314,11 @@ class LLMRequestSubStage(Stage): async def _handle_webchat(self, event: AstrMessageEvent, req: ProviderRequest): """处理 WebChat 平台的特殊情况,包括第一次 LLM 对话时总结对话内容生成 title""" + # 检查会话级别的LLM启停状态,防止标题生成功能绕过会话级别限制 + if not SessionServiceManager.should_process_llm_request(event): + logger.debug(f"会话 {event.unified_msg_origin} 禁用了 LLM,跳过 WebChat 标题生成。") + return + conversation = await self.conv_manager.get_conversation( event.unified_msg_origin, req.conversation.cid )