def _export_stories(tracker, export_file_path): # export current stories and quit exported = StoryExported(export_file_path) tracker.update(exported) logger.info("Stories got exported to '{}'.".format( os.path.abspath(exported.path)))
def test_json_parse_export(): # DOCS MARKER StoryExported evt = \ { 'event': 'export', } # DOCS END assert Event.from_parameters(evt) == StoryExported()
def _export_stories(self, tracker): # export current stories and quit export_file_path = utils.request_input( prompt="File to export to (if file exists, this " "will append the stories) [stories.md]: ") exported = StoryExported(export_file_path) tracker.update(exported) logger.info("Stories got exported to '{}'.".format( os.path.abspath(exported.path)))
def probabilities_using_best_policy(self, tracker, domain): # [feature vector, tracker, domain] -> int # given a state, predict next action via asking a human probabilities = self.base_ensemble.probabilities_using_best_policy( tracker, domain) pred_out = np.argmax(probabilities) latest_action_was_listen = self._print_history(tracker) action_name = domain.action_for_index(pred_out).name() colored_name = utils.wrap_with_color(action_name, utils.bcolors.OKBLUE) if latest_action_was_listen: print("The bot wants to [{}] due to the intent. " "Is this correct?\n".format(colored_name)) user_input = utils.request_input( ["1", "2", "3", "0"], "\t1.\tYes\n" + "\t2.\tNo, intent is right but the action is wrong\n" + "\t3.\tThe intent is wrong\n" + "\t0.\tExport current conversations as stories and quit\n") else: print("The bot wants to [{}]. " "Is this correct?\n".format(colored_name)) user_input = utils.request_input( ["1", "2", "0"], "\t1.\tYes.\n" + "\t2.\tNo, the action is wrong.\n" + "\t0.\tExport current conversations as stories and quit\n") feature_vector = domain.feature_vector_for_tracker( self.featurizer, tracker, self.max_history) X = np.expand_dims(np.array(feature_vector), 0) if user_input == "1": # max prob prediction was correct return probabilities elif user_input == "2": # max prob prediction was false, new action required # action wrong y = self._request_action(probabilities, domain, tracker) self._fit_example(X, y, domain) self.write_out_story(tracker) return utils.one_hot(y, domain.num_actions) elif user_input == "3": # intent wrong and maybe action wrong intent = self._request_intent(tracker, domain) latest_message = copy.copy(tracker.latest_message) latest_message.intent = intent tracker.update(UserUtteranceReverted()) tracker.update(latest_message) return self.probabilities_using_best_policy(tracker, domain) elif user_input == "0": # export current stories and quit tracker.update(StoryExported()) exit() else: raise Exception( "Incorrect user input received '{}'".format(user_input))
def _export_stories(tracker): # export current stories and quit file_prompt = ("File to export to (if file exists, this " "will append the stories) " "[{}]: ").format(DEFAULT_FILE_EXPORT_PATH) export_file_path = utils.request_input(prompt=file_prompt) if not export_file_path: export_file_path = DEFAULT_FILE_EXPORT_PATH exported = StoryExported(export_file_path) tracker.update(exported) logger.info("Stories got exported to '{}'.".format( os.path.abspath(exported.path)))
@pytest.mark.parametrize("one_event,another_event", [ (UserUttered("/greet", { "name": "greet", "confidence": 1.0 }, []), UserUttered("/goodbye", { "name": "goodbye", "confidence": 1.0 }, [])), (TopicSet("my_topic"), TopicSet("my_other_topic")), (SlotSet("my_slot", "value"), SlotSet("my__other_slot", "value")), (Restarted(), None), (AllSlotsReset(), None), (ConversationPaused(), None), (ConversationResumed(), None), (StoryExported(), None), (ActionReverted(), None), (ActionExecuted("my_action"), ActionExecuted("my_other_action")), (BotUttered("my_text", "my_data"), BotUttered("my_other_test", "my_other_data")), (ReminderScheduled("my_action", "now"), ReminderScheduled("my_other_action", "now")), ]) def test_event_has_proper_implementation(one_event, another_event): # equals tests assert one_event != another_event, \ "Same events with different values need to be different" assert one_event == deepcopy(one_event), \ "Event copies need to be the same" assert one_event != 42, \ "Events aren't equal to 42!"
(SlotSet("my_slot", "value"), SlotSet("my__other_slot", "value")), (Restarted(), None), (AllSlotsReset(), None), (ConversationPaused(), None), (ConversationResumed(), None), (StoryExported(), None), (ActionReverted(), None), (ActionExecuted("my_action"), ActionExecuted("my_other_action")), (BotUttered("my_text", "my_data"), BotUttered("my_other_test", "my_other_data")), (ReminderScheduled("my_action", "now"), ReminderScheduled("my_other_action", "now")), ]) def test_event_has_proper_implementation(one_event, another_event):
def run(self, dispatcher, tracker, domain): return [StoryExported("data.md"), Restarted()]