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

feat(google-common): Add tokenUsage to llmOutput of google-genai #7806

Merged

Conversation

Liboul
Copy link
Contributor

@Liboul Liboul commented Mar 6, 2025

In callbacks of google-genai chat models, the llmOutput doesn't contain a tokenUsage key, only generations, while the usage is known and computed at this point. This PR makes the llmOutput consistent with openai chat models.

Context: Trying to use UpstashRatelimitHandler with google-genai models raises this error:

Failed to log token usage for Upstash rate limit. It could be because the LLM returns the token usage in a different format than expected. See UpstashRatelimitHandler parameters. Got error: TypeError: Cannot read properties of undefined (reading 'promptTokens')

Copy link

vercel bot commented Mar 6, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
langchainjs-docs ✅ Ready (Inspect) Visit Preview Mar 6, 2025 5:39pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
langchainjs-api-refs ⬜️ Ignored (Inspect) Mar 6, 2025 5:39pm

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs labels Mar 6, 2025
Copy link
Collaborator

@jacoblee93 jacoblee93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this!

CC @afirstenberg

@dosubot dosubot bot added the lgtm PRs that are ready to be merged as-is label Mar 11, 2025
@jacoblee93 jacoblee93 changed the title Add tokenUsage to llmOutput of google-genai feat(google-common): Add tokenUsage to llmOutput of google-genai Mar 13, 2025
@jacoblee93 jacoblee93 merged commit 8004d9a into langchain-ai:main Mar 13, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto:nit Small modifications/deletions, fixes, deps or improvements to existing code or docs lgtm PRs that are ready to be merged as-is size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants