async def test_nlg_conditional_response_variations_with_diff_slot_types( slot_name: Text, slot_value: Any, message: Text ): responses = { "utter_action": [ { "text": "example boolean", "condition": [{"type": "slot", "name": "test_bool", "value": True}], }, { "text": "example integer", "condition": [{"type": "slot", "name": "test_int", "value": 12}], }, { "text": "example list", "condition": [{"type": "slot", "name": "test_list", "value": []}], }, ] } t = TemplatedNaturalLanguageGenerator(responses=responses) slot = AnySlot( name=slot_name, initial_value=slot_value, influence_conversation=False ) tracker = DialogueStateTracker(sender_id="nlg_tracker", slots=[slot]) r = await t.generate( utter_action="utter_action", tracker=tracker, output_channel="" ) assert r.get("text") == message
async def test_nlg_conditional_response_variations_with_yaml_single_condition( slot_name: Text, slot_value: Any, bot_message: Text): domain = Domain.from_file( path="data/test_domains/conditional_response_variations.yml") t = TemplatedNaturalLanguageGenerator(responses=domain.responses) slot = AnySlot(name=slot_name, initial_value=slot_value, influence_conversation=False) tracker = DialogueStateTracker(sender_id="conversation_id", slots=[slot]) r = await t.generate(utter_action="utter_withdraw", tracker=tracker, output_channel="") assert r.get("text") == bot_message
async def test_nlg_conditional_response_variations_with_none_slot(): domain = Domain.from_yaml( """ version: "2.0" responses: utter_action: - text: "text A" condition: - type: slot name: account value: "A" """ ) t = TemplatedNaturalLanguageGenerator(domain.responses) slot = AnySlot(name="account", initial_value=None, influence_conversation=False) tracker = DialogueStateTracker(sender_id="test", slots=[slot]) r = await t.generate("utter_action", tracker, "") assert r is None
async def test_rasa_file_importer(project: Text): config_path = os.path.join(project, DEFAULT_CONFIG_PATH) domain_path = os.path.join(project, DEFAULT_DOMAIN_PATH) default_data_path = os.path.join(project, DEFAULT_DATA_PATH) importer = RasaFileImporter(config_path, domain_path, [default_data_path]) domain = await importer.get_domain() assert len(domain.intents) == 7 + len(DEFAULT_INTENTS) assert domain.slots == [AnySlot(SESSION_START_METADATA_SLOT)] assert domain.entities == [] assert len(domain.action_names_or_texts) == 17 assert len(domain.templates) == 6 stories = await importer.get_stories() assert len(stories.story_steps) == 5 nlu_data = await importer.get_nlu_data("en") assert len(nlu_data.intents) == 7 assert len(nlu_data.intent_examples) == 69
async def test_nlg_conditional_response_variations_with_null_slot(): domain = Domain.from_yaml(f""" version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" responses: utter_action: - text: "text for null" condition: - type: slot name: account value: null """) t = TemplatedNaturalLanguageGenerator(domain.responses) slot = AnySlot(name="account", mappings=[{}], initial_value=None, influence_conversation=False) tracker = DialogueStateTracker(sender_id="test", slots=[slot]) r = await t.generate("utter_action", tracker, "") assert r.get("text") == "text for null" tracker_no_slots = DialogueStateTracker(sender_id="new_test", slots=[]) r = await t.generate("utter_action", tracker_no_slots, "") assert r.get("text") == "text for null"
def test_rasa_file_importer(project: Text): config_path = os.path.join(project, DEFAULT_CONFIG_PATH) domain_path = os.path.join(project, DEFAULT_DOMAIN_PATH) default_data_path = os.path.join(project, DEFAULT_DATA_PATH) importer = RasaFileImporter(config_path, domain_path, [default_data_path]) domain = importer.get_domain() assert len(domain.intents) == 7 + len(DEFAULT_INTENTS) assert domain.slots == [AnySlot(SESSION_START_METADATA_SLOT, mappings=[{}])] assert domain.entities == [] assert len(domain.action_names_or_texts) == 19 assert len(domain.responses) == 6 stories = importer.get_stories() assert len(stories.story_steps) == 5 test_stories = importer.get_conversation_tests() assert len(test_stories.story_steps) == 0 nlu_data = importer.get_nlu_data("en") assert len(nlu_data.intents) == 7 assert len(nlu_data.intent_examples) == 68
def test_exception_if_featurized( self, mappings: List[Dict[Text, Any]], ): with pytest.raises(InvalidSlotConfigError): AnySlot("⛔️", mappings=mappings, influence_conversation=True)
def create_slot(self, mappings: List[Dict[Text, Any]], influence_conversation: bool) -> Slot: return AnySlot("test", mappings=mappings, influence_conversation=False)
def test_exception_if_featurized(self): with pytest.raises(InvalidSlotConfigError): AnySlot("⛔️", influence_conversation=True)
def create_slot(self, influence_conversation: bool) -> Slot: return AnySlot("test", influence_conversation=False)
def __missing__(self, key: Text) -> Slot: value = self[key] = AnySlot(key, mappings=[]) return value