ah … @sps I see. So @theemilydyson might just need to update.
Of course:
Name: openai
Version: 0.27.0
Summary: Python client library for the OpenAI API
Author: OpenAI
Author-email: support@openai.com
License:
Location: /usr/local/lib/python3.11/site-packages
Requires: aiohttp, requests, tqdm
Required-by:
I have the same problem. have updated openai to 0.27.0. still getting same attribute error.
Hey @theemilydyson and @tamalon1
I am back to my desk and ran some tests.
I am currently on python 3.7.4 and using the the same openai module, I was able to call the chat completion endpoint.
And as it turns out the package required python 3.7.1 and upwards, it’s mentioned in the end of docs on the python package index page I shared above.
Requirements
- Python 3.7.1+
In general, we want to support the versions of Python that our customers are using. If you run into problems with any version issues, please let us know at on our support page.
@sps Did you mean it only works with python 3.7.x?
theemilydyson had python 3.11? /usr/local/lib/python3.11/site-packages
I got the same error when trying this
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages= [
{'role': 'user', 'content': 'Translate the following English text to French: '}
]
)
This is my pip show openai
output
ame: openai
Version: 0.27.0
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: support@openai.com
License:
Location: /Users/c/Projects/chat/venv/lib/python3.10/site-packages
Requires: tqdm, requests, aiohttp
Required-by:
I could find ChatCompletion in the installed package though
Hi @chatgpt711
No, it will work with all 3.7.1+ versions.
There’s no straightforward answer to the problem AFAIK. Could be multiple versions of python, could be improperly installed package.
Can you share the output of the following:
pip --version
python -m pip --version
pip3 --version
@sps
It worked after I deleted venv and reinstalled openai. Thanks
Btw, this was what I got before deleting venv.
pip 21.2.4 from /Users/j/Projects/chat/venv/lib/python3.10/site-packages/pip (python 3.10)
I got the same with you. Defined the openai version is 0.26.0 and updated to 0.27.0 but didn’t work. After that, I tried to upgrade pip openai version, then it worked. You may try it.
This work for me! Thanks!!
I am use VSCode in MacOS:
- rm -rf venv
- conda deactivate
- conda activate base
- pip uninstall openai
- pip install openai
I was getting this problem as well. The example worked using curl but not python. But I was able to get it working in my virtual environment by updating to openapi version 0.27.0. I probably updated in a roundabout way.
- Checked Python client library for the OpenAI API version with
pip show openai
. It was Version: 0.19.0. - In
requirements.txt
file, updated the openapi version toopenai==0.27.0
. - Ran
pip install -r requirements.txt
. - Ran
pip show openai
again. It showed version 0.27.0 now. - Ran the python sample again and didn’t get the no attribute ‘ChatCompletion’ error.
- Subsequently updated
requirements.txt
file toopenai>=0.27.0
.
I just use ‘pip install openai --upgrade’. It’s upgrade from 26.5 to 27.2. Looks like resolve this issue.
Mine one was very classic,
Make sure you don’t have a file called “openai.py”
I am also getting the same error. I checked openai version and it was 0.19.x, upgraded to 0.27.5 and Python version is 3.9.5. I ran code again but still getting the same error
same here buddy. then what to do . please help guys. i am stucking. what to complte anderew ng course. prompt engineering course.
What do I do if I have a filed called openai.py? Do I delete it? It seems like I need it to import openai but correct me if I am wrong.
In my case it worked with updating my open ai.
First I ran the command to check my openai version which was 0.23.1 or something (use command pip show openai in command prompt or !pip show openai in jupyter lab.
Then I ran !pip install --upgrade openai in jupyter lab (remove ! when running in command prompt).
after that I ran the command and worked for me.
openai.api_key = “sk-…”
response = get_completion(prompt)
Man you just saved me a ton of time. That was my problem.
thanks you so much, that was the error in my code
upgrade your openai package pip install --upgrade openai or uninstall openai pip uninstall openai then install newly pip install openai
if you are using chat gpt more than 3 months then the attribute error is arising because of exceed limit for usage, so open new open ai account which can help to ressolve the problem