0

当我开始研究 chatterbot API 时,它的结果经常出现,但逐渐地它的响应变得一天比一天延迟。现在需要大约 2 分钟来响应一个简单的“你好”消息。这不是代码的问题。问题是别的。谁能帮我这个?

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
bot = ChatBot(
    'Norman',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    input_adapter='chatterbot.input.TerminalAdapter',
    output_adapter='chatterbot.output.TerminalAdapter',
    logic_adapters=[
        'chatterbot.logic.MathematicalEvaluation',
        'chatterbot.logic.TimeLogicAdapter'
    ],
    database='./db.sqlite3'
)
bot.set_trainer(ListTrainer)
bot.train([
    'How are you?',
    'I am good.',
    'That is good to hear.',
    'Thank you',
    'You are welcome.'
])

while True:
    try:
        your_input = input("You: ")
        bot_output = bot.get_response(your_input)
        print(bot_output)

    except(KeyboardInterrupt, EOFError, SystemExit):
        break
4

1 回答 1

1

问题是代码正在使用终端输入适配器。
根据文档

The input terminal adapter allows a user to type into their terminal to communicate with the chat bot.

所以它基本上是用来从终端获取输入的。
该代码还尝试使用 input() (在 while 循环内)获取手动用户输入。这会使处理速度变慢。
通过删除终端适配器作为输入适配器可以解决这个问题。

于 2018-07-03T09:17:15.180 回答