def as_dialogue(self) -> Dialogue: """Return a ``Dialogue`` object containing all of the turns. This can be serialised and later used to recover the state of this tracker exactly.""" return Dialogue(self.sender_id, list(self.events))
def test_dialogue_from_parameters(): domain = Domain.load(DEFAULT_DOMAIN_PATH_WITH_SLOTS_AND_NO_ACTIONS) filename = "data/test_dialogues/default.json" tracker = tracker_from_dialogue_file(filename, domain) serialised_dialogue = InMemoryTrackerStore.serialise_tracker(tracker) deserialised_dialogue = Dialogue.from_parameters(json.loads(serialised_dialogue)) assert tracker.as_dialogue().as_dict() == deserialised_dialogue.as_dict()
def as_dialogue(self, sender_id: Text, domain: Domain) -> Dialogue: events = [] for step in self.story_steps: events.extend( step.explicit_events(domain, should_append_final_listen=False)) events.append(ActionExecuted(ACTION_LISTEN_NAME)) return Dialogue(sender_id, events)
def deserialise_tracker( self, sender_id: Text, serialised_tracker: Union[Text, bytes]) -> Optional[DialogueStateTracker]: """Deserializes the tracker and returns it.""" tracker = self.init_tracker(sender_id) try: dialogue = Dialogue.from_parameters(json.loads(serialised_tracker)) except UnicodeDecodeError: dialogue = self._deserialize_dialogue_from_pickle( sender_id, serialised_tracker) tracker.recreate_from_dialogue(dialogue) return tracker
def deserialise_tracker( self, sender_id: Text, serialised_tracker: Union[Text, bytes] ) -> Optional[DialogueStateTracker]: """Deserializes the tracker and returns it.""" tracker = self.init_tracker(sender_id) try: dialogue = Dialogue.from_parameters(json.loads(serialised_tracker)) except UnicodeDecodeError as e: raise TrackerDeserialisationException( "Tracker cannot be deserialised. " "Trackers must be serialised as json. " "Support for deserialising pickled trackers has been removed." ) from e tracker.recreate_from_dialogue(dialogue) return tracker
TEST_DEFAULT_DIALOGUE = Dialogue( name="default", events=[ ActionExecuted(action_name="action_listen", timestamp=1551952977.4850519), UserUttered( entities=[{ "end": 19, "entity": "name", "start": 14, "value": "Peter" }], intent={ "confidence": 0.0, "name": "greet" }, message_id=None, parse_data={ "entities": [{ "end": 19, "entity": "name", "start": 14, "value": "Peter" }], "intent": { "confidence": 0.0, "name": "greet" }, "message_id": None, "metadata": {}, "text": "Hi my name is Peter", }, text="Hi my name is Peter", timestamp=1551953035.076376, ), SlotSet(key="name", timestamp=1551953035.076385, value="Peter"), ActionExecuted(action_name="utter_greet", timestamp=1551953040.607782), BotUttered( data={ "attachment": None, "buttons": None, "elements": None }, text="hey there Peter!", timestamp=1551953040.60779, ), ], )
def test_dialogue_from_parameters(domain: Domain): tracker = tracker_from_dialogue(TEST_DEFAULT_DIALOGUE, domain) serialised_dialogue = InMemoryTrackerStore.serialise_tracker(tracker) deserialised_dialogue = Dialogue.from_parameters( json.loads(serialised_dialogue)) assert tracker.as_dialogue().as_dict() == deserialised_dialogue.as_dict()