-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Bogda01m/OpenAI batch mode #2367
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
PR Change SummaryImplemented batch processing support for OpenAI models to enhance cost efficiency and manage high-volume requests.
Modified Files
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
- Add comprehensive mocks for OpenAI batch API in test_examples.py - Mock batches.create, batches.retrieve, files.create, and files.content methods - Add realistic batch result data in JSONL format - Add expected output comments to batch examples in documentation - Resolves ModelHTTPError and PytestUnraisableExceptionWarning issues - All batch-related tests now pass successfully
…st cases for batch processing
@bogdan01m Thanks for working on this! I think we can make this feel a bit more Pydantic AI-native, though, and reuse more of the existing model request building and parsing logic from Since a batch request by definition cannot be part of an agentic loop, the closest parallel we have right now is the Direct API: https://ai.pydantic.dev/direct/. Those methods do one single request to the model API by taking in the model object, a list of messages ( I would expect a Pydantic AI batch API to similarly take a model object and messages + parameters for each batch item as input, and then once the batch items complete, return
We should be able to separate that logic from actually performing the chat-completions request, and also use it for building a batch request and parsing batch responses. That also suggests the method to create a new batch could live on the existing That approach wouldn't immediately support Let me know what you think! |
Add OpenAI batch processing support
Implements batch processing for OpenAI models to help reduce costs and handle rate limits when processing large volumes of requests.
Summary
pydantic_ai.batches.openai
module with batch processing capabilitiesKey Features
Test Plan
Closes #1771
Addresses a requested feature for high-volume request processing.
Planning to add Anthropic batch support next.