Skip to content

Conversation

@GoncaloGuedes
Copy link
Contributor

Description:
This PR adds a helper function to extract token usage from LLMResult or ChatResult, using the Azure AI response format returned by LangChain.

Key Changes:

  • Added get_token_usage_for_azure_ai utility, supporting Azure AI's token usage format as returned by LangChain.
  • Implemented unit tests to validate behavior.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 11, 2025
Copy link
Member

@anistark anistark 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 the PR @GoncaloGuedes

A few changes are needed.

Please rebase once once these fixes are done.

logger.info("No llm_output found in the LLMResult")
return TokenUsage(input_tokens=0, output_tokens=0)
output_tokens = get_from_dict(llm_output, "token_usage.input_tokens", 0)
input_tokens = get_from_dict(llm_output, "token_usage.output_tokens", 0)
Copy link
Member

Choose a reason for hiding this comment

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

The input_tokens and output_tokens seem to be swapped.

token_usage = get_token_usage_for_bedrock(bedrock_claude_result)
assert token_usage == TokenUsage(input_tokens=10, output_tokens=10)

# Azure AI
Copy link
Member

Choose a reason for hiding this comment

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

Please add a separate test for azure ai.

@anistark anistark added the blocked Blocked on further action label Aug 28, 2025
@anistark
Copy link
Member

Taken up in #2306

@anistark anistark closed this Sep 23, 2025
anistark added a commit that referenced this pull request Sep 23, 2025
## Issue Link / Problem Description
<!-- Link to related issue or describe the problem this PR solves -->
- contd #2004

---------

Co-authored-by: Goncalo Guedes <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocked Blocked on further action size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants