Files
ai-video-fullstack/backend/services/brains/registry.py
Xin Wang 32aef14ddb Add workflow support and enhance runtime configuration in models and services
- Introduce RuntimeModelResource and RuntimeKnowledgeBase classes to manage workflow resources.
- Update AssistantConfig to include workflow_model_resources and workflow_knowledge_bases for better integration.
- Refactor validation and processing logic in routes and services to accommodate workflow types.
- Implement dynamic variable support for workflow assistants and enhance graph normalization.
- Add ToolExecutor for reusable tool execution across different assistant types.
- Update various services to ensure compatibility with new workflow features and improve error handling.
2026-07-13 16:13:27 +08:00

41 lines
1.1 KiB
Python

"""Explicit assistant-type registry. Unsupported types never silently degrade."""
from __future__ import annotations
from collections.abc import Callable
from models import AssistantConfig
from services.brains.base import Brain, BrainSpec
from services.brains.dify_brain import DifyBrain
from services.brains.fastgpt_brain import FastGPTBrain
from services.brains.prompt_brain import PromptBrain
from services.brains.workflow_brain import WorkflowBrain
def _workflow(cfg: AssistantConfig) -> Brain:
return WorkflowBrain(cfg)
BRAIN_FACTORIES: dict[str, Callable[[AssistantConfig], Brain]] = {
"prompt": lambda cfg: PromptBrain(cfg),
"workflow": _workflow,
"dify": lambda _cfg: DifyBrain(),
"fastgpt": lambda _cfg: FastGPTBrain(),
}
SPECS: dict[str, BrainSpec] = {
"prompt": PromptBrain.spec,
"workflow": WorkflowBrain.spec,
"dify": DifyBrain.spec,
"fastgpt": FastGPTBrain.spec,
}
def build_brain(cfg: AssistantConfig) -> Brain:
try:
factory = BRAIN_FACTORIES[cfg.type]
except KeyError as exc:
raise ValueError(f"尚未实现的助手类型: {cfg.type}") from exc
return factory(cfg)