2

在创建 Python Chatterbot 实例时,我收到了“unrecognizedInputFormatException”。我正在使用基于此处发布的示例的代码。这是代码:

from chatterbot import ChatBot


def main():
    from chatterbot.training.trainers import ChatterBotCorpusTrainer
    # create a new instance of a chatbot
    bot = ChatBot("proactive_response1",
              storage_adapter="chatterbot.adapters.storage.JsonDatabaseAdapter",
              logic_adapters=["chatterbot.adapters.logic.ClosestMatchAdapter"],
              input_adapter="chatterbot.adapters.input.VariableInputTypeAdapter",
              output_adapter="chatterbot.adapters.output.OutputFormatAdapter",
              output_format='text',
              database="../database.db"
              )

# set up machine learning training
    bot.set_trainer(ChatterBotCorpusTrainer)
    bot.train("chatterbot.corpus.english.proactive_corpus.proactive_response1")

print('Welcome , I\'m theProActive Response Bot, how are you today?')

while True:
    try:
        bot_input = bot.get_response(None)
        print(bot_input)

    # Press ctrl-c or ctrl-d on the keyboard to exit
    except (KeyboardInterrupt, EOFError, SystemExit):
        break


main()

这是堆栈跟踪:

    Traceback (most recent call last):
    Welcome , I'm theProActive Response Bot, how are you today?
 File "C:/Users/brohj_000/PycharmProjects/chatterbot/chatbot        /__init__.py", line 32, in <module>
    main()
 File "C:/Users/brohj_000/PycharmProjects/chatterbot/chatbot/__init__.py",   line 24, in main
   bot_input = bot.get_response(None)
File "C:\Users\brohj_000\AppData\Local\Programs\Python\Python35-32\lib\site-packages\chatterbot\chatterbot.py", line 133, in get_response
input_statement = self.input.process_input(input_item)
File "C:\Users\brohj_000\AppData\Local\Programs\Python\Python35-32\lib\site-packages\chatterbot\adapters\input\variable_input_type_adapter.py", line 39, in process_input
input_type = self.detect_type(statement)
File "C:\Users\brohj_000\AppData\Local\Programs\Python\Python35-32\lib\site-packages\chatterbot\adapters\input\variable_input_type_adapter.py", line 34, in detect_type
input_type
Chatterbot.adapters.input.variable_input_type_adapter.UnrecognizedInputFormatException: "The type <class 'NoneType'> is not recognized as a valid input type."

进程以退出代码 1 结束

4

1 回答 1

0

我相信你可以尝试更换

bot.get_response(None)

bot.get_response(user_input)

“user_input”变量可以提前定义

于 2020-09-15T13:40:58.450 回答