Skip to content

Commit 4858cc1

Browse files
committed
Revert "fix: total tokens is wrong which is zero in inter way, close langgenius#11221 (langgenius#11224)"
This reverts commit fd4be36.
1 parent 28231d3 commit 4858cc1

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

api/core/app/apps/advanced_chat/generate_task_pipeline.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ def __init__(
127127

128128
self._conversation_name_generate_thread = None
129129
self._recorded_files: list[Mapping[str, Any]] = []
130-
self.total_tokens: int = 0
131130

132131
def process(self):
133132
"""
@@ -361,8 +360,6 @@ def _process_stream_response(
361360
if not workflow_run:
362361
raise Exception("Workflow run not initialized.")
363362

364-
# FIXME for issue #11221 quick fix maybe have a better solution
365-
self.total_tokens += event.metadata.get("total_tokens", 0) if event.metadata else 0
366363
yield self._workflow_iteration_completed_to_stream_response(
367364
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
368365
)
@@ -376,7 +373,7 @@ def _process_stream_response(
376373
workflow_run = self._handle_workflow_run_success(
377374
workflow_run=workflow_run,
378375
start_at=graph_runtime_state.start_at,
379-
total_tokens=graph_runtime_state.total_tokens or self.total_tokens,
376+
total_tokens=graph_runtime_state.total_tokens,
380377
total_steps=graph_runtime_state.node_run_steps,
381378
outputs=event.outputs,
382379
conversation_id=self._conversation.id,

api/core/app/apps/workflow/generate_task_pipeline.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def __init__(
106106

107107
self._task_state = WorkflowTaskState()
108108
self._wip_workflow_node_executions = {}
109-
self.total_tokens: int = 0
110109

111110
def process(self) -> Union[WorkflowAppBlockingResponse, Generator[WorkflowAppStreamResponse, None, None]]:
112111
"""
@@ -320,8 +319,6 @@ def _process_stream_response(
320319
if not workflow_run:
321320
raise Exception("Workflow run not initialized.")
322321

323-
# FIXME for issue #11221 quick fix maybe have a better solution
324-
self.total_tokens += event.metadata.get("total_tokens", 0) if event.metadata else 0
325322
yield self._workflow_iteration_completed_to_stream_response(
326323
task_id=self._application_generate_entity.task_id, workflow_run=workflow_run, event=event
327324
)
@@ -335,7 +332,7 @@ def _process_stream_response(
335332
workflow_run = self._handle_workflow_run_success(
336333
workflow_run=workflow_run,
337334
start_at=graph_runtime_state.start_at,
338-
total_tokens=graph_runtime_state.total_tokens or self.total_tokens,
335+
total_tokens=graph_runtime_state.total_tokens,
339336
total_steps=graph_runtime_state.node_run_steps,
340337
outputs=event.outputs,
341338
conversation_id=None,

0 commit comments

Comments
 (0)