我正在编写一个聊天机器人,我想在输入 “谢谢” 后中断,但我不知道该怎么做。 这是代码:
from nltk.chat.util import Chat, reflections
words =[
['(hi|hey|hola|goodmorning|hay)', ['hello,how can i help you?']],
['(order|can i order)',['what size']],
['(my size is (.*))',['%1 is avalable'+' what color?']],
['(my color is (.*))',['%1 is avalable']],
['(how much)',['price is 300le' + ' send your information ']],
['(my information is)',['order placed and will be delivered in 3 working days']],
['(thanks)',['you\'re welcome']],
]
chat = Chat(words, reflections)
chat.converse()
我尝试使用
while
循环但它没有用,也尝试在代码末尾使用 break
也没有用。
converse
方法有一个quit
参数,它表示结束对话的输入。请注意,机器人仍会响应该输入,然后结束对话。
所以在你的情况下,你只需要添加:
chat.converse(quit="thanks")