Create Custom nlu, rules,story files

hi i am new in rasa and i have built a basic FAQ chatbot but now i need to make all the things dynamic i have already read this blog Customize how Rasa imports training data | The Rasa Blog | Rasa But I don’t understand in which format we need to create a csv file to import and how to set the path of the file. Please help me.

Hi @preeti ,

The blog post you read is for Rasa 1.x and seems quite outdated…
If you need to load a CSV file to get NLU data into a Rasa-style YAML file, you can:

  • Prep a CSV with two columns: intent and text
  • Modify the script below as necessary:
from typing import Text
import pandas
import rasa
from rasa.shared.nlu.training_data.formats.rasa_yaml import RasaYAMLWriter
from rasa.shared.nlu.training_data.message import Message
from rasa.shared.nlu.training_data.training_data import TrainingData

def write_nlu_file(df: pandas.DataFrame, filepath: Text):
    training_data = TrainingData(
        [Message({'intent': row.intent, 'text': row.text})
         for row in df.itertuples()]
    )
    RasaYAMLWriter().dump(target=filepath, training_data=training_data)
    return None

df = pandas.read_csv('path/to/the/input/file.csv')
write_nlu(df, 'path/to/the/output/file.yml')

Hope that helps

1 Like

@E-dC thank you for the reply. Can you tell me when should I call this function?

Hi @preeti,

That depends a lot on your use case. The script above will only do one thing: converting a CSV containing your training examples to a YAML Rasa NLU file.

What is the shape of your data now? Do you have stories.yml, nlu.yml, etc? What do you mean by “making all the things dynamic”?

Hi @E-dC ,

In my chatbot I used to hardcode nlu.yml, stories.yml files to design, but I want clients to add their question and answer by frontend so I want to make these pages dynamic. is it possible??