RASA - OR statements

petr7555

Petr Janik

Posted on May 28, 2021

RASA - OR statements

Another way to write shorter stories, or to handle multiple intents the same way, is to use an or statement.

For example, if you ask the user to confirm something, and you want to treat the affirm and thankyou intents in the same way. The story below will be converted into two stories at the training time:



# stories.yml
# ... previous content ...
  - story: confirm by affirm or thankyou
    steps:
      - intent: confirm
      - action: utter_ask_confirm
      - or:
          - intent: affirm
          - intent: thankyou
      - action: utter_confirmed


Enter fullscreen mode Exit fullscreen mode

For this example to work, apart from the code we have from the previous chapters, I have created two new intents:



# data/nlu.yml
# ... previous content ...
  - intent: confirm
    examples: |
      - can I confirm
      - I want to confirm
      - I would like to confirm that
  - intent: thankyou
    examples: |
      - thank you
      - thanks
      - thanks a lot
      - thank you so much!


Enter fullscreen mode Exit fullscreen mode

and added them to domain.yml:



# domain.yml
# ... previous content ...
intents:
  # ... previous intents ...
  - confirm
  - thankyou


Enter fullscreen mode Exit fullscreen mode

We need the chatbot's responses as well:



# domain.yml
# ... previous content ...
  utter_ask_confirm:
    - text: Do you really want to confirm that?
  utter_confirmed:
    - text: Confirmed.


Enter fullscreen mode Exit fullscreen mode

Let's see this in action:

Conversation with OR first

Conversation with OR second

You can learn more about OR statements in the documentation.

In the next chapter, we will look at slots in detail.

Repository for this tutorial:

You can checkout the state of the repository at the end of this tutorial by running:



git clone --branch 14-or-statements git@github.com:petr7555/rasa-dev-tutorial.git


Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
petr7555
Petr Janik

Posted on May 28, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

RASA - Session persistence
rasa RASA - Session persistence

July 28, 2022

RASA - Socket.IO integration
rasa RASA - Socket.IO integration

August 30, 2021

RASA - Google Chat integration
rasa RASA - Google Chat integration

August 9, 2021

RASA - Synonyms
rasa RASA - Synonyms

August 7, 2021