chatterbot花了很长时间才能回复

时间:2020-05-26 23:51:44

标签: python artificial-intelligence bots chatterbot repl.it

我有一个示例代码。在repl.it上运行良好,就像几秒钟后的响应一样。但是,过了一段时间,它在大约1-3分钟后开始返回响应,甚至更多甚至没有。
在运行重新启动时,突然开始发生这种情况。我尝试重置数据库。那没有帮助。然后,我尝试制作一个新的副本。那也没有帮助

这是我的代码:

from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
import logging


'''
This is an example showing how to train a chat bot using the
ChatterBot Corpus of conversation dialog.
'''

# Enable info level logging
logging.basicConfig(level=logging.INFO)

chatbot = ChatBot('Example Bot')

# Start by training our bot with the ChatterBot corpus data
chatbot.set_trainer(ChatterBotCorpusTrainer)

chatbot.train(
    'chatterbot.corpus.english'
)
while True:
    inp = input("=> ")
    print(chatbot.get_response(inp))

它开始工作正常,但卡在:

/opt/virtualenvs/python3/lib/python3.8/site-packages/chatterbot/storage/jsonfile.py:24: UnsuitableForProductionWarning:The JsonFileStorageAdapter is not recommended for production environments.
warnings.warn(
=> Hello
INFO:chatterbot.adapters:Recieved input statement: Hello
INFO:chatterbot.adapters:"Hello" is a known statement

以下是repl链接:https://repl.it/@blackskull12/chatterbottest#main.py


如果我替换:

chatbot.set_trainer(ChatterBotCorpusTrainer)

chatbot.train(
    'chatterbot.corpus.english'
)

收件人:

trainer = ChatterBotCorpusTrainer(chatbot)

trainer.train(
    'chatterbot.corpus.english'
)

此更改在我的PC上正常运行。但是给出关于repl的错误。 ChatBot has no atribute 'find'

我不知道在哪里继续。有人可以帮助我,让我的机器人重获新生吗?

1 个答案:

答案 0 :(得分:0)

TDRL; 我不确定为什么它会“卡在”那里,但是如果它在您的PC上工作正常,那么问题可能出在Repl.it上的chatterbox版本是旧版本(尽管repl可能由于权限问题或无法正常工作)性能检查/限制)。

“发现”错误

如以下github issue tracker所示:

find属性最近在1.0.0a1版本中被删除,但是我不确定为什么您会从0.8.7版本中得到此消息。

您可以在PC上降级到以前的版本(以匹配repl.it中的版本) 1

pip3 install chatterbot==0.8.6

或重新安装chatterbox并将其升级到1.0.0a1以上,以使用chatbot.set_trainer(ChatterBotCorpusTrainer))方法。在您的PC上应该是:

sudo pip3 uninstall chatterbot
sudo pip3 install chatterbot --no-cache-dir

对于Repl.it: 2 根据文档,他们有一个GUI package manager you can use to install a package

点击“包装盒”符号:

picture of adding package_box on left top

搜索并单击该程序包,然后单击加号将其添加

Then click on the plus sign

应将其显示为安装版本1.1...。

Shows dependency installing

要检查您在家用台式机上使用的版本并复制,请使用以下命令(带有您的Python别名):

python3 -m chatterbot --version

1:我不建议您这样做,因为它可以在您的PC上运行,因此升级似乎是更可能的解决方案。

2:我不建议为此使用Repl.it,因为要处理一个小repl太多了-在我的系统中安装9个依赖项花费了很长时间,并且repl.it有多个CPU如人们期望的那样到位。我也有一个付费帐户,以便给我不同的权限。如果不起作用,请联系其客户服务。