From 7f6ed674b49db40535ad406925f17998e33aaea5 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 28 Feb 2025 00:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=BC=EF=B8=8F=F0=9F=90=9B=20fix:=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=92=A9=E5=AD=90=E5=87=BD=E6=95=B0=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E7=BB=88=E6=AD=A2=E4=BA=8B=E4=BB=B6=E4=BC=A0=E6=92=AD?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8D=E6=9F=90?= =?UTF-8?q?=E4=BA=9B=E6=83=85=E5=86=B5=E4=B8=8B=E7=BB=88=E6=AD=A2=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E4=BC=A0=E6=92=AD=E5=90=8E=E4=BB=8D=E7=84=B6=E4=BC=9A?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=20LLM=20=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/pipeline/process_stage/method/llm_request.py | 9 +++++++++ astrbot/core/pipeline/respond/stage.py | 4 ++++ astrbot/core/pipeline/result_decorate/stage.py | 4 ++++ astrbot/core/pipeline/scheduler.py | 3 +++ 4 files changed, 20 insertions(+) diff --git a/astrbot/core/pipeline/process_stage/method/llm_request.py b/astrbot/core/pipeline/process_stage/method/llm_request.py index ce998e7cb..fd9dde12d 100644 --- a/astrbot/core/pipeline/process_stage/method/llm_request.py +++ b/astrbot/core/pipeline/process_stage/method/llm_request.py @@ -75,6 +75,10 @@ class LLMRequestSubStage(Stage): except BaseException: logger.error(traceback.format_exc()) + if event.is_stopped(): + logger.info(f"{star_map[handler.handler_module_path].name} - {handler.handler_name} 终止了事件传播。") + return + if isinstance(req.contexts, str): req.contexts = json.loads(req.contexts) @@ -92,6 +96,11 @@ class LLMRequestSubStage(Stage): await handler.handler(event, llm_response) except BaseException: logger.error(traceback.format_exc()) + + if event.is_stopped(): + logger.info(f"{star_map[handler.handler_module_path].name} - {handler.handler_name} 终止了事件传播。") + return + # 保存到历史记录 await self._save_to_history(event, req, llm_response) diff --git a/astrbot/core/pipeline/respond/stage.py b/astrbot/core/pipeline/respond/stage.py index 9980d46c3..cbd8c197d 100644 --- a/astrbot/core/pipeline/respond/stage.py +++ b/astrbot/core/pipeline/respond/stage.py @@ -95,5 +95,9 @@ class RespondStage(Stage): await handler.handler(event) except BaseException: logger.error(traceback.format_exc()) + + if event.is_stopped(): + logger.info(f"{star_map[handler.handler_module_path].name} - {handler.handler_name} 终止了事件传播。") + return event.clear_result() \ No newline at end of file diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index c7f0bf72c..5db4d19b5 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -70,6 +70,10 @@ class ResultDecorateStage(Stage): logger.debug(f"hook(on_decorating_result) -> {star_map[handler.handler_module_path].name} - {handler.handler_name} 将消息结果清空。") except BaseException: logger.error(traceback.format_exc()) + + if event.is_stopped(): + logger.info(f"{star_map[handler.handler_module_path].name} - {handler.handler_name} 终止了事件传播。") + return # 需要再获取一次。插件可能直接对 chain 进行了替换。 result = event.get_result() diff --git a/astrbot/core/pipeline/scheduler.py b/astrbot/core/pipeline/scheduler.py index fcb200787..a59181cf5 100644 --- a/astrbot/core/pipeline/scheduler.py +++ b/astrbot/core/pipeline/scheduler.py @@ -27,6 +27,9 @@ class PipelineScheduler(): logger.debug(f"阶段 {stage.__class__ .__name__} 已终止事件传播。") break await self._process_stages(event, i + 1) + if event.is_stopped(): + logger.debug(f"阶段 {stage.__class__ .__name__} 已终止事件传播。") + break else: await coro