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

Handle missing token usage fields for Google AI #184

Merged
merged 1 commit into from
Sep 29, 2024

Conversation

elliotb
Copy link
Contributor

@elliotb elliotb commented Sep 27, 2024

Very sporadically, we see errors due to the usageMetadata map missing one of the token count fields when using the Google AI API.

This PR provides a fallback value when fetching either of the fields.

Copy link
Owner

@brainlid brainlid left a comment

Choose a reason for hiding this comment

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

Excellent. Thanks!

❤️💛💙💜

@brainlid brainlid merged commit 95063f1 into brainlid:main Sep 29, 2024
@elliotb elliotb deleted the google-ai-token-usage branch September 30, 2024 14:49
brainlid added a commit that referenced this pull request Oct 28, 2024
* 'main' of github.com:brainlid/langchain:
  Add AWS Bedrock support to ChatAnthropic (#154)
  Handle functions with no parameters for Google AI (#183)
  Handle missing token usage fields for Google AI (#184)
  Handle empty text parts from GoogleAI responses (#181)
  Support system instructions for Google AI (#182)
  feat: add OpenAI's new structured output API (#180)
  Support strict mode for tools (#173)
  Do not duplicate tool call parameters if they are identical (#174)
  🐛 cast tool_calls arguments correctly inside message_deltas (#175)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants