Dear Team,
While I was undergoing my training, I tried applying the same thing in replit which was showed in the one of the videos. But after I run the program It’s showing me an error.
Below is the template I used:
import openai
import os
import sys
try:
openai.api_key = os.environ[‘OPENAI_API_KEY’]
except KeyError:
sys.stderr.write(“”"
You haven’t set up your API key yet.
If you don’t have an API key yet, visit:
- Make an account or sign in
- Click “View API Keys” from the top right menu.
- Click “Create new secret key”
Then, open the Secrets Tool and add OPENAI_API_KEY as a secret.
“”")
exit(1)
response = openai.ChatCompletion.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?”}
]
)
print(response)
And below is the output I received after the I run this code:
Hoping for your reply soon and with a solution to it!