import openai
openai.api_key = "sk-dLwvqqqq"
class Chatbot:
def __init__(self):
self.messages = []
def ask_question(self, question):
self.messages.append({"role": "user", "content": question})
response = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=self.messages)
answer = response.choices[0].message['content']
self.messages.append({"role": "assistant", "content": answer})
return answer
# Main loop for chatting
chatbot = Chatbot()
print("Chatbot: Hello! How can I assist you today?")
while True:
user_input = input("You: ")
if user_input.lower() == 'exit':
print("Chatbot: Goodbye! Have a great day!")
break
response = chatbot.ask_question(user_input)
print("Chatbot:", response)
No hay comentarios:
Publicar un comentario