Files
syops/backend/app/services/chat/executors/hybrid.py
T

30 lines
954 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
backend/app/services/chat/executors/hybrid.py
用途:runtime_provider=hybrid 的聊天 Executor(Handler 前置 + Dify 流)。
依赖:resolve_handler、DifyChatExecutor。
逻辑:resolve_handler 校验 → handler.prepare_stream → DifyChatExecutor.stream。
"""
from __future__ import annotations
from typing import Iterator
from app.services.agent_registry.resolver import resolve_handler
from app.services.chat.executors.base import ChatExecutor, ChatStreamContext
from app.services.chat.executors.dify_chat import DifyChatExecutor
class HybridChatExecutor(ChatExecutor):
"""Hybrid:业务 Handler 前置 + Dify Chatflow 流。"""
provider_key = 'hybrid'
def __init__(self) -> None:
self._dify = DifyChatExecutor()
def stream(self, ctx: ChatStreamContext) -> Iterator[str]:
handler = resolve_handler(ctx.agent)
ctx = handler.prepare_stream(ctx)
yield from self._dify.stream(ctx)