@@ -1680,7 +1680,7 @@ class OpenAIStreamedResponse(StreamedResponse):
16801680    _provider_name : str 
16811681    _provider_url : str 
16821682
1683-     async  def  _get_event_iterator (self ) ->  AsyncIterator [ModelResponseStreamEvent ]:
1683+     async  def  _get_event_iterator (self ) ->  AsyncIterator [ModelResponseStreamEvent ]:   # noqa: C901 
16841684        async  for  chunk  in  self ._response :
16851685            self ._usage  +=  _map_usage (chunk , self ._provider_name , self ._provider_url , self ._model_name )
16861686
@@ -1706,23 +1706,25 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
17061706            # The `reasoning_content` field is only present in DeepSeek models. 
17071707            # https://api-docs.deepseek.com/guides/reasoning_model 
17081708            if  reasoning_content  :=  getattr (choice .delta , 'reasoning_content' , None ):
1709-                 yield  self ._parts_manager .handle_thinking_delta (
1709+                 for   e   in  self ._parts_manager .handle_thinking_delta (
17101710                    vendor_part_id = 'reasoning_content' ,
17111711                    id = 'reasoning_content' ,
17121712                    content = reasoning_content ,
17131713                    provider_name = self .provider_name ,
1714-                 )
1714+                 ):
1715+                     yield  e 
17151716
17161717            # The `reasoning` field is only present in gpt-oss via Ollama and OpenRouter. 
17171718            # - https://cookbook.openai.com/articles/gpt-oss/handle-raw-cot#chat-completions-api 
17181719            # - https://openrouter.ai/docs/use-cases/reasoning-tokens#basic-usage-with-reasoning-tokens 
17191720            if  reasoning  :=  getattr (choice .delta , 'reasoning' , None ):  # pragma: no cover 
1720-                 yield  self ._parts_manager .handle_thinking_delta (
1721+                 for   e   in  self ._parts_manager .handle_thinking_delta (
17211722                    vendor_part_id = 'reasoning' ,
17221723                    id = 'reasoning' ,
17231724                    content = reasoning ,
17241725                    provider_name = self .provider_name ,
1725-                 )
1726+                 ):
1727+                     yield  e 
17261728
17271729            # Handle the text part of the response 
17281730            content  =  choice .delta .content 
@@ -1887,12 +1889,13 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
18871889                if  isinstance (chunk .item , responses .ResponseReasoningItem ):
18881890                    if  signature  :=  chunk .item .encrypted_content :  # pragma: no branch 
18891891                        # Add the signature to the part corresponding to the first summary item 
1890-                         yield  self ._parts_manager .handle_thinking_delta (
1892+                         for   e   in  self ._parts_manager .handle_thinking_delta (
18911893                            vendor_part_id = f'{ chunk .item .id }  -0' ,
18921894                            id = chunk .item .id ,
18931895                            signature = signature ,
18941896                            provider_name = self .provider_name ,
1895-                         )
1897+                         ):
1898+                             yield  e 
18961899                elif  isinstance (chunk .item , responses .ResponseCodeInterpreterToolCall ):
18971900                    _ , return_part , file_parts  =  _map_code_interpreter_tool_call (chunk .item , self .provider_name )
18981901                    for  i , file_part  in  enumerate (file_parts ):
@@ -1925,11 +1928,12 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
19251928                    yield  self ._parts_manager .handle_part (vendor_part_id = f'{ chunk .item .id }  -return' , part = return_part )
19261929
19271930            elif  isinstance (chunk , responses .ResponseReasoningSummaryPartAddedEvent ):
1928-                 yield  self ._parts_manager .handle_thinking_delta (
1931+                 for   e   in  self ._parts_manager .handle_thinking_delta (
19291932                    vendor_part_id = f'{ chunk .item_id }  -{ chunk .summary_index }  ' ,
19301933                    content = chunk .part .text ,
19311934                    id = chunk .item_id ,
1932-                 )
1935+                 ):
1936+                     yield  e 
19331937
19341938            elif  isinstance (chunk , responses .ResponseReasoningSummaryPartDoneEvent ):
19351939                pass   # there's nothing we need to do here 
@@ -1938,11 +1942,12 @@ async def _get_event_iterator(self) -> AsyncIterator[ModelResponseStreamEvent]:
19381942                pass   # there's nothing we need to do here 
19391943
19401944            elif  isinstance (chunk , responses .ResponseReasoningSummaryTextDeltaEvent ):
1941-                 yield  self ._parts_manager .handle_thinking_delta (
1945+                 for   e   in  self ._parts_manager .handle_thinking_delta (
19421946                    vendor_part_id = f'{ chunk .item_id }  -{ chunk .summary_index }  ' ,
19431947                    content = chunk .delta ,
19441948                    id = chunk .item_id ,
1945-                 )
1949+                 ):
1950+                     yield  e 
19461951
19471952            elif  isinstance (chunk , responses .ResponseOutputTextAnnotationAddedEvent ):
19481953                # TODO(Marcelo): We should support annotations in the future. 
0 commit comments