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

RulePolicy: scope dispatches per form #6030

Merged
merged 2 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions rasa/core/actions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,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