How to link NLU and domain files which is stored in DB with rasa agent

Hi All,

I am new to rasa development. I want to load my nlu.yml, story.yml and domain.yml from DB to train the rasa bot. Can anybody please help me with this?

Thanks in Advance.

There’s no built-in way for this in Rasa. What you can do is write a script that downloads the database, convert the files to YAML, and train the bot.

Hi @ChrisRahme thank you for your reply. Can you please tell me in which file I have to write that script in rasa agent?. And it’s more helpful to me if you share some sample script code.

Thanks in Advance

This would be a script unrelated to Rasa, you can put it anywhere. I don’t have such a script since I don’t pull my data from a database, but since it’s unrelated to Rasa, you can do it any way you want in any language you want.

Of course, the output directory should have a particular format:

├── actions
│   ├──
│   └──
├── config.yml
├── credentials.yml
├── data
│   ├── nlu.yml
│   ├── rules.yml
│   └── stories.yml
├── domain.yml
├── endpoints.yml
├── models
│   └── <timestamp>.tar.gz
└── tests
   └── test_stories.yml

as well as the training data format, which you can see here.

Just write any code that pulls from a database with the format you want, as long as you transform the data into the correct YAML format. To be sure the format is correct, you can use the command rasa data validate.

Hi @ChrisRahme thank you for your quick reply. I will try to implement how you have explained. I have checked Custom Importer(TrainingDataImporter) in rasa documentation. Can I use the below code to load nlu, domain and config files from different location by specifying the file path? def __init__( self, config_file: Optional[Text] = None, domain_path: Optional[Text] = None, training_data_paths: Optional[Union[List[Text], Text]] = None, **kwargs: Dict ): And can you please tell me in which file, I need to write this TrainingDataImporter code?

Thanks in Advance.

Ohhh I completely forgot about that! Sorry, but I have no information other than what’s in here.

Hi @ChrisRahme, Thanks for your reply. I have checked [ TrainingDataImporter] (Training Data Importers). But I don’t know in which file I have to write that code and how to run that in my rasa agent. if you guide me on this then it’s more helpful to me.

Thanks in Advance.

I think you can just put your file at the root of the chatbot’s directory, and then, in your config.yml, do this:

- name: "CustomImporter" <-- Name of your class
- name: "RasaFileImporter"

You can also read the blog post here, it will help!

Hi @ChrisRahme, Thanks a lot for your reply. I have tried. But I am getting errors while running rasa train.

Error:- InvalidDomain: No domain file was specified. Please specify a path to a valid domain file.

And I have written my code like below,

  def __init__(
    config_file: Optional[Text] = 'D:/rasaagent/config.yml',
    domain_path: Optional[Text] = **'D:/rasaagent/domain.yml',**
    training_data_paths: Optional[Union[List[Text], Text]] = 'D:/rasaagent/data/nlu.yml',
    **kwargs: Dict

Can you please tell me what I am doing wrong while specifying the file path in my training data importer code?

Thanks in Advance.

Try to set the paths as config.yml and domain.yml only, without D:/rasaagent/.

Maybe you should even leave them as None, since config.yml and domain.yml will be taken as default values unless specified otherwise on the command line interface.

Try both of these because I’m not sure anyway.