-
Notifications
You must be signed in to change notification settings - Fork 1k
Adding CountToken to Gemini #2137
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
base: main
Are you sure you want to change the base?
Conversation
Gemini Provides an endpoint to count token before sending an response https://ai.google.dev/api/tokens#method:-models.counttokens
added type adaptor
Removed extra assignment
Linting
Linting
Linting
Removed White Space
@kauabh I agree that if a model API has a method to count tokens, it would be nice to expose that on the But I don't think we should automatically use it when That check would need to be implemented here, just before we call pydantic-ai/pydantic_ai_slim/pydantic_ai/_agent_graph.py Lines 379 to 393 in b31c77d
This would require a method that exists on every model, so it'd be implemented as an abstract method on the base As for that concrete implementation, I recommend adding it to |
Gemini Provides an endpoint to count tokens https://ai.google.dev/api/tokens#method:-models.counttokens.
I think it will be useful and address some concerns in this issue #1794 (at least for gemini).
@DouweM Wanted to check if this will be helpful. If yes and if the approach is right, wanted to know if you can share some pointers around adding it in usage_limits for gemini. Happy to work on other models too, if this one make it through.