After the latest OpenAI deprecations in early Jan this year, I’m trying to convert from the older API calls to the newer ones. (openai==0.28.0 to 1.10.0)
After switching to the new functions I always get one error: ImportError: cannot import name ‘OpenAI’ from ‘openai’.
I’m working on an AWS EC2 instance, and I’ve tried to re-install the openai package, and upgrade it.
None of these fixes worked.
CODE:
from openai import OpenAI
client = OpenAI()
def openai_call(content):
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{
"role": "user",
"content": f"{content}"
}
],
temperature=1,
max_tokens=256,
top_p=1,
frequency_penalty=0,
presence_penalty=0)
return response.choices[0].message.content
ERROR (IN AWS LOGS):
Feb 01 18:14:33 ip-172-31-39-220 gunicorn[1641]: File "/home/ubuntu/code_src/app.py", line 9, in <module>
Feb 01 18:14:33 ip-172-31-39-220 gunicorn[1641]: import utils
Feb 01 18:14:33 ip-172-31-39-220 gunicorn[1641]: File "/home/ubuntu/code_src/utils.py", line 10, in <module>
Feb 01 18:14:33 ip-172-31-39-220 gunicorn[1641]: from openai import OpenAI
Feb 01 18:14:33 ip-172-31-39-220 gunicorn[1641]: ImportError: cannot import name 'OpenAI' from 'openai' (/home/ubuntu/code_src/venv/lib/python3.10/site-packages/openai/__init__.py
I tried to re-install and upgrade the packages, my current openai version is 1.10.0, but still it doesn’t seem to work.
Attempt 1: pip install --upgrade openai==1.10.0
Attempt 2: pip uninstall openai
pip install openai==1.10.0
None of this seems to work. When I run it on a python interpreter shell with version 3.10.12, it works, along with the functions. When I try it on my files on the flask (gunicorn) server, it stops working. Does anyone know why?
Please let me know how I can fix it.