I cant access gpt-3.5-turbo with python because I seem to be getting the error " AttributeError: module ‘openai’ has no attribute ‘ChatCompletion’"
I have updated to openai v0.27.0, as well as tried using new API keys just incase that was causing the issue. Ive double checked that I actually have updated to the new version of openai 0.27.0 by running “pip list”. Ive also tried " pip install --upgrade openai " and “pip install openai-0.27.0-py3-none-any.whl”
Im not sure what else I can try, does anyone have any ideas?
Thanks.
They have not released the version with the ChatCompletion api … you need to grab ‘main’ from the python-openai repo as your dependency to have this work now. I am sure they will release soon.
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
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.
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 to openai==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 to openai>=0.27.0.
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