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

Add support for usage limits #409

Open
wants to merge 4 commits into
base: rename-cost-to-usage
Choose a base branch
from
Open

Conversation

dmontagu
Copy link
Contributor

@dmontagu dmontagu commented Dec 18, 2024

This is an alternative implementation to #374, which uses the Usage struct (renamed from Cost in the base branch of this PR) to store the request count, and checks for limits to be exceeded.

Relative to that PR, I changed execution_limits and ExecutionLimits to usage_limits and UsageLimits respectively. But I think everything else is mostly the same.

@samuelcolvin if you don't want to rename Cost to Usage, I would still suggest we use the approach in this PR, just change the names back.

This could use more tests before merging, I wouldn't say I'm confident it is working properly in all cases yet. But I'm also not confident enough in the approach to really want to put a lot more effort into testing yet. (Though I'll note I did already add one simple test, and updated the FunctionModel and TestModel to track token counts in the usage.)

Copy link

cloudflare-workers-and-pages bot commented Dec 18, 2024

Deploying pydantic-ai with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3bb0e46
Status: ✅  Deploy successful!
Preview URL: https://cd2f556b.pydantic-ai.pages.dev
Branch Preview URL: https://usage-limits.pydantic-ai.pages.dev

View logs

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