Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions astrbot/core/pipeline/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import AsyncGenerator
from typing import cast

from astrbot.core import logger
from astrbot.core.platform import AstrMessageEvent
Expand All @@ -10,7 +11,7 @@

from .bootstrap import ensure_builtin_stages_registered
from .context import PipelineContext
from .stage import registered_stages
from .stage import Stage, registered_stages
from .stage_order import STAGES_ORDER


Expand All @@ -23,7 +24,7 @@ def __init__(self, context: PipelineContext) -> None:
key=lambda x: STAGES_ORDER.index(x.__name__),
) # 按照顺序排序
self.ctx = context # 上下文对象
self.stages = [] # 存储阶段实例
self.stages: list[Stage] = [] # 存储阶段实例

async def initialize(self) -> None:
"""初始化管道调度器时, 初始化所有阶段"""
Expand All @@ -49,7 +50,8 @@ async def _process_stages(self, event: AstrMessageEvent, from_stage=0) -> None:

if isinstance(coroutine, AsyncGenerator):
# 如果返回的是异步生成器, 实现洋葱模型的核心
async for _ in coroutine:
agen = cast(AsyncGenerator[None], coroutine)
async for _ in agen:
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Comment thread
PersonalViolet marked this conversation as resolved.
# 此处是前置处理完成后的暂停点(yield), 下面开始执行后续阶段
if event.is_stopped():
logger.debug(
Expand Down
2 changes: 1 addition & 1 deletion astrbot/core/pipeline/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def process(
Args:
event (AstrMessageEvent): 事件对象,包含事件的相关信息
Returns:
Union[None, AsyncGenerator[None, None]]: 处理结果,可能是 None 或者异步生成器, 如果为 None 则表示不需要继续处理, 如果为异步生成器则表示需要继续处理(进入下一个阶段)
None | AsyncGenerator[None]: 处理结果,可能是 None 或者异步生成器, 如果为 None 则表示不需要继续处理, 如果为异步生成器则表示需要继续处理(进入下一个阶段)

"""
raise NotImplementedError
Loading