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.
This commit is contained in:
@@ -1,25 +1,40 @@
|
||||
"""类型 → Brain 工厂。新增一种大脑 = 加一个 brain 文件 + 在此注册一行。"""
|
||||
"""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.internal_brain import InternalBrain
|
||||
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(),
|
||||
}
|
||||
|
||||
# 各类型的元数据(供 schema 校验 / realtime 门控复用,无需实例化 Brain)。
|
||||
SPECS: dict[str, BrainSpec] = {
|
||||
"prompt": InternalBrain("prompt").spec,
|
||||
"workflow": InternalBrain("workflow").spec,
|
||||
"fastgpt": FastGPTBrain().spec,
|
||||
"prompt": PromptBrain.spec,
|
||||
"workflow": WorkflowBrain.spec,
|
||||
"dify": DifyBrain.spec,
|
||||
"fastgpt": FastGPTBrain.spec,
|
||||
}
|
||||
|
||||
|
||||
def build_brain(cfg: AssistantConfig) -> Brain:
|
||||
"""按 cfg.type 构造每通电话的 Brain 实例(未知类型回退 prompt)。"""
|
||||
if cfg.type == "fastgpt":
|
||||
return FastGPTBrain()
|
||||
if cfg.type in ("prompt", "workflow"):
|
||||
return InternalBrain(cfg.type)
|
||||
return InternalBrain("prompt")
|
||||
try:
|
||||
factory = BRAIN_FACTORIES[cfg.type]
|
||||
except KeyError as exc:
|
||||
raise ValueError(f"尚未实现的助手类型: {cfg.type}") from exc
|
||||
return factory(cfg)
|
||||
|
||||
Reference in New Issue
Block a user