def get_response_trigger_phrase(
         self,
         state: State,
         trigger_phrase: str = None) -> ResponseGeneratorResult:
     error_message = f"Method get_response_trigger_phrase of {self.name} was selected to respond, but it is not implemented."
     logger.error(error_message)
     return self.get_handoff_response(self.state_manager, state)
Beispiel #2
0
 def get_prompt(self, state: dict) -> PromptResult:
     try:
         response = self._get_prompt(state)
     except Exception as err:
         tb = traceback.print_tb(err.__traceback__)
         logger.error(
             "MUSIC RG is returning an emptyPrompt, because of {}, with the traceback: {}"
             .format(err, tb))
         response = emptyPrompt(state)
     return response
    def get_response_last_turn_asked_question(self, state):
        utterance = self.state_manager.current_state.text
        triggered_answers = self.process_templates(ANSWER_TEMPLATES, utterance)
        sentiment_answers = self.process_templates(SENTIMENT_TEMPLATES, utterance)
        triggered_answers = {**triggered_answers, **sentiment_answers}

        if state.last_turn_asked_question == 'QuestionLikedMusicianTemplate':
            response = self._handle_answer_like_question(state, triggered_answers)
        elif state.last_turn_asked_question == 'QuestionWhichOfTheirSongsDoYouLike':
            response = self._handle_answer_liked_songs(state, triggered_answers)
        else:
            # Last turn was a question, but we don't have a matching template. This should not have happened.
            error_message = "Last turn question {} is not a part of {}. This is not supposed to happen.".format(state.last_turn_asked_question, self.name)
            logger.error(error_message)
            response = self.get_handoff_response(self.state_manager, state)
        return response
    def get_response(self,
                     state: State,
                     trigger_entity: WikiEntity = None,
                     trigger_phrase: str = None) -> ResponseGeneratorResult:
        if state.last_turn_asked_question:
            response = self.get_response_last_turn_asked_question(state)
        elif trigger_entity:
            response = self.get_response_trigger_entity(state, trigger_entity)
        elif trigger_phrase:
            response = self.get_response_trigger_phrase(state, trigger_phrase)
        else:
            error_message = f"{self.name} was selected to respond, but neither of the conditions are met: last_turn_asked_question, trigger_entity, or trigger_phrase."
            logger.error(error_message)
            response = self.get_handoff_response(self.state_manager, state)

        response.conditional_state.turn_treelet_history.append(self.name)

        return response
Beispiel #5
0
    def get_response_last_turn_asked_question(self, state):
        utterance = self.state_manager.current_state.text
        triggered_answers = self.process_templates(ANSWER_TEMPLATES, utterance)
        sentiment_answers = self.process_templates(SENTIMENT_TEMPLATES,
                                                   utterance)
        triggered_answers = {**triggered_answers, **sentiment_answers}

        if state.last_turn_asked_question == 'QuestionListeningFrequencyTemplate':
            response = self._handle_answer_listening_frequency_question(
                state, triggered_answers)
        elif state.last_turn_asked_question == 'QuestionListeningConditionsTemplate':
            response = self._handle_answer_listening_conditions_question(
                state, triggered_answers)
        elif state.last_turn_asked_question == 'QuestionFeelingsAboutMusicTemplate':
            response = self._handle_answer_feelings_about_music_question(
                state, triggered_answers)
        else:
            # Last turn was a question, but we don't have a matching template. This should not have happened.
            error_message = "Last turn question {} is not a part of {}. This is not supposed to happen.".format(
                state.last_turn_asked_question, self.name)
            logger.error(error_message)
            response = self.get_handoff_response(self.state_manager, state)
        return response
 def get_response_last_turn_asked_question(
         self, state: State) -> ResponseGeneratorResult:
     error_message = f"Method get_response_last_turn_asked_question of {self.name} was selected to respond, but it is not implemented."
     logger.error(error_message)
     return self.get_handoff_response(self.state_manager, state)
Beispiel #7
0
    "I have a question for you about music. ",
    "There's so much music here in the cloud and I'm curious to know what you think about it. ",
    "I've been listening to a lot of new songs lately, and I'd love to hear what you think about music. "
]

# 'QuestionListeningFrequencyTemplate' is quite similar to 'QuestionListeningConditionsTemplate'. We are
# removing one of these randomly in every conversation.
try:
    question = random.choice([
        'QuestionListeningConditionsTemplate',
        'QuestionListeningConditionsTemplate'
    ])
    del QUESTION_TEMPLATES[question]
except KeyError as e:
    logger.error(
        "We caught an error in Music RG. Key {} didn't exist in {}, but we tried to remove it."
        .format(question, QUESTION_TEMPLATES))


class GenericTreelet(Treelet):
    def __init__(self, rg):
        super().__init__(rg)
        self.name = "generic"
        self.repr = "Generic Treelet"
        self.treelet_type = TreeletType.HEAD
        self.templates = {**QUESTION_TEMPLATES, **QUESTION_TEMPLATES}
        self.trigger_phrases = self.get_trigger_phrases()
        self.trigger_entity_groups = self.get_trigger_entity_groups()

    @staticmethod
    def get_trigger_phrases():