mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-18 10:00:40 +08:00
大致凭借自己理解修复了一下整个检查流程,防止钩子出现问题
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user