Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAI Client Token Usage not being tracked #4769

Closed
gziz opened this issue Dec 20, 2024 · 0 comments · Fixed by #4770
Closed

OpenAI Client Token Usage not being tracked #4769

gziz opened this issue Dec 20, 2024 · 0 comments · Fixed by #4770
Assignees
Milestone

Comments

@gziz
Copy link
Contributor

gziz commented Dec 20, 2024

What happened?

The BaseOpenAIChatCompletionClient has a total_usage property that's supposed to track the token usage of the client.
However, it looks like the logic to do so is not implemented correctly.

Here's the function responsible of adding usage

def _add_usage(usage1: RequestUsage, usage2: RequestUsage) -> RequestUsage:
    return RequestUsage(
        prompt_tokens=usage1.prompt_tokens + usage2.prompt_tokens,
        completion_tokens=usage1.completion_tokens + usage2.completion_tokens,
    )

Here's how the function is being used

        _add_usage(self._total_usage, usage)

The function returns a RequestUsage object however, we are not even receiving that returned value.

AutoGen version

0.4

Which package was this bug in

Extensions

Model used

No response

Python version

No response

Operating system

No response

Any additional info you think would be helpful for fixing this bug

No response

gziz added a commit to gziz/autogen that referenced this issue Dec 20, 2024
@ekzhu ekzhu added this to the 0.4.0 milestone Dec 22, 2024
jackgerrits added a commit that referenced this issue Dec 30, 2024
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants