-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathresponses-structured-aoai-v1.py
More file actions
50 lines (44 loc) · 1.34 KB
/
responses-structured-aoai-v1.py
File metadata and controls
50 lines (44 loc) · 1.34 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
43
44
45
46
47
48
49
50
import os
from openai import OpenAI
from dotenv import load_dotenv
import json
load_dotenv()
client = OpenAI(
api_key=os.getenv("AZURE_OPENAI_API_KEY"),
base_url=os.getenv("AZURE_OPENAI_V1_API_ENDPOINT"),
)
response = client.responses.create(
model=os.environ["AZURE_OPENAI_API_MODEL"],
input=[
{"role": "system", "content": "Extract the event information."},
{"role": "user", "content": "Alice and Bob are going to a science fair on Friday."}
],
text={
"format": {
"type": "json_schema",
"name": "calendar_event",
"schema": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"date": {
"type": "string"
},
"participants": {
"type": "array",
"items": {
"type": "string"
}
},
},
"required": ["name", "date", "participants"],
"additionalProperties": False
},
"strict": True
}
}
)
event = json.loads(response.output_text)
print(event)