I’ve searched the forum and the internet and I can not figure out how to fix this issue. Can someone please tell me how to fix this problem?
#code
import openai
import os
openai.api_key = os.getenv("OPENAI_API_KEY", "XXXXXXXXX")
def chat_with_gpt():
print("Welcome to ChatGPT Clone! Type 'exit' to end the conversation.\n")
# Conversation history
messages = [{"role": "system", "content": "You are a helpful assistant."}]
while True:
# Get user input
user_input = input("You: ")
if user_input.lower() == "exit":
print("Goodbye!")
break
# Append user message to history
messages.append({"role": "user", "content": user_input})
try:
# Call the OpenAI API
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
)
# Get assistant's reply
assistant_reply = response.choices[0].message.content
print(f"ChatGPT: {assistant_reply}")
# Append assistant response to history
messages.append({"role": "assistant", "content": assistant_reply})
except Exception as e:
print(f"An error occurred: {e}")
break
if __name__ == "__main__":
chat_with_gpt()
Error:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at {link} 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: {link}
runfile(‘/Users/joshua.faulkner/.spyder-py3/ChatGPTclone.py’, wdir=‘/Users/joshua.faulkner/.spyder-py3’)
Welcome to ChatGPT Clone! Type ‘exit’ to end the conversation.
You: Hello
An error occurred:
You tried to access openai.ChatCompletion, but this is no longer supported in openai>=1.0.0 - see the README at {link} 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: {link}
OpenAI Python library version: openai 1.56.0
Python Version: Python 3.12.7
Thanks in advance for any help you can give me.