Hello,
I would like to know if it is possible to avoid the form validation when a slot is being defined in a custom action through SlotSet(‘slot_name’, value). I don’t know if this is very clear, so here’s a concrete example:
#rules.yml
version: "2.0"
rules:
- rule: just a test
steps:
- intent: test
- action: action_check
- action: info_form
- active_loop: null
#domain.yml
session_config:
session_expiration_time: 60
carry_over_slots_to_new_session: true
intents:
- hi
- test
- give_slot_2:
use_entities:
- slot_2
entities:
- slot_1
- slot_2
slots:
slot_1:
type: any
influence_conversation: false
slot_2:
type: any
influence_conversation: false
responses:
utter_ask_slot_2:
- text: What's the slot_2 ?
utter_bye:
- text: bye
actions:
- validate_info_form
- action_check
forms:
info_form:
slot_2:
- entity: slot_2
intent: give_slot_2
type: from_entity
slot_1:
- entity: slot_1
type: from_entity
#actions.py
from typing import Any, Text, Dict, List, Union
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.forms import FormAction
from rasa_sdk.events import SlotSet
class ValidateInfoForm(Action):
def name(self) -> Text:
return "validate_info_form"
def run(self, dispatcher, tracker, domain):
required_slots = ["slot_1", "slot_2"]
for slot_name in required_slots:
if tracker.slots.get(slot_name) is None:
print("This line is printed twice :(")
return []
# All slots are filled.
return [SlotSet("requested_slot", None)]
class Check(Action):
def name(self) -> Text:
return "action_check"
def run(self, dispatcher, tracker, domain):
return [SlotSet("slot_1", "abcde")]
This code leads to the following conversation:
$ rasa shell
2020-11-15 15:16:18 INFO root - Connecting to channel 'cmdline' which was specified by the '--connector' argument.
Any other channels will be ignored. To connect to all given channels, omit the '--connector' argument.
2020-11-15 15:16:18 INFO root - Starting Rasa server on http://localhost:5005
2020-11-15 15:16:23 INFO root - Rasa server is up and running.
Bot loaded. Type a message and press enter (use '/stop' to exit):
Your input -> this is a test
What's the slot_2 ?
Your input ->
$ rasa run actions
2020-11-15 15:15:38 INFO rasa_sdk.endpoint - Starting action endpoint server...
2020-11-15 15:15:38 INFO rasa_sdk.executor - Registered function for 'validate_info_form'.
2020-11-15 15:15:38 INFO rasa_sdk.executor - Registered function for 'action_check'.
2020-11-15 15:15:38 INFO rasa_sdk.endpoint - Action endpoint is up and running on http://localhost:5055
This line is printed twice :(
This line is printed twice :(
The first call to the run() method of the ValidateInfoForm class is made because SlotSet(“slot_1”, “abcde”) is returned in the Check class. Then, it is called again because of the line “- action: info_form” in my rule. Well, at least that’s what I understood, I could be wrong,
So, is there a way to set the slot “slot_1” in my Check class without triggering the validation ?
Thank’s in advance