Py学习  »  Python

如何在chatbot python flask中返回空响应?

kiran • 7 年前 • 569 次点击  

当我搜索一些不可用的问题时,如何得到空的回答?

如果问题是可用的,它应该返回正确的回答。

from chatterbot import ChatBot

from chatterbot.trainers import ListTrainer
chatterbot = ChatBot("Training Example")
chatterbot.set_trainer(ListTrainer)

chatterbot.train([
    "Hi there!",
    "Hello",
])

chatterbot.train([
    "Greetings!",
    "Hello",
])

chatbot.train(["Greetings!","Hello",])

chatbot.train(["How are you?","I am good.","That is good to 
hear.","Thank you","You are welcome.",])

while True:

try:

  a = input("question please..? ")

  response = chatterbot.get_response(a)

  print(response)

except (KeyboardInterrupt,SystemExit):

  print("your loop has been closed: ")

  break
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43013
文章 [ 1 ]  |  最新文章 7 年前