我读了Sumit Raj写的一本书,书名为“用Python构建聊天机器人:使用自然语言处理和机器学习”,并遵循书中编写的代码。然后我得到了一个如何在线培训对话的示例代码,但后来我发现该代码已被弃用。代码如下:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core import utils, train
from rasa_core.training import online
from rasa_core.interpreter import NaturalLanguageInterpreter
logger = logging.getLogger(__name__)
def train_agent(interpreter):
return train.train_dialog_model(domain_file="horoscope_domain.yml",
stories_file="data/stories.md", output_path="models/dialog", nlu_model_path=interpreter,
endpoints="endpoints.yml", max_history=2, kwargs={"batch_size": 50,"epochs": 200,
"max_training_samples": 300 })
if __name__ == '__main__':
utils.configure_colored_logging(loglevel="DEBUG")
nlu_model_path = "./models/nlu/default/horoscopebot" interpreter =
NaturalLanguageInterpreter.create(nlu_model_path) agent = train_agent(interpreter)
online.serve_agent(agent)
那么结果是
ImportError: cannot import name ‘online’ from ‘rasa_core.training’
请告诉我最新版本的代码是什么样子的。当我检查时,我使用rasa nlu 0.15.1版本
非常感谢你的帮助
我强烈建议您使用最新版本,即2.0版
自从您使用的版本以来,Rasa已经从python库演变为python应用程序,并具有强大的命令行界面
现在,您可以使用以下命令从命令行训练bot:
您可以使用以下命令测试bot:
然后你用命令与机器人对话:
如果您确实喜欢使用Rasa作为库,您可以找到培训、测试和维护的方法;在using Rasa with Jupyter Notebook文档中聊天
相关问题 更多 >
编程相关推荐