Replies: 1 comment
-
| answer is in Your message. You use example from the old version of openai library. method openai.ChatCompletion is deprecated and now its client.chat.completions.create. | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Data science student here trying to create different projects in order to get more experince in my resume, but having some trouble with making my chatbot that uses chat GPT. I tried reading the readme file I was directed to, but being a beginner with AI, I was quickly overwhelmed and didn't know what to do. Can someone help me please?
The code is:
import openai
openai.api_key = 'sk....'
def chat_with_gpt(prompt):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo", # or "gpt-4"
messages=[{"role": "user", "content": prompt}]
)
return response['choices'][0]['message']['content'].strip()
while True:
user_input = input("You: ")
if user_input.lower() in ["quit", "exit", "bye"]:
print("Chatbot: Goodbye!")
break
response = chat_with_gpt(user_input)
print(f"Chatbot: {response}")
The error I receive is:
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 migrateto 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.28A detailed migration guide is available here: #742
Beta Was this translation helpful? Give feedback.
All reactions