ImportError:无法从“ rasa_core.training”

时间:2019-11-13 21:53:08

标签: python cmd rasa-core rasa

我正在跟踪一本书中的代码,并在尝试进行在线培训时遇到此错误。

完整错误是:

  

回溯(最近通话最近):     文件“ train_online.py”,第9行,在       从rasa_core.training在线导入   ImportError:无法从'rasa_core.training'(C:\ Users \ Max \ AppData \ Local \ Programs \ Python \ Python37 \ lib \ site-packages \ rasa_core \ training__init __。py)中导入名称'online'

我的代码是:

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 NatraulLanguageInterpreter

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 = NatraulLanguageInterpreter.create(nlu_model_path)
    agent = train_agent(interpreter)
    online.serve_agent(agent)

2 个答案:

答案 0 :(得分:1)

您正在阅读的书可能带有带有过时版本的Rasa库的代码示例。

使用rasa-x安装pip install rasa-x --extra-index-url https://pypi.rasa.com/simple软件包并尝试在Python 3.6解释器中运行from rasa_core.training import online之后,我得到以下警告:

  

UserWarning:“ rasa_core”包已重命名。您应该将导入更改为使用“ rasa.core”。

考虑使用Rasa文档阅读新的Getting Started

答案 1 :(得分:0)

希望对您有所帮助: 删除

from rasa_core.training import online
online.serve_agent(agent)

替换为此

from rasa_core.training import interactive
interactive.run_interactive_learning(agent)