Skip to content

Conversation

@paxiaatucsdedu
Copy link
Member

@paxiaatucsdedu paxiaatucsdedu commented Oct 20, 2025

Summary

Adds total_tokens to AIMessage.additional_kwargs for chat responses, enabling users to track token consumption when using ChatOCIGenAI

Usage

python

response = chat.invoke("Tell me a joke?")
print(response.additional_kwargs.get('total_tokens')) 

Testing

✅ Cohere Command-R models
✅ Meta Llama models
test-temp.ipynb

Related issue

#22

Add total_tokens to AiMessage in cohere provider and generic provider
Add total tokens to AIMessage in cohere provider and generic provider
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label Oct 20, 2025
@YouNeedCryDear YouNeedCryDear self-requested a review October 20, 2025 23:32
Copy link
Member

@YouNeedCryDear YouNeedCryDear left a comment

Choose a reason for hiding this comment

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

Changes look good. Can you add some test cases to make sure the behavior consistent? @paxiaatucsdedu

Add unit test for total_tokens
@paxiaatucsdedu
Copy link
Member Author

Changes look good. Can you add some test cases to make sure the behavior consistent? @paxiaatucsdedu

Of course, I added unit test to test the total_tokens field in the response. @YouNeedCryDear

@YouNeedCryDear YouNeedCryDear merged commit 2e65d06 into oracle:main Oct 21, 2025
1 check passed
@dsantiago
Copy link

Tried via INSTANCE_PRINCIPAL but it still don't ouput token usage, could you check @paxiaatucsdedu ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OCA Verified All contributors have signed the Oracle Contributor Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants