Skip to content

Commit

Permalink
Merge pull request #6030 from RasaHQ/rules-scope-dispatched-per-form
Browse files Browse the repository at this point in the history
RulePolicy: scope dispatches per form
  • Loading branch information
alwx authored Jun 24, 2020
2 parents ff213fc + afad45f commit bed6aeb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
13 changes: 10 additions & 3 deletions rasa/core/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,24 @@ async def request_next_slot(
# no more required slots to fill
return [SlotSet(REQUESTED_SLOT, None)]

@staticmethod
def _name_of_utterance(self, domain: Domain, slot_name: Text) -> Text:
full_name = f"utter_ask_{self._form_name}_{slot_name}"
if full_name in domain.action_names:
return full_name
else:
return f"utter_ask_{slot_name}"

async def _ask_for_slot(
self,
domain: Domain,
nlg: NaturalLanguageGenerator,
output_channel: OutputChannel,
slot_name: Text,
tracker: DialogueStateTracker,
) -> List[Event]:
name_of_utterance = f"utter_ask_{slot_name}"

action_to_ask_for_next_slot = action.action_from_name(
name_of_utterance, None, domain.user_actions
self._name_of_utterance(domain, slot_name), None, domain.user_actions
)
events_to_ask_for_next_slot = await action_to_ask_for_next_slot.run(
output_channel, nlg, tracker, domain
Expand Down
26 changes: 26 additions & 0 deletions tests/core/actions/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,32 @@ async def test_validate_slots():
]


def test_name_of_utterance():
form_name = "another_form"
slot_name = "num_people"
full_utterance_name = f"utter_ask_{form_name}_{slot_name}"

domain = f"""
forms:
- {form_name}:
{slot_name}:
- type: from_text
responses:
{full_utterance_name}:
- text: "How many people?"
"""
domain = Domain.from_yaml(domain)

action_server_url = "http:/my-action-server:5055/webhook"

with aioresponses() as mocked:
action_server = EndpointConfig(action_server_url)
action = FormAction(form_name, action_server)

assert action._name_of_utterance(domain, slot_name) == full_utterance_name
assert action._name_of_utterance(domain, "another_slot") == "utter_ask_another_slot"


def test_temporary_tracker():
extra_slot = "some_slot"
sender_id = "test"
Expand Down

0 comments on commit bed6aeb

Please sign in to comment.