-
Notifications
You must be signed in to change notification settings - Fork 127
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
fix: Fix missing usage metadata in GoogleAIGeminiChatGenerator #1195
fix: Fix missing usage metadata in GoogleAIGeminiChatGenerator #1195
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.
Hey!
Thanks for the contribution.
Please sign the CLA and take my considerations into account.
Feel free to discuss them if anything is unclear.
# align openai api response | ||
usage_metadata = metadata.get("usage_metadata") | ||
if usage_metadata: | ||
candidate_metadata["usage"] = { | ||
"prompt_tokens": usage_metadata["prompt_token_count"], | ||
"completion_tokens": usage_metadata["candidates_token_count"], | ||
"total_tokens": usage_metadata["total_token_count"], | ||
} |
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.
- my impression is that the key names are wrong. See https://ai.google.dev/api/generate-content#UsageMetadata
- if we want to add this information to each candidate, we should
- use
prompt_tokens
as you did - use
completion_tokens
fromtokenCount
of each candidate (https://ai.google.dev/api/generate-content#v1beta.Candidate) - compute
total_tokens
as the sum of the previous to field.
- use
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.
Ok I was wrong. Google documentation is a bit confusing.
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.
Thanks for the PR!
In practice, I used your solution, added a comment + a test.
Related Issues
Proposed Changes:
How did you test it?
Notes for the reviewer
Checklist
fix:
,feat:
,build:
,chore:
,ci:
,docs:
,style:
,refactor:
,perf:
,test:
.