def _generate_domain_file( self, intents: list, templates: dict, actions: list ) -> NoReturn: """ Generated the domain file for an agent, merging it with the already trained domain of the smalltalk set of intents :return: """ from rasa.core.slots import TextSlot from rasa.core.domain import Domain # Get entities that appears in any intent to be trained entities = set() for entity in self.entities_data: if any( intent in [x["name"] for x in entity["intents"]] for intent in intents ): entities.add(entity["name"]) # Save domain domain_path = os.path.join(TRAINING_DATA_DIR, DEFAULT_DOMAIN_PATH) domain = Domain( intents=intents, entities=list(entities), templates=dict(templates), slots=[TextSlot(entity) for entity in list(entities)], action_names=[*dict(templates)] + actions, form_names=[], ) domain.persist(domain_path)
def test_check_domain_sanity_on_invalid_domain(): with pytest.raises(InvalidDomain): Domain( intents={}, entities=[], slots=[], templates={}, action_names=["random_name", "random_name"], form_names=[], ) with pytest.raises(InvalidDomain): Domain( intents={}, entities=[], slots=[TextSlot("random_name"), TextSlot("random_name")], templates={}, action_names=[], form_names=[], ) with pytest.raises(InvalidDomain): Domain( intents={}, entities=[ "random_name", "random_name", "other_name", "other_name" ], slots=[], templates={}, action_names=[], form_names=[], ) with pytest.raises(InvalidDomain): Domain( intents={}, entities=[], slots=[], templates={}, action_names=[], form_names=["random_name", "random_name"], )
def test_unfeaturized_slot_in_domain_warnings(): # create empty domain domain = Domain.empty() # add one unfeaturized and one text slot unfeaturized_slot = UnfeaturizedSlot("unfeaturized_slot", "value1") text_slot = TextSlot("text_slot", "value2") domain.slots.extend([unfeaturized_slot, text_slot]) # ensure both are in domain assert all(slot in domain.slots for slot in (unfeaturized_slot, text_slot)) # text slot should appear in domain warnings, unfeaturized slot should not in_domain_slot_warnings = domain.domain_warnings()["slot_warnings"]["in_domain"] assert text_slot.name in in_domain_slot_warnings assert unfeaturized_slot.name not in in_domain_slot_warnings
def create_slot(self): return TextSlot("test")