Advertisement
nicuf

ChatGPT BOT OPEN AI

Feb 23rd, 2024
1,248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import openai
  2.  
  3. openai.api_key = "API-KEY"  # https://platform.openai.com/api-keys
  4.  
  5. def chat_with_gpt(prompt):
  6.     response = openai.completions.create( # Changed
  7.         model="gpt-3.5-turbo-instruct", # Changed
  8.         prompt=prompt,
  9.         max_tokens=150
  10.     )
  11.  
  12.     # Extracting the response
  13.     answer = response.choices[0].text.strip()
  14.     print("Chatbot:", answer)
  15.  
  16. if __name__ == "__main__":
  17.     while True:
  18.         user_input = input("You: ")
  19.         if user_input.lower() in ["quit", "exit", "bye"]:
  20.             break
  21.         chat_with_gpt(user_input)
  22. response = client.completions.create(
  23.   model="gpt-3.5-turbo-instruct",
  24.  
  25. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement