Search code examples
pythonpython-3.xopenai-apichatgpt-api

OpenAI API error: "The model gpt-3.5 does not exist or you do not have access to it"


I have the following code:

def speakgpt():
    aiactive = True
    while aiactive == True:
        if query[0] == 'deactivate':
            aiactive = False
        else:
            completion = openai.ChatCompletion.create(model="gpt-3.5", messages=[{"role": "user", "content": query}])
            text = completion.choices[0].message.content
            gptresult = (gTTS(text=text, lang=lang, slow=False, tld="com.scot"))
            speak(gptresult)

Running this results in the following error:

You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at https://github.com/openai/openai-python 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: https://github.com/openai/openai-python/discussions/742"

When I downgrade and use a version before 1.0.0, it gives the following error:

The model gpt-3.5 does not exist or you do not have access to it.

I don't know how to run openai migrate, which gives this error when run:

The term 'openai' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

I can't figure out from the migration guide what my code should be changed to.

Another post I found said to use openai.chat.completions.create in place of openai.ChatCompletions.create but that gives the same error:

The model gpt-3.5 does not exist or you do not have access to it.


Solution

  • Your code will start working if you solve both problems you currently have with it.

    Problem 1: You're using an incorrect method name

    What openai migrate will do is change this...

    openai.ChatCompletion.create
    

    ...to this.

    openai.chat.completions.create
    

    You can also change this manually.


    Problem 2: You have a typo in the OpenAI model name

    Change gpt-3.5 to gpt-3.5-turbo. The gpt-3.5 model doesn't exist. See all available OpenAI models in the official OpenAI documentation.