-
Notifications
You must be signed in to change notification settings - Fork 17k
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
core[patch]: add token counting callback handler #30481
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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.
implementation looks good, needs more api reference documentation
|
||
callback = UsageMetadataCallbackHandler() | ||
results = llm.batch(["Hello", "Goodbye"], config={"callbacks": [callback]}) | ||
print(callback) |
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.
printing the callback isn't that useful I think.
instead
print(callback.usage_metadata)
and consider showing example output
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.
the callback does implement __repr__
, so it renders OK but I think it's better to do callback.usage_metadata
as you suggest to show people how to access the underlying dict.
Stripped-down version of OpenAICallbackHandler that just tracks
AIMessage.usage_metadata
.