mirror of
https://github.com/langgenius/dify.git
synced 2026-10-04 13:47:55 +08:00
refactor: move workflow package to dify_graph (#32844)
This commit is contained in:
1 parent
9c33923985
commit
c917838f9c
613 files changed
+2008
-2012
No files matched your search
@@ -0,0 +1,3 @@
|
||||
from .variable_aggregator_node import VariableAggregatorNode
|
||||
|
||||
__all__ = ["VariableAggregatorNode"]
|
||||
@@ -0,0 +1,33 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from dify_graph.nodes.base import BaseNodeData
|
||||
from dify_graph.variables.types import SegmentType
|
||||
|
||||
|
||||
class AdvancedSettings(BaseModel):
|
||||
"""
|
||||
Advanced setting.
|
||||
"""
|
||||
|
||||
group_enabled: bool
|
||||
|
||||
class Group(BaseModel):
|
||||
"""
|
||||
Group.
|
||||
"""
|
||||
|
||||
output_type: SegmentType
|
||||
variables: list[list[str]]
|
||||
group_name: str
|
||||
|
||||
groups: list[Group]
|
||||
|
||||
|
||||
class VariableAggregatorNodeData(BaseNodeData):
|
||||
"""
|
||||
Variable Aggregator Node Data.
|
||||
"""
|
||||
|
||||
output_type: str
|
||||
variables: list[list[str]]
|
||||
advanced_settings: AdvancedSettings | None = None
|
||||
@@ -0,0 +1,40 @@
|
||||
from collections.abc import Mapping
|
||||
|
||||
from dify_graph.enums import NodeType, WorkflowNodeExecutionStatus
|
||||
from dify_graph.node_events import NodeRunResult
|
||||
from dify_graph.nodes.base.node import Node
|
||||
from dify_graph.nodes.variable_aggregator.entities import VariableAggregatorNodeData
|
||||
from dify_graph.variables.segments import Segment
|
||||
|
||||
|
||||
class VariableAggregatorNode(Node[VariableAggregatorNodeData]):
|
||||
node_type = NodeType.VARIABLE_AGGREGATOR
|
||||
|
||||
@classmethod
|
||||
def version(cls) -> str:
|
||||
return "1"
|
||||
|
||||
def _run(self) -> NodeRunResult:
|
||||
# Get variables
|
||||
outputs: dict[str, Segment | Mapping[str, Segment]] = {}
|
||||
inputs = {}
|
||||
|
||||
if not self.node_data.advanced_settings or not self.node_data.advanced_settings.group_enabled:
|
||||
for selector in self.node_data.variables:
|
||||
variable = self.graph_runtime_state.variable_pool.get(selector)
|
||||
if variable is not None:
|
||||
outputs = {"output": variable}
|
||||
|
||||
inputs = {".".join(selector[1:]): variable.to_object()}
|
||||
break
|
||||
else:
|
||||
for group in self.node_data.advanced_settings.groups:
|
||||
for selector in group.variables:
|
||||
variable = self.graph_runtime_state.variable_pool.get(selector)
|
||||
|
||||
if variable is not None:
|
||||
outputs[group.group_name] = {"output": variable}
|
||||
inputs[".".join(selector[1:])] = variable.to_object()
|
||||
break
|
||||
|
||||
return NodeRunResult(status=WorkflowNodeExecutionStatus.SUCCEEDED, outputs=outputs, inputs=inputs)
|
||||
Reference in new issue
Block a user