└── Chatbot.py /Chatbot.py: -------------------------------------------------------------------------------- 1 | import random 2 | from nltk.chat.util import Chat, reflections 3 | # Define patterns and responses 4 | pairs = [ 5 | [ 6 | r"my name is (.*)", 7 | ["Hello %1! How can I help you today?",] 8 | ], 9 | [ 10 | r"what is your name?", 11 | ["You can call me ChatGPT. How can I assist you?",] 12 | ], 13 | [ 14 | r"how are you?", 15 | ["I'm doing well, thank you!", "I'm fine, thanks for asking.",] 16 | ], 17 | [ 18 | r"(.*) (hungry|sleepy)", 19 | ["I'm just a computer program, so I don't feel hunger or sleepiness.",] 20 | ], 21 | [ 22 | r"(.*) age?", 23 | ["I'm just a computer program, I don't have an age.",] 24 | ], 25 | [ 26 | r"what (.*) want?", 27 | ["I'm here to assist you. How can I help you today?",] 28 | ], 29 | [ 30 | r"(.*) created you?", 31 | ["I was created by OpenAI using their GPT-3.5 architecture.",] 32 | ], 33 | [ 34 | r"(.*) (location|city) ?", 35 | ["I exist in the digital realm. I don't have a physical location.",] 36 | ], 37 | [ 38 | r"how can I (.*) help you?", 39 | ["You can ask me questions or tell me what you need assistance with.",] 40 | ], 41 | [ 42 | r"quit", 43 | ["Thank you for chatting with me. Have a great day!", "Goodbye!"] 44 | ], 45 | ] 46 | 47 | # Create a Chat instance 48 | chatbot = Chat(pairs, reflections) 49 | # Start the conversation 50 | print("Hi! I'm your chatbot assistant. How can I help you today?") 51 | while True: 52 | user_input = input("You: ") 53 | if user_input.lower() == 'exit': 54 | break 55 | response = chatbot.respond(user_input) 56 | print("ChatGPT:", response) --------------------------------------------------------------------------------