Add OpenAIBatchChatGenerator for processing batch API requests (#8482) - #12268
Open
DhanushPillay wants to merge 3 commits into
Open
Add OpenAIBatchChatGenerator for processing batch API requests (#8482)#12268DhanushPillay wants to merge 3 commits into
DhanushPillay wants to merge 3 commits into
Conversation
DhanushPillay
requested review from
julian-risch
and removed request for
a team
August 7, 2026 07:38
|
@DhanushPillay is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
DhanushPillay
force-pushed
the
feature/openai-batch-api
branch
4 times, most recently
from
August 7, 2026 08:04
b0a0ab1 to
44ea597
Compare
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||
DhanushPillay
force-pushed
the
feature/openai-batch-api
branch
2 times, most recently
from
August 7, 2026 09:18
1583b27 to
289c033
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Proposed Changes:
Adds the
OpenAIBatchChatGeneratorto support OpenAI's Batch API. This provides a 50% cost reduction for high-throughput, latency-insensitive workloads (like evals).list[list[ChatMessage]]) instead of just one, and outputs the exact same structure back._build_jsonl): Converts the conversations into a JSONL file in memory. Generates acustom_idfor each request to keep track of their original order.run/run_async): Uploads the JSONL file to OpenAI, creates the batch job, and enters a polling loop (checking status every 30 seconds)._parse_results): Once the batch completes, we download the output file. Because the Batch API returns raw JSON dicts instead of standard Pydantic models, we use a lightweight dictionary parser (_parse_choices) to convert them back into HaystackChatMessageobjects, mapping them to their original order using thecustom_id.How did you test it?
test_openai_batch.pymocking out the OpenAI client. Tests cover serialization, building the jsonl, parsing results (including out-of-order responses), and error handling/timeouts.hatch run test:unitandhatch run test:types(mypy is clean).Notes for the reviewer
openai.py. I had to write a lightweight dictionary-based parser (_parse_choices), but the logic itself is pretty much identical.generation_kwargs, just to make sure we don't silently drop data.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.