Introduction to Forms
In this segment we will teach you how to configure Rasa Forms. Having a form has many benefits, but the main one is that it allows us to add constraints to how we collect slot values.
Video
Code
There are some important changes that we've made to our domain.yml file.
entities:- shirt_size
slots: shirt_size: type: text influence_conversation: true mappings: - type: from_entity entity: shirt_size conditions: - active_loop: shirt_size_form
forms: shirt_size_form: required_slots: - shirt_sizeThe main thing we've added now is the conditions in the slot mappings. This ensures
that we only store the slot information if the user is in an active form.
Rules
In order to make the form work, we need to add some rules to our rules.yml file.
rules:- rule: Activate form steps: - intent: ask_me_anything - action: shirt_size_form - active_loop: shirt_size_form
- rule: Submit form condition: - active_loop: shirt_size_form steps: - action: shirt_size_form - active_loop: null - slot_was_set: - requested_slot: null - action: utter_rememberStories
Again, we also ensure that we have stories available. Here's an example
that's been extracted from a long rasa interactive conversation.
- story: interactive story steps: - intent: greet - action: utter_greet - intent: mood_unhappy - action: utter_cheer_up - action: utter_did_that_help - intent: affirm - action: utter_happy - intent: repeat_shirt_size - action: action_say_shirt_size - intent: ask_me_anything - action: shirt_size_form - active_loop: shirt_size_form - slot_was_set: - requested_slot: shirt_size - slot_was_set: - shirt_size: large - slot_was_set: - requested_slot: null - active_loop: null - action: utter_remember - intent: repeat_shirt_size - action: action_say_shirt_size - intent: mood_unhappy - action: utter_cheer_up - action: utter_did_that_help - intent: affirm - action: utter_happyLinks
Exercises
Try to answer the following questions to test your knowledge.
- Why do we prefer to use conditions in our forms?
- Can you think of a situation where you don't want to use conditions?
- What will happen if the form cannot fill in a slot value?