Query in the lesson - Writing your first AI code using template


Unable to understand this type of error. Have already created a new account so no issue of credits should arise.

It mentions something like : You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at GitHub - openai/openai-python: The official Python library for the OpenAI API for the API.
Is this a version support issue? If yes , how can i resolve it now?

Hi @nit.nitish02

In the latest OpenAI package the response.choices object type is changed . Kindly make the following changes in your code.

response = openai.chat.completions.create

and

return response.choices[0].message.content

This must solve your problem. We have updating the same in the training content as well. If you still face any issues please feel free to get back to us.

Sorry… this doesn’t seem to work for me… I am attaching the code below , kindly make suitable changes in it and revert.

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?”
}])

print(response.choices[0].message.content)

Hi @nit.nitish02

You should use return keyword in response.choices[0].message.content and not print statement. Please find the corrected code snippet attached below. Do try this and let us know if you encounter any issues.

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?”
}])

return response.choices[0].message.content

It says that Chat completion is no longer supported by openai. It is true. The new tool is chat.completions. So, try replacing “ChatCompletion” with “chat.completions” in your code.
Good luck! :four_leaf_clover:
for more information, go to Text generation - OpenAI API and click on Chat Completions.

PS: If similar problem arises, you can always go to https://platform.openai.com/docs/ and figure out what’s wrong as well as what you have to do.