Skip to content

Commit

Permalink
fix: wrong token usage in iteration node for streaming result (langge…
Browse files Browse the repository at this point in the history
  • Loading branch information
rerorero authored Jun 18, 2024
1 parent 3005dd8 commit 7051ad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/core/app/entities/task_entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class Data(BaseModel):

class IterationNodeCompletedStreamResponse(StreamResponse):
"""
NodeStartStreamResponse entity
NodeCompletedStreamResponse entity
"""
class Data(BaseModel):
"""
Expand All @@ -385,6 +385,7 @@ class Data(BaseModel):
error: Optional[str] = None
elapsed_time: float
total_tokens: int
execution_metadata: Optional[dict] = None
finished_at: int
steps: int

Expand Down Expand Up @@ -545,4 +546,4 @@ class Data(BaseModel):
total_tokens: int = 0
node_data: BaseNodeData

current_iterations: dict[str, Data] = None
current_iterations: dict[str, Data] = None
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ def _handle_iteration_to_stream_response(self, task_id: str, event: QueueIterati
error=None,
elapsed_time=time.perf_counter() - current_iteration.started_at,
total_tokens=current_iteration.total_tokens,
execution_metadata={
'total_tokens': current_iteration.total_tokens,
},
finished_at=int(time.time()),
steps=current_iteration.current_index
)
Expand Down Expand Up @@ -276,7 +279,10 @@ def _handle_iteration_exception(self, task_id: str, error: str) -> Generator[Ite
error=error,
elapsed_time=time.perf_counter() - current_iteration.started_at,
total_tokens=current_iteration.total_tokens,
execution_metadata={
'total_tokens': current_iteration.total_tokens,
},
finished_at=int(time.time()),
steps=current_iteration.current_index
)
)
)

0 comments on commit 7051ad6

Please sign in to comment.