From 5646442931f0295ba5ead4894f64c3f8f5746632 Mon Sep 17 00:00:00 2001 From: jiangbo721 <365065261@qq.com> Date: Fri, 14 Mar 2025 17:44:24 +0800 Subject: [PATCH] fix: iteration total tokens calculate error (#15813) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 刘江波 --- api/core/workflow/graph_engine/graph_engine.py | 3 ++- api/core/workflow/nodes/iteration/iteration_node.py | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/api/core/workflow/graph_engine/graph_engine.py b/api/core/workflow/graph_engine/graph_engine.py index 9bb54da3a..498d15c91 100644 --- a/api/core/workflow/graph_engine/graph_engine.py +++ b/api/core/workflow/graph_engine/graph_engine.py @@ -873,11 +873,12 @@ class GraphEngine: def create_copy(self): """ create a graph engine copy - :return: with a new variable pool instance of graph engine + :return: graph engine with a new variable pool and initialized total tokens """ new_instance = copy(self) new_instance.graph_runtime_state = copy(self.graph_runtime_state) new_instance.graph_runtime_state.variable_pool = deepcopy(self.graph_runtime_state.variable_pool) + new_instance.graph_runtime_state.total_tokens = 0 return new_instance def _handle_continue_on_error( diff --git a/api/core/workflow/nodes/iteration/iteration_node.py b/api/core/workflow/nodes/iteration/iteration_node.py index 16fccf8bf..a7d0aefc6 100644 --- a/api/core/workflow/nodes/iteration/iteration_node.py +++ b/api/core/workflow/nodes/iteration/iteration_node.py @@ -590,7 +590,6 @@ class IterationNode(BaseNode[IterationNodeData]): with flask_app.app_context(): parallel_mode_run_id = uuid.uuid4().hex graph_engine_copy = graph_engine.create_copy() - graph_engine_copy.graph_runtime_state.total_tokens = 0 variable_pool_copy = graph_engine_copy.graph_runtime_state.variable_pool variable_pool_copy.add([self.node_id, "index"], index) variable_pool_copy.add([self.node_id, "item"], item)