generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathazure_test_code.py
43 lines (36 loc) · 1003 Bytes
/
azure_test_code.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
import os
import requests
# Use this code to test your Azure OpenAI API key.
# Configuration
API_KEY = os.environ.get("AZURE_OPENAI_API_KEY")
headers = {
"Content-Type": "application/json",
"api-key": API_KEY,
}
# Payload for the request
payload = {
"messages": [
{
"role": "system",
"content": [
{
"type": "text",
"text": "You are an AI assistant that helps people find information."
}
]
}
],
"temperature": 0.7,
"top_p": 0.95,
"max_tokens": 800
}
# Use your Azure OpenAI endpoint
ENDPOINT = "Your Azure OpenAI endpoint here."
# Send request
try:
response = requests.post(ENDPOINT, headers=headers, json=payload)
response.raise_for_status() # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
except requests.RequestException as e:
raise SystemExit(f"Failed to make the request. Error: {e}")
# Handle the response as needed (e.g., print or process)
print(response.json())