mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
add few workflow run codes
This commit is contained in:
@ -1,32 +1,21 @@
|
||||
from abc import abstractmethod
|
||||
from typing import Optional
|
||||
from typing import Optional, Type
|
||||
|
||||
from core.workflow.entities.base_node_data_entities import BaseNodeData
|
||||
from core.workflow.entities.node_entities import NodeType
|
||||
from core.workflow.entities.variable_pool import VariablePool
|
||||
|
||||
|
||||
class BaseNode:
|
||||
_node_type: NodeType
|
||||
_node_data_cls: Type[BaseNodeData]
|
||||
|
||||
def __int__(self, node_config: dict) -> None:
|
||||
self._node_config = node_config
|
||||
def __init__(self, config: dict) -> None:
|
||||
self._node_id = config.get("id")
|
||||
if not self._node_id:
|
||||
raise ValueError("Node ID is required.")
|
||||
|
||||
@abstractmethod
|
||||
def run(self, variable_pool: Optional[VariablePool] = None,
|
||||
run_args: Optional[dict] = None) -> dict:
|
||||
"""
|
||||
Run node
|
||||
:param variable_pool: variable pool
|
||||
:param run_args: run args
|
||||
:return:
|
||||
"""
|
||||
if variable_pool is None and run_args is None:
|
||||
raise ValueError("At least one of `variable_pool` or `run_args` must be provided.")
|
||||
|
||||
return self._run(
|
||||
variable_pool=variable_pool,
|
||||
run_args=run_args
|
||||
)
|
||||
self._node_data = self._node_data_cls(**config.get("data", {}))
|
||||
|
||||
@abstractmethod
|
||||
def _run(self, variable_pool: Optional[VariablePool] = None,
|
||||
@ -39,6 +28,22 @@ class BaseNode:
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
||||
def run(self, variable_pool: Optional[VariablePool] = None,
|
||||
run_args: Optional[dict] = None) -> dict:
|
||||
"""
|
||||
Run node entry
|
||||
:param variable_pool: variable pool
|
||||
:param run_args: run args
|
||||
:return:
|
||||
"""
|
||||
if variable_pool is None and run_args is None:
|
||||
raise ValueError("At least one of `variable_pool` or `run_args` must be provided.")
|
||||
|
||||
return self._run(
|
||||
variable_pool=variable_pool,
|
||||
run_args=run_args
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_default_config(cls, filters: Optional[dict] = None) -> dict:
|
||||
"""
|
||||
|
||||
27
api/core/workflow/nodes/start/entities.py
Normal file
27
api/core/workflow/nodes/start/entities.py
Normal file
@ -0,0 +1,27 @@
|
||||
from typing import Optional
|
||||
|
||||
from core.app.app_config.entities import VariableEntity
|
||||
from core.workflow.entities.base_node_data_entities import BaseNodeData
|
||||
from core.workflow.entities.node_entities import NodeType
|
||||
|
||||
|
||||
class StartNodeData(BaseNodeData):
|
||||
"""
|
||||
- title (string) 节点标题
|
||||
- desc (string) optional 节点描述
|
||||
- type (string) 节点类型,固定为 start
|
||||
- variables (array[object]) 表单变量列表
|
||||
- type (string) 表单变量类型,text-input, paragraph, select, number, files(文件暂不支持自定义)
|
||||
- label (string) 控件展示标签名
|
||||
- variable (string) 变量 key
|
||||
- max_length (int) 最大长度,适用于 text-input 和 paragraph
|
||||
- default (string) optional 默认值
|
||||
- required (bool) optional是否必填,默认 false
|
||||
- hint (string) optional 提示信息
|
||||
- options (array[string]) 选项值(仅 select 可用)
|
||||
"""
|
||||
type: str = NodeType.START.value
|
||||
|
||||
title: str
|
||||
desc: Optional[str] = None
|
||||
variables: list[VariableEntity] = []
|
||||
@ -1,5 +1,22 @@
|
||||
from typing import Type, Optional
|
||||
|
||||
from core.workflow.entities.node_entities import NodeType
|
||||
from core.workflow.entities.variable_pool import VariablePool
|
||||
from core.workflow.nodes.base_node import BaseNode
|
||||
from core.workflow.nodes.start.entities import StartNodeData
|
||||
|
||||
|
||||
class StartNode(BaseNode):
|
||||
pass
|
||||
_node_type = NodeType.START
|
||||
_node_data_cls = StartNodeData
|
||||
|
||||
def _run(self, variable_pool: Optional[VariablePool] = None,
|
||||
run_args: Optional[dict] = None) -> dict:
|
||||
"""
|
||||
Run node
|
||||
:param variable_pool: variable pool
|
||||
:param run_args: run args
|
||||
:return:
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
Reference in New Issue
Block a user