-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_responses.py
More file actions
42 lines (38 loc) · 1.17 KB
/
test_responses.py
File metadata and controls
42 lines (38 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import asyncio
import os
import json
from dotenv import load_dotenv
from openai import AsyncOpenAI
load_dotenv()
async def test():
client = AsyncOpenAI()
model = os.getenv("OPENAI_MODEL", "gpt-5.1-codex-mini")
print(f"Testing model: {model}")
response = await client.responses.create(
model=model,
instructions="You are a JSON generator. Output valid JSON.",
input="Output a JSON object with 'message' set to 'hi json'.",
text={
"format": {
"type": "json_schema",
"json_schema": {
"name": "greeting",
"strict": False,
"schema": {
"type": "object",
"properties": {"message": {"type": "string"}},
"required": ["message"]
}
}
}
}
)
print("Responses output text:")
try:
content = response.output[0].content[0].text
print(content)
print(json.loads(content))
except Exception as e:
print("Failed to parse output:", e)
print(response)
asyncio.run(test())