mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 12:39:14 +08:00
chore(iteration): keep start_node_id using in parallel start nodes
This commit is contained in:
parent
4e3dc36e37
commit
4256e9d47f
@ -52,35 +52,6 @@ class IterationNode(BaseNode):
|
|||||||
|
|
||||||
graph_config = self.graph_config
|
graph_config = self.graph_config
|
||||||
|
|
||||||
# find nodes in current iteration and donot have source and have have start_node_in_iteration flag
|
|
||||||
# these nodes are the start nodes of the iteration (in version of parallel support)
|
|
||||||
start_node_ids = []
|
|
||||||
for node_config in graph_config['nodes']:
|
|
||||||
if (
|
|
||||||
node_config.get('data', {}).get('iteration_id')
|
|
||||||
and node_config.get('data', {}).get('iteration_id') == self.node_id
|
|
||||||
and not node_config.get('source')
|
|
||||||
and node_config.get('data', {}).get('start_node_in_iteration', False)
|
|
||||||
):
|
|
||||||
start_node_ids.append(node_config.get('id'))
|
|
||||||
|
|
||||||
if len(start_node_ids) > 0:
|
|
||||||
# add new fake iteration start node that connect to all start nodes
|
|
||||||
root_node_id = f"{self.node_id}-start"
|
|
||||||
graph_config['nodes'].append({
|
|
||||||
"id": root_node_id,
|
|
||||||
"data": {
|
|
||||||
"title": "iteration start",
|
|
||||||
"type": NodeType.ITERATION_START.value,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
for start_node_id in start_node_ids:
|
|
||||||
graph_config['edges'].append({
|
|
||||||
"source": root_node_id,
|
|
||||||
"target": start_node_id
|
|
||||||
})
|
|
||||||
else:
|
|
||||||
if not self.node_data.start_node_id:
|
if not self.node_data.start_node_id:
|
||||||
raise ValueError(f'field start_node_id in iteration {self.node_id} not found')
|
raise ValueError(f'field start_node_id in iteration {self.node_id} not found')
|
||||||
|
|
||||||
|
@ -214,6 +214,16 @@ def test_run_parallel():
|
|||||||
"source": "iteration-1",
|
"source": "iteration-1",
|
||||||
"target": "answer-3",
|
"target": "answer-3",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "iteration-start-source-tt-target",
|
||||||
|
"source": "iteration-start",
|
||||||
|
"target": "tt",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "iteration-start-source-tt-2-target",
|
||||||
|
"source": "iteration-start",
|
||||||
|
"target": "tt-2",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "tt-source-if-else-target",
|
"id": "tt-source-if-else-target",
|
||||||
"source": "tt",
|
"source": "tt",
|
||||||
@ -250,7 +260,7 @@ def test_run_parallel():
|
|||||||
"output_selector": ["tt", "output"],
|
"output_selector": ["tt", "output"],
|
||||||
"output_type": "array[string]",
|
"output_type": "array[string]",
|
||||||
"startNodeType": "template-transform",
|
"startNodeType": "template-transform",
|
||||||
"start_node_id": "tt",
|
"start_node_id": "iteration-start",
|
||||||
"title": "iteration",
|
"title": "iteration",
|
||||||
"type": "iteration",
|
"type": "iteration",
|
||||||
},
|
},
|
||||||
@ -268,7 +278,14 @@ def test_run_parallel():
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"iteration_id": "iteration-1",
|
"iteration_id": "iteration-1",
|
||||||
"start_node_in_iteration": True,
|
"title": "iteration-start",
|
||||||
|
"type": "iteration-start",
|
||||||
|
},
|
||||||
|
"id": "iteration-start",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"iteration_id": "iteration-1",
|
||||||
"template": "{{ arg1 }} 123",
|
"template": "{{ arg1 }} 123",
|
||||||
"title": "template transform",
|
"title": "template transform",
|
||||||
"type": "template-transform",
|
"type": "template-transform",
|
||||||
@ -279,7 +296,6 @@ def test_run_parallel():
|
|||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"iteration_id": "iteration-1",
|
"iteration_id": "iteration-1",
|
||||||
"start_node_in_iteration": True,
|
|
||||||
"template": "{{ arg1 }} 321",
|
"template": "{{ arg1 }} 321",
|
||||||
"title": "template transform",
|
"title": "template transform",
|
||||||
"type": "template-transform",
|
"type": "template-transform",
|
||||||
@ -372,6 +388,7 @@ def test_run_parallel():
|
|||||||
"output_selector": ["tt", "output"],
|
"output_selector": ["tt", "output"],
|
||||||
"output_type": "array[string]",
|
"output_type": "array[string]",
|
||||||
"startNodeType": "template-transform",
|
"startNodeType": "template-transform",
|
||||||
|
"start_node_id": "iteration-start",
|
||||||
"title": "迭代",
|
"title": "迭代",
|
||||||
"type": "iteration",
|
"type": "iteration",
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user