- Introduce dynamic variable definitions in AssistantConfig and Assistant models, allowing for flexible prompt customization. - Implement validation for dynamic variable names and types in the schema. - Update backend services and routes to handle dynamic variables in assistant configurations and runtime processing. - Enhance frontend components to support dynamic variable definitions, including a new editor for managing variables. - Add tests to ensure proper functionality and validation of dynamic variables in various scenarios.
41 lines
1.1 KiB
Python
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(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)
|