Failed to load the component rasa

I am using rasa as a python library. Here is my directory structure

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

Here is how my config.yml

language: en
pipeline:
  - name: components.data_processing.DataProcessingComponent
  - name: WhitespaceTokenizer
  - name: CountVectorsFeaturizer

and this is how I train the model

rasa train --fixed-model-name my-model --out ../../bots/models/rasa/

And in rasa_bot.py This is how I am loading the model

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)
        )

and __get_model method

@staticmethod
def __get_model(modelName):
    MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
    return '{}/{}'.format(MODEL_LOCATION, modelName)

I am using rasa as a python library. Here is my directory structure

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

Here is how my config.yml

language: en
pipeline:
  - name: components.data_processing.DataProcessingComponent
  - name: WhitespaceTokenizer
  - name: CountVectorsFeaturizer

and this is how I train the model

rasa train --fixed-model-name my-model --out ../../bots/models/rasa/

And in rasa_bot.py This is how I am loading the model

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)
        )

and __get_model method

@staticmethod
def __get_model(modelName):
    MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
    return '{}/{}'.format(MODEL_LOCATION, modelName)

but this is showing this error

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'

@ermarkar To double-check, what command did you run to get this stacktrace? At a quick glance sounds like the path to your component needs to be fixed because components can’t be found; maybe you’re also missing an __init__.py in components?

In my rasa_bot.py , I added

RASA_DIR = os.getcwd() + "//projects//rasa"
sys.path.append(RASA_DIR)

@anca thanks for the answer, I tried adding the __init__.py in components folder, even with the parent folder too, but it did not work, somehow i figured out the solution and answered.

Thanks

1 Like