Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在chatbot python flask中返回空响应?_Python_Chatterbot - Fatal编程技术网

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

如何在chatbot python flask中返回空响应?,python,chatterbot,Python,Chatterbot,当我搜索一些不可用的问题时,如何获得空响应 如果问题可用,则应返回正确答案 from chatterbot import ChatBot from chatterbot.trainers import ListTrainer chatterbot = ChatBot("Training Example") chatterbot.set_trainer(ListTrainer) chatterbot.train([ "Hi there!", "Hello", ]) chatt

当我搜索一些不可用的问题时,如何获得空响应

如果问题可用,则应返回正确答案

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
如果无法以较高的置信度确定响应,则可用于返回默认响应。 将阈值设置为响应的最小置信度分数。如果置信度小于此阈值,它将返回默认响应。 使用LowConfidenceAdapter更新的代码:

输出:


@基兰,如果答案有帮助,请接受并投票表决我还有一个问题,关于我们在chatbot中请求问题时如何获得多个响应?请随意创建另一个包含问题详细信息的问题。在Stackoverflow中,不建议在一个查询中询问和回答多个问题:。
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