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