Пример #1
0
 def _temporary_tracker(
     self,
     current_tracker: DialogueStateTracker,
     additional_events: List[Event],
     domain: Domain,
 ) -> DialogueStateTracker:
     return DialogueStateTracker.from_events(
         current_tracker.sender_id,
         current_tracker.events_after_latest_restart()
         # Insert form execution event so that it's clearly distinguishable which
         # events were newly added.
         + [ActionExecuted(self.name())] + additional_events,
         slots=domain.slots,
     )
Пример #2
0
 def _temporary_tracker(
     self,
     current_tracker: DialogueStateTracker,
     additional_events: List[Event],
     domain: Domain,
 ) -> DialogueStateTracker:
     return DialogueStateTracker.from_events(
         current_tracker.sender_id,
         current_tracker.events_after_latest_restart()
         # Insert SlotSet event to make sure REQUESTED_SLOT belongs to active form.
         + [SlotSet(REQUESTED_SLOT, self.get_slot_to_fill(current_tracker))]
         # Insert form execution event so that it's clearly distinguishable which
         # events were newly added.
         + [ActionExecuted(self.name())] + additional_events,
         slots=domain.slots,
     )
Пример #3
0
async def replay_events(tracker: DialogueStateTracker, agent: "Agent") -> None:
    """Take a tracker and replay the logged user utterances against an agent.

    During replaying of the user utterances, the executed actions and events
    created by the agent are compared to the logged ones of the tracker that
    is getting replayed. If they differ, a warning is logged.

    At the end, the tracker stored in the agent's tracker store for the
    same sender id will have quite the same state as the one
    that got replayed."""

    actions_between_utterances = []
    last_prediction = [ACTION_LISTEN_NAME]

    for i, event in enumerate(tracker.events_after_latest_restart()):
        if isinstance(event, UserUttered):
            _check_prediction_aligns_with_story(last_prediction,
                                                actions_between_utterances)

            actions_between_utterances = []
            rasa.shared.utils.cli.print_success(event.text)
            out = CollectingOutputChannel()
            await agent.handle_text(event.text,
                                    sender_id=tracker.sender_id,
                                    output_channel=out)
            for m in out.messages:
                buttons = m.pop("buttons", None)  # for non-terminal stdin
                console.print_bot_output(m)

                if buttons is not None:
                    color = rasa.shared.utils.io.bcolors.OKBLUE
                    rasa.shared.utils.cli.print_color("Buttons:", color=color)
                    for idx, button in enumerate(buttons):
                        rasa.shared.utils.cli.print_color(
                            cli_utils.button_to_string(button, idx),
                            color=color)

            tracker = agent.tracker_store.retrieve(tracker.sender_id)
            last_prediction = actions_since_last_utterance(tracker)

        elif isinstance(event, ActionExecuted):
            actions_between_utterances.append(event.action_name)

    _check_prediction_aligns_with_story(last_prediction,
                                        actions_between_utterances)