Ejemplo n.º 1
0
    def _run_action(self, action, tracker, dispatcher, policy=None,
                    confidence=None):
        # events and return values are used to update
        # the tracker state after an action has been taken
        try:
            events = action.run(dispatcher, tracker, self.domain)
        except ActionExecutionRejection:
            events = [ActionExecutionRejected(action.name(),
                                              policy, confidence)]
            tracker.update(events[0])
            return self.should_predict_another_action(action.name(), events)
        except Exception as e:
            logger.error("Encountered an exception while running action '{}'. "
                         "Bot will continue, but the actions events are lost. "
                         "Make sure to fix the exception in your custom "
                         "code.".format(action.name()))
            logger.debug(e, exc_info=True)
            events = []

        self._log_action_on_tracker(tracker, action.name(), events, policy,
                                    confidence)
        self.log_bot_utterances_on_tracker(tracker, dispatcher)
        self._schedule_reminders(events, dispatcher)

        return self.should_predict_another_action(action.name(), events)
Ejemplo n.º 2
0
def _emulate_form_rejection(processor, partial_tracker):
    if partial_tracker.active_form.get("name"):
        for p in processor.policy_ensemble.policies:
            if isinstance(p, FormPolicy):
                # emulate form rejection
                partial_tracker.update(
                    ActionExecutionRejected(
                        partial_tracker.active_form["name"]))
                # check if unhappy path is covered by the train stories
                if not p.state_is_unhappy(partial_tracker, processor.domain):
                    # this state is not covered by the stories
                    del partial_tracker.events[-1]
                    partial_tracker.active_form['rejected'] = False