Print example from intent

Hi there,

Is there any way I could print the first example of a specific intent, as defined in the nlu.yml file?

nlu:
- intent: cannot_login
  examples: |
    - I cannot login
    - How login works
    - How can I login?

I want to print “I cannot login”.

Thanks in advance

1 Like

Where do you want to do that? In a custom action?

If yes, you can just read the file:

import yaml

with open('../data/nlu.yml',' r') as file:
    nlu = yaml.load(file, Loader = yaml.FullLoader)
    examples = []
    example = ''

    for intent in nlu:
        if intent['intent'] == 'cannot_login':
            examples = intent['examples']

    if len(examples) > 0:
        example = examples.split('-')[1]

    print(example)

Cheers @ChrisRahme. Indeed I need this a custom action. to be honest I thought that Rasa would have a specific command/ default action to perform this. I should have thought to read the file earlier… Let me check and revert.

1 Like

Yeah, since you can read the domain in a custom action (the domain variable`), it would have made sense to be able to do so for the NLU files. But oh well :joy:

1 Like