Skip to content

APIRemovedInV1: You tried to access openai.ChatCompletion, but this is no longer supported #987

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
1 task done
Anand0805 opened this issue Dec 18, 2023 · 5 comments
Closed
1 task done
Labels
bug Something isn't working

Comments

@Anand0805
Copy link

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • This is an issue with the Python library

Describe the bug

I'm trying to create a simple BOT however getting the below error.
APIRemovedInV1: 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: #742

Validations:
Environment Check done
Upgraded OpenAI Python Library
Restarted Kernel
Validated API key

To Reproduce

Code attached

Code snippets

# Streamlit UI
st.title("Vitamin Quiz Bot")

# Initialize session state
if 'iteration' not in st.session_state:
    st.session_state.iteration = 0
    st.session_state.quiz_active = False

# Main loop for the quiz
user_input = st.text_input("You (Iteration {}):".format(st.session_state.iteration))

if user_input.lower() == "lets begin the quiz":
    st.session_state.quiz_active = True

if st.session_state.quiz_active:
    # Generate a question
    chat_history = [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Generate a question about vitamins and minerals for a 3rd-grade quiz."},
    ]
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=chat_history,
        max_tokens=50,
        temperature=0.7,
    )
    question = response['choices'][0]['message']['content'].strip()

    # Display the question
    st.text("Bot: {}".format(question))

    # Get user's response
    user_response = st.text_input("You:")

    # Evaluate the response
    if st.button("Submit"):
        st.text("You said: {}".format(user_response))

OS

windows

Python version

Python 3.12.1

Library version

openai 1.5.0

@Anand0805 Anand0805 added the bug Something isn't working label Dec 18, 2023
@BlueHephaestus
Copy link

It seems you're using the earlier syntax for the ChatCompletion API. The syntax was changed from

response = openai.ChatCompletion.create(...)

to

client = OpenAI(api_key='...')
response = client.chat.completions.create(...)

Additionally, your line here:

question = response['choices'][0]['message']['content'].strip()

needs to be modified to

question = response.choices[0].message.content.strip()

After doing these modifications on the same environment, I was able to get your app to run no problem!

17b1ee58318cccff9b0b3f907ca03fed

You can see some more examples of the usage of the new API in the examples/: https://github.com/openai/openai-python/blob/main/examples/demo.py and in the main README.

Hope that clears things up!

@lightonkalumba
Copy link

Thanks was also facing the same issue

@autodidact01
Copy link

I get a TypeError: Client.init() got an unexpected keyword argument 'proxies'. after the API issue is resolved. Did anyone else face this too? Please let me know how it can be fixed.

@RobertCraigie
Copy link
Collaborator

You need to update to the latest version, that was a bug which has been fixed.

@autodidact01
Copy link

autodidact01 commented Dec 11, 2024

Thank you for the quick reply. It works now!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants