无法加载组件 rasa
Failed to load the component rasa
我将 rasa 用作 python 库。这是我的目录结构
chat-bot/
bots/
models/
rasa/
my-model.tar.gz
rasa_bot.py
projects/
rasa/
actions/
components/
data_processing.py
data/
nlu.yml
stories.yml
config.yml
domain.yml
这是我的 config.yml
language: en
pipeline:
- name: components.data_processing.DataProcessingComponent
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
这就是我训练模型的方式
rasa train --fixed-model-name my-model --out ../../bots/models/rasa/
在 rasa_bot.py
这就是我加载模型的方式
model = RasaBot.__get_model("my-model.tar.gz")
# get the agent from model and action server
ACTION_ENDPOINT = os.getenv('ACTION_ENDPOINT')
agent = Agent.load(
model,
action_endpoint=EndpointConfig(ACTION_ENDPOINT)
)
和__get_model
方法
@staticmethod
def __get_model(modelName):
MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
return '{}/{}'.format(MODEL_LOCATION, modelName)
但这显示了这个错误
Failed to load the component 'components.data_processing.DataProcessingComponent'. Failed to find module 'components.data_processing'. Either your pipeline configuration contains an error or the module you are trying to import is broken (e.g. the module is trying to import a package that is not installed). Traceback (most recent call last):
File "c:\chat-bot\env37\lib\site-packages\rasa\nlu\registry.py", line 121, in get_component_class
return rasa.shared.utils.common.class_from_module_path(component_name)
File "c:\chat-bot\env37\lib\site-packages\rasa\shared\utils\common.py", line 37, in class_from_module_path
m = importlib.import_module(module_name)
File "C:\Users\sgarg\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'components'
您可以将一个空的 __init__.py
文件添加到您的 components
文件夹吗?这样文件夹就会被检测为 Python 模块。
请注意,我假设您是 运行 来自此处 projects/rasa
文件夹的 rasa train
命令。
在我的 rasa_bot.py
中,我添加了
RASA_DIR = os.getcwd() + "//projects//rasa"
sys.path.append(RASA_DIR)
成功了
我将 rasa 用作 python 库。这是我的目录结构
chat-bot/
bots/
models/
rasa/
my-model.tar.gz
rasa_bot.py
projects/
rasa/
actions/
components/
data_processing.py
data/
nlu.yml
stories.yml
config.yml
domain.yml
这是我的 config.yml
language: en
pipeline:
- name: components.data_processing.DataProcessingComponent
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
这就是我训练模型的方式
rasa train --fixed-model-name my-model --out ../../bots/models/rasa/
在 rasa_bot.py
这就是我加载模型的方式
model = RasaBot.__get_model("my-model.tar.gz")
# get the agent from model and action server
ACTION_ENDPOINT = os.getenv('ACTION_ENDPOINT')
agent = Agent.load(
model,
action_endpoint=EndpointConfig(ACTION_ENDPOINT)
)
和__get_model
方法
@staticmethod
def __get_model(modelName):
MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
return '{}/{}'.format(MODEL_LOCATION, modelName)
但这显示了这个错误
Failed to load the component 'components.data_processing.DataProcessingComponent'. Failed to find module 'components.data_processing'. Either your pipeline configuration contains an error or the module you are trying to import is broken (e.g. the module is trying to import a package that is not installed). Traceback (most recent call last):
File "c:\chat-bot\env37\lib\site-packages\rasa\nlu\registry.py", line 121, in get_component_class
return rasa.shared.utils.common.class_from_module_path(component_name)
File "c:\chat-bot\env37\lib\site-packages\rasa\shared\utils\common.py", line 37, in class_from_module_path
m = importlib.import_module(module_name)
File "C:\Users\sgarg\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'components'
您可以将一个空的 __init__.py
文件添加到您的 components
文件夹吗?这样文件夹就会被检测为 Python 模块。
请注意,我假设您是 运行 来自此处 projects/rasa
文件夹的 rasa train
命令。
在我的 rasa_bot.py
中,我添加了
RASA_DIR = os.getcwd() + "//projects//rasa"
sys.path.append(RASA_DIR)
成功了