API Endpoints Yielding Errors with Different Versions - Most Recent Lacks ChatCompletions


In version 1.1.1 this does not work, because AttributeError: module ‘openai’ has no attribute ‘ChatCompletion’.

model_engine = "gpt-3.5-turbo"

def get_response(background_information, input_text):
    current_time = datetime.datetime.now()
    response = openai.ChatCompletion.create(
            {"role": "system", "content": "Keep your responses relatively short."},
            {"role": "system", "content": "You are an AI language model that can understand and remember the information provided to you."},
            {"role": "system", "content": "Please pay close attention to the background information in the user message and use it to answer the user's question."},
            {"role": "system", "content": "Each line of the input contains a Date and Time. If prompted, use this to determine when a message was inputted. When saying a time, just say the hour and minute."},
            {"role": "system", "content": "All time based responses should be given as HH:MM. Do not give the full output time unless requested."},
            {"role": "user", "content": "2023-04-01 14:33:25.087262 - User: I've always wanted a pony"},
            {"role": "user", "content": "2023-04-01 14:42:00.852956 - User: At what time did I say I have always wanted a pony?"},
            {"role": "assistant", "content": "You told me you have always wanted a pony at 2:33 PM"},
            {"role": "system", "content": "*ONLY* respond to the most recent question, based on the time at the beginning of the line."},
            {"role": "user", "content": "Do not respond with the time the question was asked, unless requested."},
            {"role": "user", "content": "When responding to a question, do not repeat it back. Just answer it."},
            {"role": "user", "content": "Only respond to the most recent question"},
            {"role": "user", "content": background_information + "\n" + input_text + str(current_time)}]
    return response['choices'][0]['message']['content'].strip()

However this works.

client = OpenAI(
    # defaults to os.environ.get("OPENAI_API_KEY")
    api_key="key here",

# Function to speak the output
def speak(text):
    speech_file_path = Path(__file__).parent / "speech.mp3"
    response = client.audio.speech.create(

    # Play the speech file using an appropriate media player library or command
    # Example using pygame (you'll need to install pygame library first)
    while pygame.mixer.music.get_busy():  # Wait for the playback to finish

That being said, if I downgrade to a version where ChatCompletions endpoint is available, TTS does not function. How can I call ChatCompletions on the most recent version? (1.1.1)

1 Like

Hi, how do you downgrade to the previous version?

pip install openai==

run that to see the versions.


pip install openai==1.1.1

or whatever you choose.

1 Like

Hi, I’m having an issue with directly pip installing the latest openai update (1.1.1). I have even tested this on Google colab as that is a standardly configured IDE. The code

!pip install openai


import openai

return this error:

ImportError: cannot import name ‘override’ from ‘typing_extensions’ (/usr/local/lib/python3.10/dist-packages/typing_extensions.py)

How did you manage to successfully pip install/use the latest openai version danieljmueller?

I ran pip install openai==1.1.1. Just remember that your python version must be the highest in the path, otherwise it will install to whichever is higher. For instance if python 3.9 is above 3.8, by default pip will install to 3.9. Once this is done you should be able to pip install successfully.