Hi
How do I set slot values hard? I think the way I do it (see below) is nor correct, since I get warnings (see below). However, the bot seems to work correctly. Maybe it is just a RASA buck. I am working on the latest version rasa==1.6.1. The problem was not there for previous version. Can you spot what I am doing wrong? Or maybe everything is correct?
I want to ask for specific user informations:
- What is your first name?
- What is you last name?
- What is your street name?
- What is your house number?
Therefore I use a custom form
which asks the user to get all these data.
I am not sure, how the value which is given by the user is stored in the slot.
This is what I do:
domain.yml:
intents:
- name
- name_last
- street_name
- house_number
entities:
- name
- name_last
- street_name
- house_number
slots:
name:
type: unfeaturized
name_last:
type: unfeaturized
street_name:
type: unfeaturized
house_number:
type: unfeaturized
actions:
- utter_ask_name
- utter_ask_name_last
- utter_ask_street_name
- utter_ask_house_number
forms:
- authenticate_form
templates:
utter_ask_name:
- text: What is your first name?
buttons:
- title: "FirstName"
payload: "name"
utter_ask_name_last:
- text: What is your last name?
buttons:
- title: "LastName"
payload: "name_last"
actions.py:
class AuthenticateForm(FormAction):
def name(self):
# type: () -> Text
return "authenticate_form"
@staticmethod
def required_slots(tracker):
# type: () -> List[Text]
return ["name", "name_last", "street_name", "house_number"]
def submit(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict]
"""
Define what the form has to do after all required slots are filled
"""
return []
def slot_mappings(self):
# type: () -> Dict[Text: Union[Dict, List[Dict]]]
return {
"name": [self.from_entity(entity="name", not_intent=["chitchat"])],
"name_last": [self.from_entity(entity="name_last", not_intent=["chitchat"])],
"street_name": [self.from_entity(entity="street_name", not_intent=["chitchat"])],
"house_number": [self.from_entity(entity="house_number", not_intent=["chitchat"])]
}
def validate(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict]:
.....
for slot, value in slot_values.items():
if slot == 'name':
if ...:
slot_values[slot] = value
else:
slot_values[slot] = None
if slot == 'street_name':
if ...:
slot_values[slot] = value
else:
slot_values[slot] = None
....
return [SlotSet(slot, value) for slot, value in slot_values.items()]
stories.md:
## story_form_happy_path
- authenticate_form
- form{"name": "authenticate_form"}
- slot{"name": "Sam"}
- slot{"name_last": "Johns"}
- slot{"street_name": "Gartenstrasse"}
- form{"name": null}
This approach works, but I get the following warnings:
UserWarning: Interpreter parsed an intent 'name:' that is not defined in the domain.
UserWarning: Interpreter parsed an intent 'name_last:' that is not defined in the domain.
UserWarning: Interpreter parsed an intent 'street_name:' that is not defined in the domain.
UserWarning: Interpreter parsed an intent 'house_number:' that is not defined in the domain.
This is strange, since these intents are clearly defined in my domain-file. So, how do I set the slot value correctly?