Skip to content

fix(langchain): token counts for vertex#1197

Merged
hassiebp merged 1 commit intomainfrom
fix-vertex-langchain-usage
May 27, 2025
Merged

fix(langchain): token counts for vertex#1197
hassiebp merged 1 commit intomainfrom
fix-vertex-langchain-usage

Conversation

@hassiebp
Copy link
Copy Markdown
Contributor

@hassiebp hassiebp commented May 27, 2025

Important

Adjusts token count calculations for Vertex AI in _parse_usage_model() to handle modality-specific token counts without going below zero.

  • Behavior:
    • Adjusts token count calculations in _parse_usage_model() in CallbackHandler.py for Vertex AI.
    • Subtracts modality-specific token counts from input and output ensuring they do not go below zero.
    • Applies changes to prompt_tokens_details, candidates_tokens_details, and cache_tokens_details.

This description was created by Ellipsis for 33e09bc. You can customize this summary. It will automatically update as commits are pushed.

Greptile Summary

Disclaimer: Experimental PR review

Updates token count handling for Vertex AI in the Langchain integration to ensure accurate usage statistics for multi-modal interactions.

  • Fixed token count processing in langfuse/langchain/CallbackHandler.py to properly subtract prompt, candidate, and cache tokens from total counts
  • Added support for multi-modal input/output token tracking in Vertex AI integrations
  • Improved accuracy of usage statistics by correctly handling different token types (prompt, completion, cache)

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@hassiebp hassiebp linked an issue May 27, 2025 that may be closed by this pull request
@hassiebp hassiebp enabled auto-merge (squash) May 27, 2025 09:37
@hassiebp hassiebp merged commit 923b0ff into main May 27, 2025
10 checks passed
@hassiebp hassiebp deleted the fix-vertex-langchain-usage branch May 27, 2025 09:39
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.

bug: Langchain Google Vertex AI tracing not working

1 participant