-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #253 from RasaHQ/extract-slots-helper
add helper to extract form slot candidates
- Loading branch information
Showing
3 changed files
with
102 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Added the method ``form_slots_to_validate`` to ``Tracker``. This method is helpful | ||
when using a custom action to validate slots which were extracted by a Form as shown | ||
by the following example. | ||
|
||
.. code-block:: python | ||
class ValidateSlots(Action): | ||
def name(self) -> Text: | ||
return "validate_your_form" | ||
def run( | ||
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict | ||
) -> List[EventType]: | ||
extracted_slots: Dict[Text, Any] = tracker.form_slots_to_validate() | ||
validation_events = [] | ||
for slot_name, slot_value in extracted_slots: | ||
# Check if slot is valid. | ||
if is_valid(slot_value): | ||
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 | ||
def is_valid(slot_value: Any) -> bool: | ||
# Implementation of the validate function. | ||
Please note that ``tracker.form_slots_to_validate`` only works with Rasa Open Source 2. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters