88
99import os
1010import sys
11- from typing import Any
12-
1311# Add parent directory to path for imports
1412sys .path .insert (0 , os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
1513
@@ -65,8 +63,10 @@ def test_basic_agent(self) -> None:
6563 )
6664
6765 response = agent .run ("What is 2+2?" )
68- assert response .content [0 ].text .strip () in ["4" , "2+2=4" , "2 + 2 = 4" ]
69- self ._print (f"Response: { response .content [0 ].text } " )
66+ # response is a list of message content blocks
67+ assert any ("4" in str (block .get ("text" , "" )) for block in response if block .get ("type" ) == "text" )
68+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
69+ self ._print (f"Response: { response_text } " )
7070
7171 def test_custom_headers (self ) -> None :
7272 """Test passing custom headers through message_params."""
@@ -87,8 +87,9 @@ def test_custom_headers(self) -> None:
8787 assert agent .message_params ["extra_headers" ]["X-Custom-Header" ] == "test-value"
8888
8989 response = agent .run ("What is 3+3?" )
90- assert "6" in response .content [0 ].text
91- self ._print (f"Response with custom headers: { response .content [0 ].text } " )
90+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
91+ assert "6" in response_text
92+ self ._print (f"Response with custom headers: { response_text } " )
9293
9394 def test_beta_headers (self ) -> None :
9495 """Test passing beta feature headers."""
@@ -105,8 +106,9 @@ def test_beta_headers(self) -> None:
105106
106107 # The API call should succeed even with beta headers
107108 response = agent .run ("What is 5*5?" )
108- assert "25" in response .content [0 ].text
109- self ._print (f"Response with beta headers: { response .content [0 ].text } " )
109+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
110+ assert "25" in response_text
111+ self ._print (f"Response with beta headers: { response_text } " )
110112
111113 def test_metadata (self ) -> None :
112114 """Test passing valid metadata fields."""
@@ -122,8 +124,9 @@ def test_metadata(self) -> None:
122124 )
123125
124126 response = agent .run ("What is 10/2?" )
125- assert "5" in response .content [0 ].text
126- self ._print (f"Response with metadata: { response .content [0 ].text } " )
127+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
128+ assert "5" in response_text
129+ self ._print (f"Response with metadata: { response_text } " )
127130
128131 def test_api_parameters (self ) -> None :
129132 """Test passing various API parameters."""
@@ -145,8 +148,9 @@ def test_api_parameters(self) -> None:
145148 assert params ["temperature" ] == 0.7
146149
147150 response = agent .run ("Say 'test'" )
148- assert response .content [0 ].text
149- self ._print (f"Response with custom params: { response .content [0 ].text } " )
151+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
152+ assert response_text
153+ self ._print (f"Response with custom params: { response_text } " )
150154
151155 def test_parameter_override (self ) -> None :
152156 """Test that message_params override config defaults."""
@@ -219,8 +223,9 @@ def test_combined_parameters(self) -> None:
219223 assert params ["top_k" ] == 5
220224
221225 response = agent .run ("What is 1+1?" )
222- assert "2" in response .content [0 ].text
223- self ._print (f"Response with combined params: { response .content [0 ].text } " )
226+ response_text = next ((block ["text" ] for block in response if block .get ("type" ) == "text" ), "" )
227+ assert "2" in response_text
228+ self ._print (f"Response with combined params: { response_text } " )
224229
225230 def run_all_tests (self ) -> None :
226231 """Run all test cases."""
0 commit comments