示例#1
0
文件: states.py 项目: ralic/alexafsm
    def has_result(self) -> response.Response:
        """Offer a preview of a skill"""
        attributes = self.attributes
        query = attributes.query
        skill = attributes.skill
        asked_for_speech = ''
        if attributes.first_time_presenting_results:
            asked_for_speech = _you_asked_for(query)
        if attributes.number_of_hits == 1:
            skill_position_speech = 'The only skill I found is'
        else:
            skill_position_speech = f'The {ENGLISH_NUMBERS[attributes.skill_cursor]} skill is'
            if attributes.first_time_presenting_results:
                if attributes.number_of_hits > 6:
                    num_hits = f'Here are the top {MAX_SKILLS} results.'
                else:
                    num_hits = f'I found {len(attributes.skills)} skills.'
                skill_position_speech = f'{num_hits} {skill_position_speech}'
        return response.Response(
            speech=f"{asked_for_speech} "
            f" {skill_position_speech} {_get_verbal_skill(skill)}."
            f" {HEAR_MORE}",
            card=f"Search for {query}",
            card_content=f"""
            Top result: {skill.name}

            {_get_highlights(skill)}
            """,
            reprompt=DEFAULT_PROMPT)
示例#2
0
文件: states.py 项目: ralic/alexafsm
 def no_query_search(self) -> response.Response:
     """No query specified, ask for query"""
     return response.Response(
         speech=
         f"Please say what it is that you want to do. For example, 'I want to buy "
         f"flowers'. Or, 'I want to get a ride.'",
         reprompt=DEFAULT_PROMPT)
示例#3
0
文件: states.py 项目: ralic/alexafsm
 def no_result(self) -> response.Response:
     """No results, ask for rephrase or help"""
     return response.Response(
         speech=f"{_you_asked_for(self.attributes.query)},"
         f" I could not find any such skills. Please rephrase, or say"
         f" help me, for help.",
         reprompt=DEFAULT_PROMPT)
示例#4
0
    def execute(self) -> response.Response:
        """Called when the user specifies an intent for this skill"""
        intent = self.attributes.intent
        previous_state = self.state

        # backup attributes in case of invalid FSM transition
        attributes_backup = self.attributes
        try:
            # trigger is added by transitions library
            self.trigger(intent)
            self._delete_temporary_attributes()
            current_state = self.state
            logger.info(
                f"Changed from {previous_state} to {current_state} through {intent}"
            )
            self.attributes.state = current_state
            return self.get_current_state_response()
        except MachineError as exception:
            logger.error(str(exception))
            # reset attributes
            self.states.attributes = attributes_backup
            state_response = self.get_current_state_response()
            not_understood_response = response.Response(
                speech=
                f'{response.NOT_UNDERSTOOD}<break/>{state_response.reprompt}',
                reprompt=state_response.reprompt,
            )
            return not_understood_response
示例#5
0
文件: states.py 项目: ralic/alexafsm
    def initial(self) -> response.Response:
        if self.attributes.first_time:
            welcome_speech = f"Welcome to {self.skill_name}. {HELP}"
        else:
            welcome_speech = f"Welcome to {self.skill_name}, {self.default_prompt}"

        return response.Response(speech=welcome_speech,
                                 reprompt=self.default_prompt)
示例#6
0
文件: states.py 项目: ralic/alexafsm
 def describe_ratings(self):
     """
     when we've found a skill that the user might like and the user wants to know how
     well-liked it is
     """
     skill = self.attributes.skill
     return response.Response(
         speech=f"{skill.name} {_get_verbal_ratings(skill)}."
         f" Would you like to hear more about this skill?",
         reprompt="Would you like to hear more about this skill?")
示例#7
0
文件: states.py 项目: ralic/alexafsm
    def describing(self) -> response.Response:
        """Describe a skill, used in response generator"""
        skill = self.attributes.skill
        if skill.num_ratings > 0:
            rating_str = f"{skill.avg_rating} (from {skill.num_ratings} reviews)"
        else:
            rating_str = "No reviews yet"

        interrupt_hint = ""
        if not self.attributes.said_interrupt:
            interrupt_hint = "Okay, interrupt me anytime by saying 'Alexa.'"
            self.attributes.said_interrupt = True

        return response.Response(speech=f"{interrupt_hint} {skill.name}."
                                 f" {skill.short_description}",
                                 card=skill.name,
                                 card_content=f"""
            Creator: {skill.creator}
            Category: {skill.category}
            Average rating: {rating_str}
            {skill.description}
            """,
                                 image=skill.image_url,
                                 reprompt=IS_THAT_ALL)
示例#8
0
文件: states.py 项目: ralic/alexafsm
    def bad_navigate(self) -> response.Response:
        """Bad navigation (first, second, third, previous, next)"""
        attributes = self.attributes
        if not attributes.skills:
            if attributes.query:
                speech = f"I did not find any skills for query {attributes.query}."
            else:
                speech = f"To navigate to a skill, please search first. {HELP}"
        elif attributes.intent == PREVIOUS_SKILL:
            speech = "There is no previous skill. I am currently at skill number one."
        elif attributes.intent == NEXT_SKILL:
            speech = f"Sorry, there is no next skill. How else can I help you?"
        elif attributes.intent == amazon_intent.NO:
            speech = f"There are no more results. Please try a different search phrase."
        else:  # nth skill
            nth = attributes.nth_as_index
            if nth >= 0:
                speech = f"You asked for skill {nth + 1}. I found only " \
                         f"{len(attributes.skills)} skills for the query {attributes.query}."
            else:
                speech = f"Sorry, I'm not sure which skill you want to go to. Please rephrase. " \
                         f"For example, tell me about skill 3."

        return response.Response(speech=speech, reprompt=DEFAULT_PROMPT)
示例#9
0
文件: states.py 项目: ralic/alexafsm
 def helping(self) -> response.Response:
     return response.Response(speech=HELP, reprompt=DEFAULT_PROMPT)
示例#10
0
文件: states.py 项目: ralic/alexafsm
 def is_that_all(self) -> response.Response:
     """when we want to see if the user is done with the skill"""
     return response.Response(speech=f"Okay, {IS_THAT_ALL}",
                              reprompt=IS_THAT_ALL)
示例#11
0
文件: states.py 项目: ralic/alexafsm
 def search_prompt(self) -> response.Response:
     """when we're asking the user to conduct a new search"""
     return response.Response(speech=DEFAULT_PROMPT,
                              reprompt=DEFAULT_PROMPT)