-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapp.py
More file actions
31 lines (26 loc) · 899 Bytes
/
Copy pathapp.py
File metadata and controls
31 lines (26 loc) · 899 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
import requests
import os
from dotenv import load_dotenv
load_dotenv()
api_url = os.getenv("OPENAI_API_URL")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {os.getenv('OPENAI_API_KEY')}",
}
prompt = "Write a one-sentence bedtime story about a unicorn."
model = os.getenv("OPENAI_MODEL")
body = {
"model": model,
"messages": [
{"role": "user", "content": prompt}
]
}
response = requests.post(api_url, headers=headers, json=body)
# print("Status Code:", response.status_code)
# print("Response Headers:", response.headers)
if response.status_code == 200:
data = response.json()
content = data['choices'][0]['message']['content']
print("\nExtracted content:")
print(content)
# Under a blanket of sparkling stars, a gentle unicorn tiptoed through a moonlit meadow, leaving trails of dreams for all the children fast asleep.