Skip to content

Commit

Permalink
Fix BaseOpenAIChatCompletionClient token usage (#4770)
Browse files Browse the repository at this point in the history
* Fix openai client token usage (#4769)

* Include actual_usage in add_usage function

* Make sure result is assigned

* remove method

---------

Co-authored-by: Jack Gerrits <[email protected]>
  • Loading branch information
gziz and jackgerrits authored Dec 30, 2024
1 parent cb1633b commit 0569689
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,8 @@ async def create(
logprobs=logprobs,
)

_add_usage(self._actual_usage, usage)
_add_usage(self._total_usage, usage)
self._total_usage = _add_usage(self._total_usage, usage)
self._actual_usage = _add_usage(self._actual_usage, usage)

# TODO - why is this cast needed?
return response
Expand Down Expand Up @@ -775,8 +775,8 @@ async def create_stream(
logprobs=logprobs,
)

_add_usage(self._actual_usage, usage)
_add_usage(self._total_usage, usage)
self._total_usage = _add_usage(self._total_usage, usage)
self._actual_usage = _add_usage(self._actual_usage, usage)

yield result

Expand Down

0 comments on commit 0569689

Please sign in to comment.