chatCompletion error

import openai
import os
import sys

question = input(“What is your question? \n”)

while True:
openai.api_key = os.environ[‘OPENAI_API_KEY’]
#if openai.api_key == “”:
You haven’t set up your API key yet.

If you don't have an API key yet, visit:

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 =
“role”: “system”,
“content”: “You are a helpful assistant.”
}, {
“role”: “user”,
“content”: “Who won the world series in 2020?”
}, {
“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

Hi @laditi454

In the latest OpenAI package the response.choices object type is changed . Kindly modify the output statement to:

output = response.choices[0].message.content

This should solve your problem. If you still face any issues, please feel free to get back to us.