@@ -1163,10 +1163,13 @@ class MyModel(TypedDict):
11631163 assert response == {"name" : "Erick" , "age" : 28 }
11641164
11651165 # Test stream
1166+ last_non_empty : dict [str , object ] | None = None
11661167 for chunk in model .stream ([message ]):
11671168 assert isinstance (chunk , dict )
11681169 assert all (key in ["name" , "age" ] for key in chunk )
1169- assert chunk == {"name" : "Erick" , "age" : 28 }
1170+ if chunk :
1171+ last_non_empty = chunk
1172+ assert last_non_empty == {"name" : "Erick" , "age" : 28 }
11701173
11711174
11721175@pytest .mark .extended
@@ -1243,14 +1246,30 @@ def test_context_catching() -> None:
12431246 response = chat .invoke ("What is the secret number?" )
12441247
12451248 assert isinstance (response , AIMessage )
1246- assert isinstance (response .content , str )
1249+ if isinstance (response .content , str ):
1250+ content_text = response .content
1251+ else :
1252+ content_text = " " .join (
1253+ block .get ("text" , "" )
1254+ for block in response .content
1255+ if isinstance (block , dict ) and block .get ("type" ) == "text"
1256+ )
1257+ assert isinstance (content_text , str )
12471258
12481259 # Using cached content in request
12491260 chat = ChatVertexAI (model_name = _DEFAULT_MODEL_NAME , rate_limiter = RATE_LIMITER )
12501261 response = chat .invoke ("What is the secret number?" , cached_content = cached_content )
12511262
12521263 assert isinstance (response , AIMessage )
1253- assert isinstance (response .content , str )
1264+ if isinstance (response .content , str ):
1265+ content_text = response .content
1266+ else :
1267+ content_text = " " .join (
1268+ block .get ("text" , "" )
1269+ for block in response .content
1270+ if isinstance (block , dict ) and block .get ("type" ) == "text"
1271+ )
1272+ assert isinstance (content_text , str )
12541273
12551274
12561275@pytest .mark .extended
0 commit comments