How to parse a yml files of rasa

there are several yml files on rasa i want to load them in to a python script

the naive

import yaml and yaml.load doesn’t seem to work because of the presence of | (pipe)

has anyone found anywork around?

I’m trying to do this to create nlu.yml stories.yml and domain.yml dynamically.

Hi @pvbhanuteja , I have used ruamel for one of my clients. Worked extremely well.

1 Like

Hi @ChikkaUdayaSai Good idea

I have opened rasa source and dug into the libraries and food a quick solution though I agree with @ChikkaUdayaSai suggestion to use ruamel.yaml

Here’s a quick look at my solution to use rasa libraries directly

from rasa.shared.nlu.training_data.formats.rasa_yaml import RasaYAMLReader, RasaYAMLWriter

from rasa.shared.nlu.training_data.message import Message

from rasa.shared.nlu.training_data.training_data import TrainingData

import pickle

import uuid

import yaml

c1 = RasaYAMLReader()

w1 = RasaYAMLWriter()

c2 = RasaYAMLReader()

w2 = RasaYAMLWriter()

td = TrainingData(finaldatalist,{},[],[],{})
f = w1.dump('/home/bhanu/Desktop/upwork/newKB/bhanu_ws/rasa_app/data/nlu.yml',td)

#make use of TrainingData class properly to convert data

You only require all those classes to change nlu.yml data other files can be easily tweaked usihng pyyaml