fix(streaming): drop the redundant choice narrowing

ModelResponse.choices is declared list[Choices], so the second isinstance was an
unnecessary check basedpyright counts against the budget; only the response
itself can be the streaming variant.

Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
This commit is contained in:
Vineeth Sai 2026-08-27 11:04:08 -07:00
parent e1b0a578e3
commit 4dd061f29e

View file

@ -8632,16 +8632,14 @@ def _chunks_for_streaming_choice_index(
def _renumbered_first_choice(response: object, index: int) -> Choices | None:
"""The single choice a per-index build produced, renumbered to that index.
None when the build did not yield a usable non-streaming choice: `stream_chunk_builder`
is typed to admit a streaming response and a streaming choice, and either one leaves
nothing to merge.
None when the build did not yield a usable non-streaming response: `stream_chunk_builder`
is typed to admit a streaming one, which leaves nothing to merge.
"""
if not isinstance(response, ModelResponse) or not response.choices:
return None
first: Final = response.choices[0]
if not isinstance(first, Choices):
return None
return first.model_copy(update={"index": index}) # mutable-ok: model_copy stores what it is given
# ModelResponse.choices is declared list[Choices], so the first entry needs no
# further narrowing; only the response itself can be the streaming variant.
return response.choices[0].model_copy(update={"index": index}) # mutable-ok: model_copy stores what it is given
def _build_streaming_choices_per_index(