1111import unittest
1212from pathlib import Path
1313
14+ import openai
15+
1416# Add e2e_response_api directory for imports
1517_TEST_DIR = Path (__file__ ).parent .parent
1618sys .path .insert (0 , str (_TEST_DIR ))
@@ -51,6 +53,7 @@ def setUpClass(cls):
5153 )
5254
5355 cls .base_url = cls .cluster ["base_url" ]
56+ cls .client = openai .Client (api_key = cls .api_key , base_url = cls .base_url + "/v1" )
5457
5558 @classmethod
5659 def tearDownClass (cls ):
@@ -64,8 +67,7 @@ def test_conversation_with_multiple_turns(self):
6467
6568 def test_structured_output_json_schema (self ):
6669 """Override with simpler schema for Llama model (complex schemas not well supported)."""
67- data = {
68- "model" : self .model ,
70+ params = {
6971 "input" : [
7072 {
7173 "role" : "system" ,
@@ -89,28 +91,26 @@ def test_structured_output_json_schema(self):
8991 },
9092 }
9193
92- create_resp = self .make_request ("/v1/responses" , "POST" , data )
93- self .assertEqual (create_resp .status_code , 200 )
94-
95- create_data = create_resp .json ()
96- self .assertIn ("id" , create_data )
97- self .assertIn ("output" , create_data )
98- self .assertIn ("text" , create_data )
94+ create_resp = self .create_response (** params )
95+ self .assertIsNone (create_resp .error )
96+ self .assertIsNotNone (create_resp .id )
97+ self .assertIsNotNone (create_resp .output )
98+ self .assertIsNotNone (create_resp .text )
9999
100100 # Verify text format was echoed back correctly
101- self .assertIn ( "format" , create_data [ " text" ] )
102- self .assertEqual (create_data [ " text" ][ " format" ][ " type" ] , "json_schema" )
103- self .assertEqual (create_data [ " text" ][ " format" ][ " name" ] , "math_answer" )
104- self .assertIn ( "schema" , create_data [ " text" ][ " format" ] )
101+ self .assertIsNotNone ( create_resp . text . format )
102+ self .assertEqual (create_resp . text . format . type , "json_schema" )
103+ self .assertEqual (create_resp . text . format . name , "math_answer" )
104+ self .assertIsNotNone ( create_resp . text . format . schema_ )
105105
106106 # Find the message output
107107 output_text = next (
108108 (
109- content .get ( " text" , "" )
110- for item in create_data . get ( " output" , [])
111- if item .get ( " type" ) == "message"
112- for content in item .get ( " content" , [])
113- if content .get ( " type" ) == "output_text"
109+ content .text
110+ for item in create_resp . output
111+ if item .type == "message"
112+ for content in item .content
113+ if content .type == "output_text"
114114 ),
115115 None ,
116116 )
@@ -154,6 +154,7 @@ def setUpClass(cls):
154154 )
155155
156156 cls .base_url = cls .cluster ["base_url" ]
157+ cls .client = openai .Client (api_key = cls .api_key , base_url = cls .base_url + "/v1" )
157158
158159 @classmethod
159160 def tearDownClass (cls ):
0 commit comments