-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Adding usage info in llm.py #4172
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
Adding usage info in llm.py #4172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
lorenzejay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely ! Can you add a couple tests showing this with
llm.call
llm.acall?
lorenzejay
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested and LGTM
Fixes #4170
Note
Introduces consistent token usage accounting across sync/async and streaming/non-streaming LiteLLM paths, with callback logging and event emission.
llm.py, extractusagefrom LiteLLM responses and stream chunks, call_track_token_usage_internal(usage_info), and invoke_handle_streaming_callbacks(...)in streaming flow; mirror usage tracking for_handle_non_streaming_responseand_ahandle_non_streaming_responseafter completion calls_ahandle_streaming_responsenow capturesusage_info, logs success callbacks, and updates internal counters before emitting completion eventstests/test_llm.pyto validate_token_usageupdates forcall/acallin both streaming and non-streaming modestest_usage_info_*(streaming and non-streaming, sync and async)Written by Cursor Bugbot for commit 104075a. This will update automatically on new commits. Configure here.