Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add helper function extract slots to validate #238

Closed
wochinge opened this issue Jul 17, 2020 · 0 comments · Fixed by #253
Closed

add helper function extract slots to validate #238

wochinge opened this issue Jul 17, 2020 · 0 comments · Fixed by #253
Assignees
Labels
area:rasa-sdk 🧑‍💻 Everything that touches our python Rasa SDK priority:normal Impacts some users. Prevents using a secondary feature normally. type:enhancement ✨ Additions of new features or changes to existing ones, should be doable in a single PR

Comments

@wochinge
Copy link
Contributor

With the changes of the RulePolicy, form slots are validated in one custom action action_validate_{form_name}. Any slots which extracted by the form action and have to be validated are appended to the tracker as SlotSet events. So whenever we trigger action_validate_{form_name} from the form action we will send a tracker, which has the following events

tracker_events = tracker_events_from_conversation + [ActionExecuted(form_name)] + slot_set_events_for_newly_extracted_slots

We need to make it easier to validate the newly extracted slots (instead of having users to go through the events one by one) we should add a helper:

    class ValidateSlots(Action):
        def name(self) -> Text:
            return "action_validate_my_form"
        def run(
            self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
        ) -> List[EventType]:
            extracted_slots: Dict[Text, Any] = tracker.get_extracted_slots()
            validation_events = []
            for slot_name, slot_value in extracted_slots:
                # Simply validation which checks if the extracted slot has a value
                if slot_value is not None:
                    validation_events.append(SlotSet(slot_name, slot_value))
                else:
                    # Return a `SlotSet` event with value `None` to indicate that this
                    # slot still needs to be filled.
                    validation_events.append(SlotSet(slot_name, None))
            return validation_events
@wochinge wochinge added type:enhancement ✨ Additions of new features or changes to existing ones, should be doable in a single PR area:rasa-sdk 🧑‍💻 Everything that touches our python Rasa SDK priority:normal Impacts some users. Prevents using a secondary feature normally. labels Jul 17, 2020
@wochinge wochinge self-assigned this Aug 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:rasa-sdk 🧑‍💻 Everything that touches our python Rasa SDK priority:normal Impacts some users. Prevents using a secondary feature normally. type:enhancement ✨ Additions of new features or changes to existing ones, should be doable in a single PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant