Function: openai.chatCompletion

I am creating a chatbot streamlit code directly understand my Snowflake account accessed via SSO in the cloud.

I got an error message as:
APIRemovedInV1: 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. You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface. Alternatively, you can pin your installation to the old version, e.g. pip install openai==0.28 A detailed migration guide is available here: v1.0.0 Migration Guide · openai/openai-python · Discussion #742 · GitHub

The python snippet is:
for delta in openai.ChatCompletion.create(
model=“gpt-3.5-turbo”, engine=“gpt35uc”,
messages=[{“role”: m[“role”], “content”: m[“content”]} for m in st.session_state.messages],

I selected openai module version 1.25 and otherse as shown in screenshot. Since it works when I deploy the code locally, I package the required libraries in a zip file and uploaded to the package stage in the corresponding schema. But still doesn’t work.

Could you please kindly advice?

Hey Winnie, I was having the same issue. I don’t write any of my own code. I use ChatGPT to write it. I found this on a forum and tried it as a response to the code given by ChatGPT and it would correct it until the code became more complicated and it would refuse. Here’s the response I found in a forum:

It seems you’re using the earlier syntax for the ChatCompletion API. The syntax was changed from response = openai.ChatCompletion.create(…) to client = OpenAI(api_key=‘…’) response =…) Additionally, your line here: question = response[‘choices’][0][‘message’][‘content’].strip() needs to be modified to question = response.choices[0].message.content.strip()

When that response was no longer working, I ran my code through Claude [Claude]
and that corrected the issue.

Its weird that ChatGPT cant write code in its own syntax.

Anyway, I dont understand much of this. Hope this helps!

There is advice already inluded in the error message. Is there something you don’t understand?

I check the README document in Github as suggested in the error message, but it doesn’t help.

You can run openai migrate to automatically upgrade your codebase to use the 1.0.0 interface. Alternatively, you can pin your installation to the old version

What do you want to do?

Acutally I see the old version of openai 0.27.4 is available in the streamlit package. I could also choose this one. In case if I would like to run openai migrate, how can I do it directly in the streamlit app within my Snowflake account?

The other issue might be due to Firewall. My company’s Snowflake account on Azure might be blocking the open ai instance. Error message: APIConnectionError: Error communicating with OpenAI. Would it be the case?

The same way you would run any other script, I guess? Or if you can’t, run it in another computer/environment.

Only your company’s admins would know.