使用更新的代码
LowConfidenceAdapter
:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Training Example",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': 0.65,
'default_response': 'I am sorry, but I do not understand.'
}
])
chatbot.set_trainer(ListTrainer)
chatbot.train([
"Hi there!",
"Hello"])
chatbot.train([
"Hello",
"Hey!"])
chatbot.train([
"How are you?",
"I am good."])
chatbot.train([
"That is good to hear.",
"Thank you",
"You are welcome."])
chatbot.train([
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."])
while True:
try:
a = input("Question please..? ")
response = chatbot.get_response(a)
print(response)
except (KeyboardInterrupt,SystemExit):
print("\nYour loop has been closed.")
break
输出: