Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions api/core/workflow/nodes/iteration/iteration_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@
)
)

# Update the total tokens from this iteration
self.graph_runtime_state.total_tokens += graph_engine.graph_runtime_state.total_tokens
# Accumulate usage from this iteration
usage_accumulator[0] = self._merge_usage(
usage_accumulator[0], graph_engine.graph_runtime_state.llm_usage
)
Expand Down Expand Up @@ -288,11 +287,10 @@
index = future_to_index[future]
try:
result = future.result()
(

Check failure on line 290 in api/core/workflow/nodes/iteration/iteration_node.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Expression with type "tuple[datetime, list[GraphNodeEventBase], object | None, int, dict[str, VariableUnion], LLMUsage]" cannot be assigned to target tuple   Type "tuple[datetime, list[GraphNodeEventBase], object | None, int, dict[str, VariableUnion], LLMUsage]" is incompatible with target tuple     Tuple size mismatch; expected 5 but received 6 (reportAssignmentType)
iter_start_at,
events,
output_value,
tokens_used,
conversation_snapshot,
iteration_usage,
) = result
Expand All @@ -304,13 +302,12 @@
yield from events

# Update tokens and timing
self.graph_runtime_state.total_tokens += tokens_used
iter_run_map[str(index)] = (datetime.now(UTC).replace(tzinfo=None) - iter_start_at).total_seconds()

usage_accumulator[0] = self._merge_usage(usage_accumulator[0], iteration_usage)

Check failure on line 307 in api/core/workflow/nodes/iteration/iteration_node.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Argument of type "dict[str, VariableUnion]" cannot be assigned to parameter "new_usage" of type "LLMUsage | None" in function "_merge_usage"   Type "dict[str, VariableUnion]" is not assignable to type "LLMUsage | None"     "dict[str, VariableUnion]" is not assignable to "LLMUsage"     "dict[str, VariableUnion]" is not assignable to "None" (reportArgumentType)

# Sync conversation variables after iteration completion
self._sync_conversation_variables_from_snapshot(conversation_snapshot)

Check failure on line 310 in api/core/workflow/nodes/iteration/iteration_node.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Argument of type "int" cannot be assigned to parameter "snapshot" of type "dict[str, VariableUnion]" in function "_sync_conversation_variables_from_snapshot"   "int" is not assignable to "dict[str, VariableUnion]" (reportArgumentType)

except Exception as e:
# Handle errors based on error_handle_mode
Expand Down Expand Up @@ -359,11 +356,10 @@
variable_pool=graph_engine.graph_runtime_state.variable_pool
)

return (

Check failure on line 359 in api/core/workflow/nodes/iteration/iteration_node.py

View workflow job for this annotation

GitHub Actions / Style Check / Python Style

Type "tuple[datetime, list[GraphNodeEventBase], object | None, dict[str, VariableUnion], LLMUsage]" is not assignable to return type "tuple[datetime, list[GraphNodeEventBase], object | None, int, dict[str, VariableUnion], LLMUsage]"   "dict[str, VariableUnion]" is not assignable to "int"   "LLMUsage" is not assignable to "dict[str, VariableUnion]" (reportReturnType)
iter_start_at,
events,
output_value,
graph_engine.graph_runtime_state.total_tokens,
conversation_snapshot,
graph_engine.graph_runtime_state.llm_usage,
)
Expand Down
5 changes: 0 additions & 5 deletions api/core/workflow/nodes/loop/loop_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def _run(self) -> Generator:

if reach_break_condition:
loop_count = 0
cost_tokens = 0

for i in range(loop_count):
graph_engine = self._create_graph_engine(start_at=start_at, root_node_id=root_node_id)
Expand All @@ -163,9 +162,6 @@ def _run(self) -> Generator:
# For other outputs, just update
self.graph_runtime_state.set_output(key, value)

# Update the total tokens from this iteration
cost_tokens += graph_engine.graph_runtime_state.total_tokens

# Accumulate usage from the sub-graph execution
loop_usage = self._merge_usage(loop_usage, graph_engine.graph_runtime_state.llm_usage)

Expand Down Expand Up @@ -194,7 +190,6 @@ def _run(self) -> Generator:
pre_loop_output=self._node_data.outputs,
)

self.graph_runtime_state.total_tokens += cost_tokens
self._accumulate_usage(loop_usage)
# Loop completed successfully
yield LoopSucceededEvent(
Expand Down
Loading