def test_tracker_update_slots_with_entity(default_domain: Domain): tracker = DialogueStateTracker("default", default_domain.slots) test_entity = default_domain.entities[0] expected_slot_value = "test user" intent = {"name": "greet", PREDICTED_CONFIDENCE_KEY: 1.0} tracker.update( UserUttered( "/greet", intent, [ { "start": 1, "end": 5, "value": expected_slot_value, "entity": test_entity, "extractor": "manual", } ], ), default_domain, ) assert tracker.get_slot(test_entity) == expected_slot_value
def extract_other_slots(self, tracker: DialogueStateTracker, domain: Domain) -> Dict[Text, Any]: """Extract the values of the other slots if they are set by corresponding entities from the user input else return `None`. """ slot_to_fill = tracker.get_slot(REQUESTED_SLOT) entity_type_of_slot_to_fill = self._get_entity_type_of_slot_to_fill( slot_to_fill, domain) slot_values = {} for slot in self.required_slots(domain): # look for other slots if slot != slot_to_fill: # list is used to cover the case of list slot type slot_mappings = self.get_mappings_for_slot(slot, domain) for slot_mapping in slot_mappings: # check whether the slot should be filled by an entity in the input should_fill_entity_slot = ( slot_mapping["type"] == str(SlotMapping.FROM_ENTITY) and self.intent_is_desired(slot_mapping, tracker) and self.entity_is_desired( slot_mapping, slot, entity_type_of_slot_to_fill, tracker, domain, )) # check whether the slot should be # filled from trigger intent mapping should_fill_trigger_slot = ( tracker.active_loop_name != self.name() and slot_mapping["type"] == str( SlotMapping.FROM_TRIGGER_INTENT) and self.intent_is_desired(slot_mapping, tracker)) if should_fill_entity_slot: value = self.get_entity_value( slot_mapping["entity"], tracker, slot_mapping.get("role"), slot_mapping.get("group"), ) elif should_fill_trigger_slot: value = slot_mapping.get("value") else: value = None if value is not None: logger.debug( f"Extracted '{value}' for extra slot '{slot}'.") slot_values[slot] = value # this slot is done, check next break return slot_values
def test_tracker_does_not_modify_slots(slot_type: Type[Slot], initial_value: Any, value_to_set: Any): slot_name = "some-slot" slot = slot_type(slot_name, initial_value) tracker = DialogueStateTracker("some-conversation-id", [slot]) # change the slot value in the tracker tracker._set_slot(slot_name, value_to_set) # assert that the tracker contains the slot with the modified value assert tracker.get_slot(slot_name) == value_to_set # assert that the initial slot has not been affected assert slot.value == initial_value