From 8a731f6dbe0ce6704d9115e7f5806f48fafbea6e Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Tue, 22 Jul 2025 18:54:01 +0800 Subject: [PATCH 1/7] Remove unused functions in class Graph --- .../workflow/graph_engine/entities/graph.py | 41 ------------------- .../core/workflow/graph_engine/test_graph.py | 9 ---- 2 files changed, 50 deletions(-) diff --git a/api/core/workflow/graph_engine/entities/graph.py b/api/core/workflow/graph_engine/entities/graph.py index 362777a199..e436ce940e 100644 --- a/api/core/workflow/graph_engine/entities/graph.py +++ b/api/core/workflow/graph_engine/entities/graph.py @@ -204,47 +204,6 @@ class Graph(BaseModel): return graph - def add_extra_edge( - self, source_node_id: str, target_node_id: str, run_condition: Optional[RunCondition] = None - ) -> None: - """ - Add extra edge to the graph - - :param source_node_id: source node id - :param target_node_id: target node id - :param run_condition: run condition - """ - if source_node_id not in self.node_ids or target_node_id not in self.node_ids: - return - - if source_node_id not in self.edge_mapping: - self.edge_mapping[source_node_id] = [] - - if target_node_id in [graph_edge.target_node_id for graph_edge in self.edge_mapping[source_node_id]]: - return - - graph_edge = GraphEdge( - source_node_id=source_node_id, target_node_id=target_node_id, run_condition=run_condition - ) - - self.edge_mapping[source_node_id].append(graph_edge) - - def get_leaf_node_ids(self) -> list[str]: - """ - Get leaf node ids of the graph - - :return: leaf node ids - """ - leaf_node_ids = [] - for node_id in self.node_ids: - if node_id not in self.edge_mapping or ( - len(self.edge_mapping[node_id]) == 1 - and self.edge_mapping[node_id][0].target_node_id == self.root_node_id - ): - leaf_node_ids.append(node_id) - - return leaf_node_ids - @classmethod def _recursively_add_node_ids( cls, node_ids: list[str], edge_mapping: dict[str, list[GraphEdge]], node_id: str diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py index 13ba11016a..e8e4fc7046 100644 --- a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py +++ b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py @@ -162,14 +162,6 @@ def test__init_iteration_graph(): } graph = Graph.init(graph_config=graph_config, root_node_id="template-transform-in-iteration") - graph.add_extra_edge( - source_node_id="answer-in-iteration", - target_node_id="template-transform-in-iteration", - run_condition=RunCondition( - type="condition", - conditions=[Condition(variable_selector=["iteration", "index"], comparison_operator="≤", value="5")], - ), - ) # iteration: # [template-transform-in-iteration -> llm-in-iteration -> answer-in-iteration] @@ -177,7 +169,6 @@ def test__init_iteration_graph(): assert graph.root_node_id == "template-transform-in-iteration" assert graph.edge_mapping.get("template-transform-in-iteration")[0].target_node_id == "llm-in-iteration" assert graph.edge_mapping.get("llm-in-iteration")[0].target_node_id == "answer-in-iteration" - assert graph.edge_mapping.get("answer-in-iteration")[0].target_node_id == "template-transform-in-iteration" def test_parallels_graph(): From 0d3fc89ed37e163f29a90ad160fdb053f17efc90 Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Tue, 22 Jul 2025 18:55:05 +0800 Subject: [PATCH 2/7] Ruff linter --- api/tests/unit_tests/core/workflow/graph_engine/test_graph.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py index e8e4fc7046..7660cd6ea0 100644 --- a/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py +++ b/api/tests/unit_tests/core/workflow/graph_engine/test_graph.py @@ -1,6 +1,4 @@ from core.workflow.graph_engine.entities.graph import Graph -from core.workflow.graph_engine.entities.run_condition import RunCondition -from core.workflow.utils.condition.entities import Condition def test_init(): From 7ec5cb03c0a9190fbfc28745362f06c24c1fa274 Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Tue, 22 Jul 2025 18:57:46 +0800 Subject: [PATCH 3/7] Fix typos --- api/core/model_runtime/README.md | 2 +- api/core/model_runtime/README_CN.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/core/model_runtime/README.md b/api/core/model_runtime/README.md index b5de7ad412..582ba12b29 100644 --- a/api/core/model_runtime/README.md +++ b/api/core/model_runtime/README.md @@ -7,7 +7,7 @@ This module provides the interface for invoking and authenticating various model ## Features -- Supports capability invocation for 5 types of models +- Supports capability invocation for 6 types of models - `LLM` - LLM text completion, dialogue, pre-computed tokens capability - `Text Embedding Model` - Text Embedding, pre-computed tokens capability diff --git a/api/core/model_runtime/README_CN.md b/api/core/model_runtime/README_CN.md index 2fc2a60461..db64d64196 100644 --- a/api/core/model_runtime/README_CN.md +++ b/api/core/model_runtime/README_CN.md @@ -7,7 +7,7 @@ ## 功能介绍 -- 支持 5 种模型类型的能力调用 +- 支持 6 种模型类型的能力调用 - `LLM` - LLM 文本补全、对话,预计算 tokens 能力 - `Text Embedding Model` - 文本 Embedding,预计算 tokens 能力 From e9c43793b24de5eec2151428a0056aca6b3ba661 Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Wed, 23 Jul 2025 16:27:32 +0800 Subject: [PATCH 4/7] remove redundant assignment `parallel = None` This line duplicates the assignment at line 270 and is therefore unnecessary. --- api/core/workflow/graph_engine/entities/graph.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api/core/workflow/graph_engine/entities/graph.py b/api/core/workflow/graph_engine/entities/graph.py index e436ce940e..28cff140da 100644 --- a/api/core/workflow/graph_engine/entities/graph.py +++ b/api/core/workflow/graph_engine/entities/graph.py @@ -287,7 +287,6 @@ class Graph(BaseModel): condition_parallels = {} for condition_hash, condition_parallel_branch_node_ids in parallel_branch_node_ids.items(): # any target node id in node_parallel_mapping - parallel = None if condition_parallel_branch_node_ids: parent_parallel_id = parent_parallel.id if parent_parallel else None From 151b94ef5d367de6bdd93e649555a9f7f5f3e443 Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Wed, 23 Jul 2025 16:36:21 +0800 Subject: [PATCH 5/7] Refactor: remove unused variable and optimize redundant computation - Removed unused variable `all_routes_node_ids` to reduce code clutter. - Moved `set(routes_node_ids.keys())` outside the loop to avoid repeated computation. --- api/core/workflow/graph_engine/entities/graph.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/api/core/workflow/graph_engine/entities/graph.py b/api/core/workflow/graph_engine/entities/graph.py index 28cff140da..c8304d158f 100644 --- a/api/core/workflow/graph_engine/entities/graph.py +++ b/api/core/workflow/graph_engine/entities/graph.py @@ -639,11 +639,8 @@ class Graph(BaseModel): if start_node_id not in reverse_edge_mapping: return False - all_routes_node_ids = set() parallel_start_node_ids: dict[str, list[str]] = {} - for branch_node_id, node_ids in routes_node_ids.items(): - all_routes_node_ids.update(node_ids) - + for branch_node_id in routes_node_ids.items(): if branch_node_id in reverse_edge_mapping: for graph_edge in reverse_edge_mapping[branch_node_id]: if graph_edge.source_node_id not in parallel_start_node_ids: @@ -651,8 +648,9 @@ class Graph(BaseModel): parallel_start_node_ids[graph_edge.source_node_id].append(branch_node_id) + expected_branch_set = set(routes_node_ids.keys()) for _, branch_node_ids in parallel_start_node_ids.items(): - if set(branch_node_ids) == set(routes_node_ids.keys()): + if set(branch_node_ids) == expected_branch_set: return True return False From eaacd435448d7ee09ae37cee13454daaa8f46cdd Mon Sep 17 00:00:00 2001 From: Yongtao Huang Date: Wed, 23 Jul 2025 16:53:30 +0800 Subject: [PATCH 6/7] Post fix --- api/core/workflow/graph_engine/entities/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/core/workflow/graph_engine/entities/graph.py b/api/core/workflow/graph_engine/entities/graph.py index c8304d158f..d0dffc7f21 100644 --- a/api/core/workflow/graph_engine/entities/graph.py +++ b/api/core/workflow/graph_engine/entities/graph.py @@ -640,7 +640,7 @@ class Graph(BaseModel): return False parallel_start_node_ids: dict[str, list[str]] = {} - for branch_node_id in routes_node_ids.items(): + for branch_node_id in routes_node_ids: if branch_node_id in reverse_edge_mapping: for graph_edge in reverse_edge_mapping[branch_node_id]: if graph_edge.source_node_id not in parallel_start_node_ids: From 3ae9bca22204cc52d5a7694371776c1f94a2bfe3 Mon Sep 17 00:00:00 2001 From: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com> Date: Thu, 24 Jul 2025 12:18:29 +0800 Subject: [PATCH 7/7] Remove empty file --- api/core/workflow/workflow_engine_manager.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 api/core/workflow/workflow_engine_manager.py diff --git a/api/core/workflow/workflow_engine_manager.py b/api/core/workflow/workflow_engine_manager.py deleted file mode 100644 index e69de29bb2..0000000000