def latest_events(template_name): return [ BotUttered(text="Heigh ho, heigh ho", metadata={"template_name": template_name}), ActionExecuted(ACTION_LISTEN_NAME), UserUttered(USER_TEXT), ]
def request_next_slot( self, dispatcher: "CollectingDispatcher", tracker: "Tracker", domain: Dict[Text, Any], ) -> Optional[List[EventType]]: #track intent of the input intent = tracker.latest_message.get("intent", {}).get("name") intent_confidence = tracker.latest_message.get("intent", {}).get("confidence") print(intent) #classify deacitvate intent if intent == 'deactivate': return [BotUttered("Do you really want to exit?", tracker)] #affirm intent to refill form elif intent == 'affirm' and intent_confidence > 0.95: return [self.deactivate()] ## continue filling form but other intents are else: for slot in self.required_slots(tracker): if self._should_request_slot(tracker, slot): logger.debug("Request next slot '{}'".format(slot)) dispatcher.utter_template("utter_ask_{}".format(slot), tracker, silent_fail=False, **tracker.slots) return [SlotSet(REQUESTED_SLOT, slot)]
def app_custom_show_hint(self, dispatcher, tracker, domain): user_question_id = tracker.get_slot('user_question_id') current_question = self.__question_collection.find_one({ 'hoclieu_q_id': user_question_id }) return [BotUttered(text='Đáp án là: {}'.format(current_question.get('correct_answer')))]
def run( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict[Text, Any]]: evt = BotUttered(text="my name is bot? idk", metadata={"nameGiven": "bot"}) return [evt]
async def test_code_not_just_asked(self): tracker = self.create_tracker(events=[ BotUttered( "asking phone number", metadata={"template_name": "utter_ask_phone_number"}, ) ]) await self.run_action(tracker) self.assert_events([]) self.assert_templates( ["utter_ask_daily_ci_enroll_form_validation_code"])
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]: print(tracker.current_slot_values()) if(tracker.current_slot_values()['name'] != None): greet_msg=self.timeGreeting()+" !! "+tracker.current_slot_values()['name']+", "+self.randGreeting() else: greet_msg = self.timeGreeting() +" !!," + self.randGreeting() return [BotUttered(text=greet_msg)]
def _carry_user_utterance(tracker: Tracker) -> List[EventType]: return [ ActionExecuted("utter_ask_another_question"), BotUttered(metadata={"template_name": "utter_ask_another_question"}), ActionExecuted(ACTION_LISTEN_NAME), UserUttered( tracker.latest_message.get("text", ""), parse_data={ "text": tracker.latest_message.get("text", ""), "intent": tracker.latest_message.get("intent", {}), "intent_ranking": tracker.latest_message.get("intent_ranking", []), "entities": tracker.latest_message.get("entities", []), }, ), ]
async def test_after_digression(self): tracker = self.create_tracker(events=[ BotUttered( "ok?", metadata={ "template_name": "utter_daily_ci_enroll_acknowledge_continue" }, ) ]) await self.run_action(tracker) self.assert_events([]) self.assert_templates(["utter_ask_phone_number_error"])
async def test_submit_feedback_not_given(self): tracker = self.create_tracker( slots={ QUESTION_SLOT: QUESTION, FEEDBACK_SLOT: FEEDBACK_NOT_GIVEN, ANSWERS_SLOT: ANSWERS, STATUS_SLOT: QuestionAnsweringStatus.SUCCESS, }, text="some text with", intent="another_intent", entities=[{"and": "entities"}], ) await self.run_action(tracker) self.assert_events( [ SlotSet(QUESTION_SLOT, None), SlotSet(FEEDBACK_SLOT, None), SlotSet( ASKED_QUESTION_SLOT, {**FULL_RESULT_SUCCESS, FEEDBACK_KEY: FEEDBACK_NOT_GIVEN}, ), ActionExecuted("utter_ask_another_question"), BotUttered(metadata={"template_name": "utter_ask_another_question"}), ActionExecuted(ACTION_LISTEN_NAME), UserUttered( "some text with", parse_data={ "text": "some text with", "intent": {"name": "another_intent"}, "intent_ranking": [], "entities": [{"and": "entities"}], }, ), ] ) self.assert_templates([])
def app_custom_get_question(self, dispatcher, tracker, domain): from .tutor.threshold import threshold_tutor print('slots: ', tracker.slots) # user infos user_id = tracker.current_state().get('sender_id', '') # toán/tiếng anh user_current_subject = tracker.get_slot('user_current_subject') user_current_skill = tracker.get_slot('user_english_skill') user_q_difficulty_label = tracker.get_slot('user_q_difficulty_label') or 'default' user_question_id = tracker.get_slot('user_question_id') evaluated_data = self.__get_needed_data( user_id, user_current_subject, user_current_skill, user_q_difficulty_label) if user_question_id: # get a new question depends on the user's level probs = threshold_tutor.next_question(**evaluated_data) q_index = np.random.choice(np.argsort(probs)[0 : 5]) next_question = evaluated_data.get('questions')[q_index] while user_question_id == str(next_question.get('hoclieu_q_id')): q_index = np.random.choice(np.argsort(probs)[0 : 5]) next_question = evaluated_data.get('questions')[q_index] user_question_id = str(next_question.get('hoclieu_q_id')) else: # get a new question depends on the user's level and differs from user_question_id # next_question = threshold_tutor.next_question(**evaluated_data) probs = threshold_tutor.next_question(**evaluated_data) q_index = np.random.choice(np.argsort(probs)[0 : 5]) next_question = evaluated_data.get('questions')[q_index] user_question_id = str(next_question.get('hoclieu_q_id')) events = [] text = next_question.get('text') answers = next_question.get('answers') image = next_question.get('image') audio = next_question.get('attachment') difficulty_label = next_question.get('difficulty_label', 'easy') level2stars = { 'easy': '⭐', 'medium': '⭐⭐', 'hard': '⭐⭐⭐', } events.append(BotUttered(text="Question's difficulty: {}".format( level2stars[difficulty_label] ))) data = { "custom": [] } if image: data["custom"].append(Attachment_Link("image", image)) if audio: data["custom"].append(Attachment_Link("audio", audio)) if answers: data["custom"].append(Quick_Replies_Answers(answers)) events.append(BotUttered(text=text, data=data)) events.append(SlotSet('user_question_id', user_question_id)) return events