Example #1
0
def new_form_and_tracker(form_spec, requested_slot, additional_slots=[]):
    form = ActionBotfrontForm(form_spec.get("form_name"))
    tracker = DialogueStateTracker.from_dict(
        "default",
        [],
        [
            Slot(name=requested_slot),
            *[Slot(name=name) for name in additional_slots],
            Slot(name="requested_slot", initial_value=requested_slot),
        ],
    )
    form.form_spec = form_spec  # load spec manually
    return form, tracker
Example #2
0
async def test_parsing_with_tracker():
    tracker = DialogueStateTracker.from_dict("1", [], [Slot("requested_language")])

    # we'll expect this value 'en' to be part of the result from the interpreter
    tracker._set_slot("requested_language", "en")

    endpoint = EndpointConfig("https://interpreter.com")
    with aioresponses() as mocked:
        mocked.post("https://interpreter.com/parse", repeat=True, status=200)

        # mock the parse function with the one defined for this test
        with patch.object(RasaNLUHttpInterpreter, "parse", mocked_parse):
            interpreter = RasaNLUHttpInterpreter(endpoint_config=endpoint)
            agent = Agent(None, None, interpreter)
            result = await agent.parse_message_using_nlu_interpreter("lunch?", tracker)

            assert result["requested_language"] == "en"
def test_single_state_featurizer_prepare_for_training():
    domain = Domain(
        intents=["greet"],
        entities=["name"],
        slots=[Slot("name")],
        templates={},
        forms=[],
        action_names=["utter_greet", "action_check_weather"],
    )

    f = SingleStateFeaturizer()
    f.prepare_for_training(domain, RegexInterpreter())

    assert len(f._default_feature_states[INTENT]) > 1
    assert "greet" in f._default_feature_states[INTENT]
    assert len(f._default_feature_states[ENTITIES]) == 1
    assert f._default_feature_states[ENTITIES]["name"] == 0
    assert len(f._default_feature_states[SLOTS]) == 1
    assert f._default_feature_states[SLOTS]["name_0"] == 0
    assert len(f._default_feature_states[ACTION_NAME]) > 2
    assert "utter_greet" in f._default_feature_states[ACTION_NAME]
    assert "action_check_weather" in f._default_feature_states[ACTION_NAME]
    assert len(f._default_feature_states[ACTIVE_LOOP]) == 0
Example #4
0
def test_container_derive_messages_from_domain_and_add():
    action_names = ["a", "b"]
    # action texts, response keys, forms, and action_names must be unique or the
    # domain will complain about it ...
    action_texts = ["a2", "b2"]
    # ... but the response texts could overlap with e.g action texts
    responses = {"a3": {TEXT: "a2"}, "b3": {TEXT: "b2"}}
    forms = {"a4": "a4"}
    # however, intent names can be anything
    intents = ["a", "b"]
    domain = Domain(
        intents=intents,
        action_names=action_names,
        action_texts=action_texts,
        responses=responses,
        entities=["e_a", "e_b", "e_c"],
        slots=[Slot(name="s", mappings=[{}])],
        forms=forms,
    )
    lookup_table = MessageContainerForCoreFeaturization()
    lookup_table.derive_messages_from_domain_and_add(domain)
    assert len(lookup_table) == (len(domain.intent_properties) +
                                 len(domain.action_names_or_texts))
Example #5
0
def test_domain_validation_with_valid_marker(depth: int, max_branches: int,
                                             seed: int):
    # We do this a bit backwards, we construct the domain from the marker
    # and assert they must match
    rng = np.random.default_rng(seed=seed)
    marker, expected_size = generate_random_marker(
        depth=depth,
        max_branches=max_branches,
        rng=rng,
        possible_conditions=CONDITION_MARKERS,
        possible_operators=OPERATOR_MARKERS,
        constant_condition_text=None,
        constant_negated=None,
    )

    slots = [
        Slot(name, []) for name in _collect_parameters(marker, SlotSetMarker)
    ]
    actions = list(_collect_parameters(marker, ActionExecutedMarker))
    intents = _collect_parameters(marker, IntentDetectedMarker)
    domain = Domain(intents, [], slots, {}, actions, {})

    assert marker.validate_against_domain(domain)
Example #6
0
 def __missing__(self, key) -> Slot:
     value = self[key] = Slot(key)
     return value
Example #7
0
 def __missing__(self, key: Text) -> Slot:
     value = self[key] = Slot(key, mappings=[])
     return value