How to return Empty Response in chatbot python-flask?












0














How can I get empty response when I search for some questions which are not available?



If the question is available it should return correct response.



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









share|improve this question





























    0














    How can I get empty response when I search for some questions which are not available?



    If the question is available it should return correct response.



    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









    share|improve this question



























      0












      0








      0







      How can I get empty response when I search for some questions which are not available?



      If the question is available it should return correct response.



      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









      share|improve this question















      How can I get empty response when I search for some questions which are not available?



      If the question is available it should return correct response.



      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 chatterbot






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 14:40









      davidism

      62.2k12157176




      62.2k12157176










      asked Nov 23 '18 at 5:36









      kiran

      62




      62
























          1 Answer
          1






          active

          oldest

          votes


















          1
















          • LowConfidenceAdapter can be used to return a default response if a response can not be determined with a high amount of confidence.

          • Set a threshold value as minimum confidence score of the response. If the confidence is less than this threshold value, it will return the default response.


          Updated code using 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


          Output:



          chatterbot example






          share|improve this answer



















          • 1




            thank you mate this helped me
            – kiran
            Nov 23 '18 at 9:52










          • @kiran, if the answer is helpful, please accept and upvote it. :)
            – arsho
            Nov 23 '18 at 9:53










          • i had another question regarding how to get multiple responses when we request a question in chatbot?
            – kiran
            Nov 26 '18 at 3:16










          • Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
            – arsho
            Nov 26 '18 at 5:21











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441139%2fhow-to-return-empty-response-in-chatbot-python-flask%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1
















          • LowConfidenceAdapter can be used to return a default response if a response can not be determined with a high amount of confidence.

          • Set a threshold value as minimum confidence score of the response. If the confidence is less than this threshold value, it will return the default response.


          Updated code using 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


          Output:



          chatterbot example






          share|improve this answer



















          • 1




            thank you mate this helped me
            – kiran
            Nov 23 '18 at 9:52










          • @kiran, if the answer is helpful, please accept and upvote it. :)
            – arsho
            Nov 23 '18 at 9:53










          • i had another question regarding how to get multiple responses when we request a question in chatbot?
            – kiran
            Nov 26 '18 at 3:16










          • Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
            – arsho
            Nov 26 '18 at 5:21
















          1
















          • LowConfidenceAdapter can be used to return a default response if a response can not be determined with a high amount of confidence.

          • Set a threshold value as minimum confidence score of the response. If the confidence is less than this threshold value, it will return the default response.


          Updated code using 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


          Output:



          chatterbot example






          share|improve this answer



















          • 1




            thank you mate this helped me
            – kiran
            Nov 23 '18 at 9:52










          • @kiran, if the answer is helpful, please accept and upvote it. :)
            – arsho
            Nov 23 '18 at 9:53










          • i had another question regarding how to get multiple responses when we request a question in chatbot?
            – kiran
            Nov 26 '18 at 3:16










          • Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
            – arsho
            Nov 26 '18 at 5:21














          1












          1








          1








          • LowConfidenceAdapter can be used to return a default response if a response can not be determined with a high amount of confidence.

          • Set a threshold value as minimum confidence score of the response. If the confidence is less than this threshold value, it will return the default response.


          Updated code using 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


          Output:



          chatterbot example






          share|improve this answer
















          • LowConfidenceAdapter can be used to return a default response if a response can not be determined with a high amount of confidence.

          • Set a threshold value as minimum confidence score of the response. If the confidence is less than this threshold value, it will return the default response.


          Updated code using 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


          Output:



          chatterbot example







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 9:49

























          answered Nov 23 '18 at 8:54









          arsho

          3,28911531




          3,28911531








          • 1




            thank you mate this helped me
            – kiran
            Nov 23 '18 at 9:52










          • @kiran, if the answer is helpful, please accept and upvote it. :)
            – arsho
            Nov 23 '18 at 9:53










          • i had another question regarding how to get multiple responses when we request a question in chatbot?
            – kiran
            Nov 26 '18 at 3:16










          • Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
            – arsho
            Nov 26 '18 at 5:21














          • 1




            thank you mate this helped me
            – kiran
            Nov 23 '18 at 9:52










          • @kiran, if the answer is helpful, please accept and upvote it. :)
            – arsho
            Nov 23 '18 at 9:53










          • i had another question regarding how to get multiple responses when we request a question in chatbot?
            – kiran
            Nov 26 '18 at 3:16










          • Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
            – arsho
            Nov 26 '18 at 5:21








          1




          1




          thank you mate this helped me
          – kiran
          Nov 23 '18 at 9:52




          thank you mate this helped me
          – kiran
          Nov 23 '18 at 9:52












          @kiran, if the answer is helpful, please accept and upvote it. :)
          – arsho
          Nov 23 '18 at 9:53




          @kiran, if the answer is helpful, please accept and upvote it. :)
          – arsho
          Nov 23 '18 at 9:53












          i had another question regarding how to get multiple responses when we request a question in chatbot?
          – kiran
          Nov 26 '18 at 3:16




          i had another question regarding how to get multiple responses when we request a question in chatbot?
          – kiran
          Nov 26 '18 at 3:16












          Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
          – arsho
          Nov 26 '18 at 5:21




          Please feel free to create another question with question details. It is not preferred in Stackoverflow to ask and answer multiple questions in a single query :).
          – arsho
          Nov 26 '18 at 5:21


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441139%2fhow-to-return-empty-response-in-chatbot-python-flask%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Sphinx de Gizeh

          Dijon

          Guerrita