-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure_api.py
60 lines (49 loc) · 1.62 KB
/
azure_api.py
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
52
53
54
55
56
57
58
59
60
import os
import dotenv
from openai import AzureOpenAI
dotenv.load_dotenv()
def main():
client = AzureOpenAI(
api_key=os.getenv("AZURE_OPENAI_KEY"),
api_version="2023-10-01-preview",
azure_endpoint=os.getenv("AZURE_OPENAI_ENDPOINT"),
)
messages = [
{
"role": "user",
"content": "Find beachfront hotels in San Diego for less than $300 a month with free breakfast.",
}
]
functions = [
{
"name": "search_hotels",
"description": "Retrieves hotels from the search index based on the parameters provided",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location of the hotel (i.e. Seattle, WA)",
},
"max_price": {
"type": "number",
"description": "The maximum price for the hotel",
},
"features": {
"type": "string",
"description": "A comma separated list of features (i.e. beachfront, free wifi, etc.)",
},
},
"required": ["location"],
},
}
]
response = client.chat.completions.create(
model="gpt-35-turbo-16k",
messages=messages,
functions=functions,
function_call="auto",
)
print(response.choices[0].message.model_dump_json(indent=2))
if __name__ == "__main__":
main()