@@ -1863,15 +1863,15 @@ def _replace_approval_contents_with_results(
18631863 msg .contents .pop (idx )
18641864
18651865
1866- def _get_finalizers_from_stream (stream : Any ) -> list [Callable [[Any ], Any ]]:
1866+ def _get_result_hooks_from_stream (stream : Any ) -> list [Callable [[Any ], Any ]]:
18671867 inner_stream = getattr (stream , "_inner_stream" , None )
18681868 if inner_stream is None :
18691869 inner_source = getattr (stream , "_inner_stream_source" , None )
18701870 if inner_source is not None :
18711871 inner_stream = inner_source
18721872 if inner_stream is None :
18731873 inner_stream = stream
1874- return list (getattr (inner_stream , "_finalizers " , []))
1874+ return list (getattr (inner_stream , "_result_hooks " , []))
18751875
18761876
18771877def _extract_function_calls (response : ChatResponse ) -> list [Content ]:
@@ -2220,12 +2220,12 @@ async def _get_response() -> ChatResponse:
22202220
22212221 response_format = mutable_options .get ("response_format" ) if mutable_options else None
22222222 output_format_type = response_format if isinstance (response_format , type ) else None
2223- stream_finalizers : list [Callable [[ChatResponse ], Any ]] = []
2223+ stream_result_hooks : list [Callable [[ChatResponse ], Any ]] = []
22242224
22252225 async def _stream () -> AsyncIterable [ChatResponseUpdate ]:
22262226 nonlocal filtered_kwargs
22272227 nonlocal mutable_options
2228- nonlocal stream_finalizers
2228+ nonlocal stream_result_hooks
22292229 errors_in_a_row : int = 0
22302230 prepped_messages = prepare_messages (messages )
22312231 fcc_messages : list [ChatMessage ] = []
@@ -2259,8 +2259,8 @@ async def _stream() -> AsyncIterable[ChatResponseUpdate]:
22592259 ** filtered_kwargs ,
22602260 )
22612261 )
2262- # pick up any finalizers from the previous stream
2263- stream_finalizers = _get_finalizers_from_stream (stream )
2262+ # pick up any result_hooks from the previous stream
2263+ stream_result_hooks [:] = _get_result_hooks_from_stream (stream )
22642264 async for update in stream :
22652265 all_updates .append (update )
22662266 yield update
@@ -2321,8 +2321,8 @@ async def _stream() -> AsyncIterable[ChatResponseUpdate]:
23212321
23222322 async def _finalize (updates : Sequence [ChatResponseUpdate ]) -> ChatResponse :
23232323 result = ChatResponse .from_chat_response_updates (updates , output_format_type = output_format_type )
2324- for finalizer in stream_finalizers :
2325- result = finalizer (result )
2324+ for hook in stream_result_hooks :
2325+ result = hook (result )
23262326 if isinstance (result , Awaitable ):
23272327 result = await result
23282328 return result
0 commit comments