I am taking the Artificial Intelligence training from Bolt. As part of it I was trying to write a code that returned only the output message to a question and not the model and other specifications. I was asked to use this code: output=response[‘choices’][0][‘message’][‘content’] to define the output variable with only the answer. This is my code:
import openai
import os
import sys
q=input(“What is your question/instruction? \n”)
openai.api_key = os.environ[‘OPENAI_API_KEY’]
response = openai.chat.completions.create(
model=“gpt-3.5-turbo”,
messages=[{
“role”: “user”,
“content”: q
}])
output=response[‘choices’][0][‘message’][‘content’]
print (output)
But i am getting the following error in the output:
What am I doing wrong? Kindly help.