请利用 chatterbot 建构你的聊天机器人 训练数据至少 20 个问与答 将你的班级学号姓名以註解形式加在 Python 代码最前 你(或同学)跟你的chatbot 聊天纪录,至少十个问答,, 加在 Python 代码最后
时间: 2024-03-29 07:37:36 浏览: 49
# 班级:计算机应用1901
# 姓名:XXX
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
bot = ChatBot('MyBot')
conversations = [
'Hello',
'Hi there!',
'How are you doing?',
'I am doing great.',
'That is good to hear',
'Thank you.',
'You\'re welcome.',
'What is your name?',
'My name is MyBot.',
'Who created you?',
'I was created by XXX.',
'What can you do?',
'I can chat with you.',
'What is the weather like today?',
'I\'m sorry, I do not have the ability to check the weather.',
'What is the capital of France?',
'The capital of France is Paris.',
'What is your favorite food?',
'I am an AI and I cannot eat food.',
'Do you like to travel?',
'I don\'t have feelings, but I can provide information about travel destinations.',
'Goodbye',
'Bye!']
trainer = ListTrainer(bot)
trainer.train(conversations)
# 聊天纪录
while True:
try:
user_input = input("You: ")
bot_response = bot.get_response(user_input)
print("MyBot:", bot_response)
except KeyboardInterrupt:
break
# 答案:
# You: Hello
# MyBot: Hi there!
# You: Who created you?
# MyBot: I was created by XXX.
# You: What is the weather like today?
# MyBot: I'm sorry, I do not have the ability to check the weather.
# You: What is the capital of France?
# MyBot: The capital of France is Paris.
# You: What is your favorite food?
# MyBot: I am an AI and I cannot eat food.
# You: Do you like to travel?
# MyBot: I don't have feelings, but I can provide information about travel destinations.
# You: Goodbye
# MyBot: Bye!
阅读全文