2025-05-02 17:31:33 +08:00

27 lines
1.5 KiB
Python

# File: backend/app/flow_components/chat_input.py (New)
# Description: Backend component for ChatInputNode
from .base import BaseComponent, InputField, OutputField, register_component
from typing import ClassVar, Dict, Any, Optional, List
from sqlalchemy.ext.asyncio import AsyncSession
@register_component
class ChatInputNodeComponent(BaseComponent):
name: ClassVar[str] = "chatInputNode" # Matches frontend type
display_name: ClassVar[str] = "Chat Input"
description: ClassVar[str] = "从 Playground 获取聊天输入。"
icon: ClassVar[str] = "MessageCircleQuestion"
inputs: ClassVar[List[InputField]] = [
InputField(name="text", display_name="Text", field_type="str", required=False, is_handle=False, info="用户输入的文本或默认文本。"),
]
outputs: ClassVar[List[OutputField]] = [
OutputField(name="message-output", display_name="Message", field_type="message", info="输出的聊天消息。") # Use 'message' type
]
async def run(self, inputs: Dict[str, Any], db: Optional[AsyncSession] = None) -> Dict[str, Any]:
# Inputs are already validated and resolved by the base class/executor
text_input = inputs.get("text", self.node_data.get("text", "")) # Get text from UI data or default
print(f"ChatInputNode ({self.node_data.get('id', 'N/A')}): 输出文本 '{text_input}'")
# Output format should match the defined output field name
return {"message-output": text_input} # Output the text