-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOPENAI.py
More file actions
31 lines (26 loc) · 745 Bytes
/
OPENAI.py
File metadata and controls
31 lines (26 loc) · 745 Bytes
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
# Sample Python API call to Azure Open API using REST!
#Ryan Mangan
import requests
import json
api_key = "<API_KEY>"
api_url = "https://<Instance>.openai.azure.com/openai/deployments/<Model>/completions?api-version=2022-12-01"
headers = {
"Content-Type": "application/json",
"api-key": api_key,
}
data = {
"prompt": "Hello ChatGPT!",
"max_tokens": 100,
"temperature": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"top_p": 0.5,
"best_of": 1,
"stop": None
}
response = requests.post(api_url, headers=headers, data=json.dumps(data))
if response.status_code == 200:
result = json.loads(response.content)["choices"][0]["text"]
print(result)
else:
print(f"Error: {response.status_code}")