Text Slots

Rasa slots can be filled by entities, but they can also store information from other sources. In this lesson we will fill slot values that are based on text.

Video


Code

We're going to use a form again so we'll need rules in our rules.yml file.

rules:
- rule: Activate form
steps:
- intent: request_names
- action: name_form
- active_loop: name_form
- rule: Submit form
condition:
- active_loop: name_form
steps:
- action: name_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: utter_submit
- action: utter_slots_values

We're referring to a name_form here, which is defined in our domain.yml file.

forms:
name_form:
required_slots:
- first_name
- last_name
slots:
first_name:
type: text
influence_conversation: true
mappings:
- type: from_text
conditions:
- active_loop: name_form
requested_slot: first_name
last_name:
type: text
influence_conversation: true
mappings:
- type: from_text
conditions:
- active_loop: name_form
requested_slot: last_name

Because we're using from_text mappings, we can fill slots based on text. It's especially important that these slots have a condition attached to them, so that they can be filled only when the user is in the form.

This domain.yml also contains some responses that help the form ask questions.

responses
utter_ask_first_name:
- text: What is your first name?
utter_ask_last_name:
- text: So {first_name}, what is your last name?
utter_submit:
- text: Ok. Thanks!
utter_slots_values:
- text: I will remember that your name is {first_name} {last_name}!

Because we're not using entities, we only need a single extra intent in our nlu.yml file in order to trigger the form.

nlu:
- intent: request_names
examples: |
- i want to give you my name
- give name
- you need to know my name
- do you know my name?

Links

Exercises

Try to answer the following questions to test your knowledge.

  1. What is the naming convention for a response that asks for a slot value?
  2. Let's say you want to use the first name to ask for a last name. Do you need to write a custom action for this use-case?

2016-2024 © Rasa.