I am writing a service which let users make their own bot, without coding. They jst have to write training , domain and story file. I want to know how to write forms or something where I can prompt users to fill the slots and the take actions accordingly.
If you want to use forms, you need to write a custom actions as described here. You have to at least implement the methods
If you don’t want to use forms, you can created an intent per slot you want to fill. For example, you would have a story like
* greet - utter_greet * restaurant_search - utter_ask_cuisine * enter_cuisine - utter_ask_people * enter_people ...
restaurant_search would trigger the “form”. You will ask step by step what you want to know (e.g.
utter_ask_people) and collect the data from the user (e.g.
enter_people). The training examples for the intents like
enter_cuisine should have the entities set. You also need to think about how to handle unhappy paths, e.g. what happens if the user is filling all slots in one utterance or if he is asking a completely different question in the middle of the conversation.
As this is very tedious, I highly recommend to use forms.
Can I auto-generate these code [
required_slots , and
submit .] somehow to make my service generic?
Maybe. We don’t have anything for that, so you need to write something on your own. Do you want to generate it from the stories, nlu data? I guess, you need some more input to generate it. E.g. from the stories/nlu data it will not be clear what the requested slots are needed and what to do once the form completed (=
submit). However, you can definitely generate the simple form action as soon as you know the required slots, the name and the template to utter once the form is finished. Maybe you can write a short script for that.
I am not planning to use RASA for completion of actions. Just want to take inputs from the users(slots). And know if intent is ready for fulfillment so basically on submit want to inform caller that all slots has been filled and caller can take further actions. And yes I am planning to generate FormAction class using story.md and domain.yml.
I would recommend you to see @khryniewicz’s MetaForm. He is trying to generate FormAction class code with simple YAML syntax.
Forms are like any other Actions. Every action needs to have a name. The name is used to find the correct action class in the end.
Right now my
actions.py looks something like that:
from rasa_metaform import MetaFormAction class FooForm(MetaFormAction, files_path="forms/foo"): pass if __name__ == "__main__": FooForm.update_domain()
I plan to do this part automatically based on the
forms directory and declare a form class for each
__main__ has to be called before training, otherwise action server will complain about missing slots in
You mean if I the name of the form and class is different it won’t work rt? I mean if change the name of the form class from RestaurantForm-> to RestranteForm it wont work?
No. The name of the form action class can differ from the name defined in the method
name. So, every action, e.g. also form actions, needs to implement a method called name. E.g.
def name(self) -> Text: return "<your-action-name>"
The name you define in that method should also appear in the domain file. When predicting the next action, we predict the name of the next action. The name is then used to find the actual action class. As forms are also actions, the same process applies to forms. Does that clarify things?
Thanks, That make sense. But if we have multiple actions then we have to write multiple classes rt?
What do you mean by multiple actions?
Szenario 1: The user is saying something and the bot needs to do three things as a reaction to that utterance. Those three things only happen after this utterance. -> In this case you can do all three things in one action class.
Szenario 2: The user is saying something and the bot needs to do three things as a reaction to that utterance. However, the second thing the bot needs to do also happens after some other utterances. -> You should write two action classes, so that you can reuse the one action at different places.