Skip to content

Commit 14dc052

Browse files
[router]Replace requests lib with openai in e2e_response_api (#13293)
1 parent b223669 commit 14dc052

File tree

8 files changed

+305
-479
lines changed

8 files changed

+305
-479
lines changed

sgl-router/py_test/e2e_response_api/backends/test_grpc_backend.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import unittest
1212
from pathlib import Path
1313

14+
import openai
15+
1416
# Add e2e_response_api directory for imports
1517
_TEST_DIR = Path(__file__).parent.parent
1618
sys.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):

sgl-router/py_test/e2e_response_api/backends/test_http_backend.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import unittest
1414
from pathlib import Path
1515

16+
import openai
17+
1618
# Add e2e_response_api directory for imports
1719
_TEST_DIR = Path(__file__).parent.parent
1820
sys.path.insert(0, str(_TEST_DIR))
@@ -52,6 +54,7 @@ def setUpClass(cls):
5254
)
5355

5456
cls.base_url = cls.cluster["base_url"]
57+
cls.client = openai.Client(api_key=cls.api_key, base_url=cls.base_url + "/v1")
5558

5659
@classmethod
5760
def tearDownClass(cls):
@@ -93,6 +96,7 @@ def setUpClass(cls):
9396
)
9497

9598
cls.base_url = cls.cluster["base_url"]
99+
cls.client = openai.Client(api_key=cls.api_key, base_url=cls.base_url + "/v1")
96100

97101
@classmethod
98102
def tearDownClass(cls):

0 commit comments

Comments
 (0)