-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
28 lines (23 loc) · 775 Bytes
/
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
import requests
from dotenv import load_dotenv
import os
import openai
# Load environment variables from the .env file
load_dotenv()
# Get the OPENAI_API_KEY environment variable
api_key = os.environ.get('OPENAI_API_KEY')
if api_key is None:
raise ValueError("OPENAI_API_KEY environment variable not set")
print(api_key)
# Instantiate the OpenAI client with the API key
client = openai.OpenAI(api_key=api_key)
# Make a completion request
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{'role':'system', 'content':'You are an assistant that speaks like b-mo from adventure time. Short, sweet, and to the point.'},
{"role": "user", "content": sampleContent},
]
)
# Print the response
print(completion.choices[0].message)