@@ -2187,11 +2187,12 @@ def has_structured_output(self) -> bool:
21872187
21882188 stream_callback = _TestCallbackHandler ()
21892189
2190+ chunk = None
21902191 for chunk in chat .stream (
21912192 "Tell me a joke about cats." , config = {"callbacks" : [stream_callback ]}
21922193 ):
21932194 validation_function (chunk )
2194- assert chunk
2195+ assert chunk is not None , "Stream returned no chunks - possible API issue"
21952196
21962197 assert len (stream_callback .options ) == 1 , (
21972198 "Expected on_chat_model_start to be called once"
@@ -2268,11 +2269,12 @@ def has_structured_output(self) -> bool:
22682269
22692270 astream_callback = _TestCallbackHandler ()
22702271
2272+ chunk = None
22712273 async for chunk in chat .astream (
22722274 "Tell me a joke about cats." , config = {"callbacks" : [astream_callback ]}
22732275 ):
22742276 validation_function (chunk )
2275- assert chunk
2277+ assert chunk is not None , "Stream returned no chunks - possible API issue"
22762278
22772279 assert len (astream_callback .options ) == 1 , (
22782280 "Expected on_chat_model_start to be called once"
@@ -2338,8 +2340,10 @@ class Joke(BaseModelV1): # Uses langchain_core.pydantic_v1.BaseModel
23382340 result = chat .invoke ("Tell me a joke about cats." )
23392341 assert isinstance (result , Joke )
23402342
2343+ chunk = None
23412344 for chunk in chat .stream ("Tell me a joke about cats." ):
23422345 assert isinstance (chunk , Joke )
2346+ assert chunk is not None , "Stream returned no chunks - possible API issue"
23432347
23442348 # Schema
23452349 chat = model .with_structured_output (
@@ -2349,9 +2353,10 @@ class Joke(BaseModelV1): # Uses langchain_core.pydantic_v1.BaseModel
23492353 assert isinstance (result , dict )
23502354 assert set (result .keys ()) == {"setup" , "punchline" }
23512355
2356+ chunk = None
23522357 for chunk in chat .stream ("Tell me a joke about cats." ):
23532358 assert isinstance (chunk , dict )
2354- assert isinstance ( chunk , dict ) # for mypy
2359+ assert chunk is not None , "Stream returned no chunks - possible API issue"
23552360 assert set (chunk .keys ()) == {"setup" , "punchline" }
23562361
23572362 def test_structured_output_optional_param (self , model : BaseChatModel ) -> None :
@@ -2473,8 +2478,10 @@ class Joke(BaseModelProper):
24732478 result = chat .invoke (msg )
24742479 assert isinstance (result , Joke )
24752480
2481+ chunk = None
24762482 for chunk in chat .stream (msg ):
24772483 assert isinstance (chunk , Joke )
2484+ assert chunk is not None , "Stream returned no chunks - possible API issue"
24782485
24792486 # Schema
24802487 chat = model .with_structured_output (
@@ -2484,9 +2491,10 @@ class Joke(BaseModelProper):
24842491 assert isinstance (result , dict )
24852492 assert set (result .keys ()) == {"setup" , "punchline" }
24862493
2494+ chunk = None
24872495 for chunk in chat .stream (msg ):
24882496 assert isinstance (chunk , dict )
2489- assert isinstance ( chunk , dict ) # for mypy
2497+ assert chunk is not None , "Stream returned no chunks - possible API issue"
24902498 assert set (chunk .keys ()) == {"setup" , "punchline" }
24912499
24922500 def test_pdf_inputs (self , model : BaseChatModel ) -> None :
0 commit comments