mirror of https://github.com/langgenius/dify.git
refactor: single-node workflow runner helpers (#31472)
This commit is contained in:
parent
5c4028d557
commit
67eb8c052d
|
|
@ -166,18 +166,22 @@ class WorkflowBasedAppRunner:
|
||||||
|
|
||||||
# Determine which type of single node execution and get graph/variable_pool
|
# Determine which type of single node execution and get graph/variable_pool
|
||||||
if single_iteration_run:
|
if single_iteration_run:
|
||||||
graph, variable_pool = self._get_graph_and_variable_pool_of_single_iteration(
|
graph, variable_pool = self._get_graph_and_variable_pool_for_single_node_run(
|
||||||
workflow=workflow,
|
workflow=workflow,
|
||||||
node_id=single_iteration_run.node_id,
|
node_id=single_iteration_run.node_id,
|
||||||
user_inputs=dict(single_iteration_run.inputs),
|
user_inputs=dict(single_iteration_run.inputs),
|
||||||
graph_runtime_state=graph_runtime_state,
|
graph_runtime_state=graph_runtime_state,
|
||||||
|
node_type_filter_key="iteration_id",
|
||||||
|
node_type_label="iteration",
|
||||||
)
|
)
|
||||||
elif single_loop_run:
|
elif single_loop_run:
|
||||||
graph, variable_pool = self._get_graph_and_variable_pool_of_single_loop(
|
graph, variable_pool = self._get_graph_and_variable_pool_for_single_node_run(
|
||||||
workflow=workflow,
|
workflow=workflow,
|
||||||
node_id=single_loop_run.node_id,
|
node_id=single_loop_run.node_id,
|
||||||
user_inputs=dict(single_loop_run.inputs),
|
user_inputs=dict(single_loop_run.inputs),
|
||||||
graph_runtime_state=graph_runtime_state,
|
graph_runtime_state=graph_runtime_state,
|
||||||
|
node_type_filter_key="loop_id",
|
||||||
|
node_type_label="loop",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Neither single_iteration_run nor single_loop_run is specified")
|
raise ValueError("Neither single_iteration_run nor single_loop_run is specified")
|
||||||
|
|
@ -314,44 +318,6 @@ class WorkflowBasedAppRunner:
|
||||||
|
|
||||||
return graph, variable_pool
|
return graph, variable_pool
|
||||||
|
|
||||||
def _get_graph_and_variable_pool_of_single_iteration(
|
|
||||||
self,
|
|
||||||
workflow: Workflow,
|
|
||||||
node_id: str,
|
|
||||||
user_inputs: dict[str, Any],
|
|
||||||
graph_runtime_state: GraphRuntimeState,
|
|
||||||
) -> tuple[Graph, VariablePool]:
|
|
||||||
"""
|
|
||||||
Get variable pool of single iteration
|
|
||||||
"""
|
|
||||||
return self._get_graph_and_variable_pool_for_single_node_run(
|
|
||||||
workflow=workflow,
|
|
||||||
node_id=node_id,
|
|
||||||
user_inputs=user_inputs,
|
|
||||||
graph_runtime_state=graph_runtime_state,
|
|
||||||
node_type_filter_key="iteration_id",
|
|
||||||
node_type_label="iteration",
|
|
||||||
)
|
|
||||||
|
|
||||||
def _get_graph_and_variable_pool_of_single_loop(
|
|
||||||
self,
|
|
||||||
workflow: Workflow,
|
|
||||||
node_id: str,
|
|
||||||
user_inputs: dict[str, Any],
|
|
||||||
graph_runtime_state: GraphRuntimeState,
|
|
||||||
) -> tuple[Graph, VariablePool]:
|
|
||||||
"""
|
|
||||||
Get variable pool of single loop
|
|
||||||
"""
|
|
||||||
return self._get_graph_and_variable_pool_for_single_node_run(
|
|
||||||
workflow=workflow,
|
|
||||||
node_id=node_id,
|
|
||||||
user_inputs=user_inputs,
|
|
||||||
graph_runtime_state=graph_runtime_state,
|
|
||||||
node_type_filter_key="loop_id",
|
|
||||||
node_type_label="loop",
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_event(self, workflow_entry: WorkflowEntry, event: GraphEngineEvent):
|
def _handle_event(self, workflow_entry: WorkflowEntry, event: GraphEngineEvent):
|
||||||
"""
|
"""
|
||||||
Handle event
|
Handle event
|
||||||
|
|
|
||||||
|
|
@ -226,8 +226,7 @@ class Workflow(Base): # bug
|
||||||
#
|
#
|
||||||
# Currently, the following functions / methods would mutate the returned dict:
|
# Currently, the following functions / methods would mutate the returned dict:
|
||||||
#
|
#
|
||||||
# - `_get_graph_and_variable_pool_of_single_iteration`.
|
# - `_get_graph_and_variable_pool_for_single_node_run`.
|
||||||
# - `_get_graph_and_variable_pool_of_single_loop`.
|
|
||||||
return json.loads(self.graph) if self.graph else {}
|
return json.loads(self.graph) if self.graph else {}
|
||||||
|
|
||||||
def get_node_config_by_id(self, node_id: str) -> Mapping[str, Any]:
|
def get_node_config_by_id(self, node_id: str) -> Mapping[str, Any]:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue