-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathresponses-structured-aoai.py
More file actions
51 lines (45 loc) · 1.42 KB
/
responses-structured-aoai.py
File metadata and controls
51 lines (45 loc) · 1.42 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
51
from openai import AzureOpenAI
from dotenv import load_dotenv
import os
import json
load_dotenv()
client = AzureOpenAI(
api_key = os.environ["AZURE_OPENAI_API_KEY"],
api_version = os.environ["AZURE_OPENAI_API_VERSION"],
azure_endpoint = os.environ["AZURE_OPENAI_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)