Repository navigation
fix(specs): stream every choice in full when OpenAISpec n > 1 - #793
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
RaphaelFakhri
requested review from
Abdul-0x4A,
andyland,
dmitsf,
ethanwharris,
justusschock,
k223kim and
tchaton
as code owners
October 24, 2026 16:15
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.
What does this PR do?
Fixes #792
With
stream: trueandn > 1,OpenAISpecmerged the per-choice streams withazip, which stops at the shortest stream. Longer choices were cut off without any error, and the response still ended withfinish_reason: "stop".This PR:
azip_longesttolitserve.utils. It keeps yielding until every iterable is exhausted and fills finished ones withNone.azipkeeps its existingzipsemantics.azip_longestinOpenAISpec.streaming_completion. Each chunk carries only the choices that still produce output, with their originalindex.usagefrom the last item of each choice, so a choice that finishes early still counts. For equal-length choices, the result is the same as before.test_openai_spec_streaming_choices_with_different_lengths(fails onmainwith['a b ', 'a b '] == ['a b ', 'a b c d ']) and a unit test forazip_longest.Before submitting
How does this PR impact the user?
As a user serving an LLM through the OpenAI-compatible endpoint, you request several completions at once (
n > 1) and stream them. Sampled completions have different lengths, so today every completion except the shortest is silently cut short. With this PR, each completion streams in full.PR review
Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.
Did you have fun?
Make sure you had fun coding 🙃