import openai
import os
import sys
question = input(“What is your question? \n”)
while True:
try:
openai.api_key = os.environ[‘OPENAI_API_KEY’]
#if openai.api_key == “”:
except:
sys.stderr.write(“”"
You haven’t set up your API key yet.
If you don't have an API key yet, visit:
https://platform.openai.com/signup
1. Make an account or sign in
2. Click "View API Keys" from the top right menu.
3. Click "Create new secret key"
Then, open the Secrets Tool and add OPENAI_API_KEY as a secret.
""")
response = openai.chat.completions.create(
model=“gpt-3.5-turbo”,
messages=[{
“role”: “system”,
“content”: “You are a helpful assistant.”
}, {
“role”: “user”,
“content”: “Who won the world series in 2020?”
}, {
“role”:
“assistant”,
“content”:
“The Los Angeles Dodgers won the World Series in 2020.”
}, {
“role”: “user”,
“content”: “Where was it played?”
}])
output = response[‘data’][0][‘messages’][1][‘content’]
print(“A:”, output, “\n”)
question = input(“Q: What is your question? \n”)
error in chat completion while genrating response