Good morning Sir/Ma’am
I expected my code to give an output of getting answer with my first AI code using template but in my case it ask question but isn’t answering, giving me error. Please solve this issue. Here, below is my code
import openai
import os
import sys
question=input(“What is your question?”)
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:
https://platform.openai.com/signup
- 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”: question}
]
)
output=response[‘choices’][0][‘message’][‘content’]
print(output)