Files
ai-video-fullstack/backend/services/brains/registry.py
Xin Wang 00270a5c01 Add Dify integration and enhance workflow node specifications
- Introduce new fields `dify_api_url` and `dify_api_key` in `AssistantConfig` for Dify API integration.
- Update `requirements.txt` to include `dify-client-python` for Dify SDK support.
- Modify `config_resolver` to handle Dify connection information.
- Add a new `globalNode` type in workflow specifications to provide unified settings across workflows.
- Enhance node specifications with additional constraints and default values for better configuration management.
- Update frontend components to support the new `globalNode` type and its properties, improving workflow editor functionality.
2026-07-11 22:26:31 +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.graph)
BRAIN_FACTORIES: dict[str, Callable[[AssistantConfig], Brain]] = {
"prompt": lambda _cfg: PromptBrain(),
"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)