Beispiel #1
0
 def getTemplate(self, content):
     template = BodyTemplate1()
     template.set_title('智能导购')
     template.set_plain_text_content(content)
     template.set_token('0c71de96-15d2-4e79-b97e-e52cec25c254')
     renderTemplate = RenderTemplate(template)
     return renderTemplate
Beispiel #2
0
    def search_intent_handler(self):
        """
        意图处理-搜索
        :return:
        """
        self.wait_answer()
        keyword = self.get_slots("keywords")
        if keyword is None or keyword == "":
            self.ask("keywords")
            return {"outputSpeech": r"请问您要搜索什么?"}

        template = ListTemplate2()
        template.set_title("搜索-" + keyword)
        template.set_background_image(
            "http://dbp-resource.cdn.bcebos.com/a3b2b130-c212-2241-294f-e13597c9dcc9/WeChat%20Image_20200508190042.jpg"
        )

        search_result = self.search_engine.search(keyword)

        for info in search_result:
            item = ListTemplateItem()
            item.set_image(info["img"])
            item.set_plain_primary_text(info["title"])
            item.set_plain_secondary_text(info["info"])
            template.add_item(item)

        directive = RenderTemplate(template)

        return {"directives": [directive], "outputSpeech": r"为您找到如下结果"}
Beispiel #3
0
    def getAnimalResponse(self, animal):
        self.set_expect_speech(True)
        self.wait_answer()
        #self.nlu.ask('animal')

        name = Utils.getName(animal)
        content = Utils.getDescribtion(animal)
        imgUrl = Utils.getImageUrl(animal)
        soundUrl = Utils.getSoundUrl(animal)

        self.set_session_attribute('name', name, None)

        template = BodyTemplate3()
        template.set_title(name)
        template.set_plain_content(content)
        template.set_image(imgUrl)
        template.set_background_image(imgUrl)

        renderTemplate = RenderTemplate(template)

        outputSpeech = '<speak>%s<audio src="%s"></audio>请问您还想听什么动物的声音呢?</speak>' % (
            name, soundUrl)
        reprompt = '请问您还想听什么动物的声音呢?'
        return {
            'directives': [renderTemplate],
            'reprompt': reprompt,
            'outputSpeech': outputSpeech
        }
Beispiel #4
0
 def getTemplate(self, content):
     template = BodyTemplate1()
     template.set_title('查询个税')
     template.set_plain_text_content(content)
     template.set_background_image('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1532350870263&di=c93edb2fb9a3cfe7a632acc46cceba62&imgtype=0&src=http%3A%2F%2Ffile25.mafengwo.net%2FM00%2F0A%2FAC%2FwKgB4lMC26CAWsKoAALb5778DWg60.rbook_comment.w1024.jpeg')
     template.set_token('0c71de96-15d2-4e79-b97e-e52cec25c254')
     renderTemplate = RenderTemplate(template)
     return renderTemplate
Beispiel #5
0
 def getTemplate2(self, music):
     print(music)
     bodyTemplate = BodyTemplate2()
     bodyTemplate.set_token(music['token'])
     bodyTemplate.set_background_image(self.DEFAULT_IMAGE)
     bodyTemplate.set_title(music['singer'])
     bodyTemplate.set_plain_content(music['name'])
     renderTemplate = RenderTemplate(bodyTemplate)
     return renderTemplate
Beispiel #6
0
 def getTemplate2(self, music):
     print(music)
     bodyTemplate = BodyTemplate2()
     bodyTemplate.setToken(music['token'])
     bodyTemplate.setBackGroundImage(self.DEFAULT_IMAGE)
     bodyTemplate.setTitle(music['singer'])
     bodyTemplate.setPlainContent(music['name'])
     renderTemplate = RenderTemplate(bodyTemplate)
     return renderTemplate
Beispiel #7
0
    def getListTemplate(self, content, items):
        template = ListTemplate2()
        template.set_token(self.LIST_TEMPLATE2_TOKEN)
        # template.set_background_image('')
        template.set_title(content)

        for item in items:
            template.add_item(self.getListTemplateItem(item))
        renderTemplate = RenderTemplate(template)
        return renderTemplate
Beispiel #8
0
    def askWhichAnimal(self):
        self.nlu.ask('animal')

        content = r'请问您想听什么动物的声音呢?'
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(content)
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        return self.getResponse(content, renderTemplate)
Beispiel #9
0
    def next_step_intent(self):
        self.wait_answer()
        couplet_list = self.utils.get_random_couplet()
        foot = u'你可以对我说' + random.choice(self.common_dialog)
        content, outputSpeech = self.get_ssml_content(couplet_list, '', foot)
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(content)
        template.set_background_image(self.BACKGROUD_URL)
        renderTemplate = RenderTemplate(template)

        return self.getResponse(content, renderTemplate, outputSpeech)
Beispiel #10
0
    def launch_request(self):
        """
        打开调用名
        """
        self.wait_answer()
        content = '欢迎进入新春对联,您可以这样对我说,猪年的对联'
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(content)
        template.set_background_image(self.BACKGROUD_URL)
        renderTemplate = RenderTemplate(template)

        return self.getResponse(content, renderTemplate, content)
Beispiel #11
0
    def end_request(self):
        """
        清空状态,结束会话
        """
        content = r'您得到了想要的春联了吗?推荐您使用技能动物声音,聆听各种萌萌哒的声音哦'
        self.wait_answer()
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content("")
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        return self.getResponse(content, renderTemplate)
Beispiel #12
0
 def get_to_list(self):
     """
     返回列表
     """
     self.wait_answer()
     self.current_item = -1
     self.set_session_attribute("current_item", -1, -1)
     list_template = self.get_list()
     render_template = RenderTemplate(list_template)
     return {
         'directives': [render_template],
         'outputSpeech': r'请选择要了解的内容,可以对我说第几个'
     }
Beispiel #13
0
    def __get_home_card(self):

        token = {'page': 'home'}
        body_template = BodyTemplate3()
        body_template.set_title('趣味计算')
        body_template.set_image(
            'http://dbp-resource.gz.bcebos.com/d78d043c-89d1-dfbb-fb48-482829cad05d/quweijisuan.png?authorization=bce-auth-v1%2Fa4d81bbd930c41e6857b989362415714%2F2018-06-23T07%3A18%3A48Z%2F-1%2F%2F77ebff2dd618080c880d6dfe15ebb0154a116a1e3ff83947e22b27e468540a46'
        )
        body_template.set_token(self.get_token(token))
        body_template.set_background_image(BG2)
        body_template.set_plain_content(
            '欢迎使用趣味计算,您可以对我说:"帮助",获取帮助信息,对我说"退出",关闭技能')
        directive = RenderTemplate(body_template)
        return directive
Beispiel #14
0
    def searchRequest(self):

        self.ask('deviceName')

        # card = TextCard('您要查找什么智能设备呢? 比如"查找我的空调"')
        # card.addCueWords("百度")
        # card.addCueWords("百度")
        # card.addCueWords("百度")
        # card.setAnchor("http://www.baidu.com", "百度")

        # renderTemplate = RenderTemplate()
        bodyTemplate = BodyTemplate1()
        bodyTemplate.setToken('token')
        bodyTemplate.setTitle('托尔斯泰的格言')
        bodyTemplate.setBackGroundImage('https://skillstore.cdn.bcebos.com/icon/100/c709eed1-c07a-be4a-b242-0b0d8b777041.jpg')
        bodyTemplate.setPlainTextContent('拖尔斯泰-理想的书籍是智慧的钥匙')
        renderTemplate = RenderTemplate(bodyTemplate)

        # renderTemplate.setTemplate(bodyTemplate)
        renderTemplate.setToken("renderTemplate")
        return {
            'directives': [renderTemplate],
            'outputSpeech': '<speak>您要查找什么智能设备呢? 比如"查找我的空调"</speak>'
        }
Beispiel #15
0
    def end_request(self):
        """
        清空状态,结束会话
        """
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(self.WELCOM_TIPS)
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        outputSpeech = r'期待下次与您见面,再见!'

        stop = Stop()

        return {'directives': [stop], 'outputSpeech': outputSpeech}
Beispiel #16
0
    def launch_request(self):
        """
        打开调用名
        """

        self.wait_answer()
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(self.WELCOM_TIPS)
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        outputSpeech = r'欢迎聆听动物声音,请告诉我您想听什么动物的叫声呢?'

        return self.getResponse(outputSpeech, renderTemplate, outputSpeech)
Beispiel #17
0
    def end_request(self):
        """
        清空状态,结束会话
        """

        self.wait_answer()
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(self.WELCOM_TIPS)
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        outputSpeech = r'期待下次与您见面,再见!'

        return self.getResponse(outputSpeech, renderTemplate, outputSpeech)
Beispiel #18
0
    def launch_request(self):
        """
        打开调用名
        """

        self.wait_answer()
        template = BodyTemplate1()
        template.set_title('查询个税')
        template.set_plain_text_content('欢迎进入查询个税')
        template.set_background_image('https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1532350870263&di=c93edb2fb9a3cfe7a632acc46cceba62&imgtype=0&src=http%3A%2F%2Ffile25.mafengwo.net%2FM00%2F0A%2FAC%2FwKgB4lMC26CAWsKoAALb5778DWg60.rbook_comment.w1024.jpeg')
        template.set_token('0c71de96-15d2-4e79-b97e-e52cec25c254')
        renderTemplate = RenderTemplate(template)
        return {
            'directives': [renderTemplate],
            'outputSpeech': r'欢迎进入查询个税,请告诉我你所在的城市是哪里呢'
        }
Beispiel #19
0
    def launch_request(self):
        """
        打开调用名
        """
        self.wait_answer()
        content = self.WELLCOM_TIPS
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(content)
        template.set_background_image(self.ICON_URL)
        template.set_token(self.BODY_TEMPLATE1_TOKEN)
        renderTemplate = RenderTemplate(template)

        card = self.getCard(self.WELLCOM_TIPS)
        card.set_anchor(self.ICON_URL, self.TITLE)

        return self.getResponse(content, card, renderTemplate)
Beispiel #20
0
    def launch_request(self):
        """
        打开调用名
        """

        self.wait_answer()
        template = BodyTemplate1()
        template.set_title(self.TITLE)
        template.set_plain_text_content(self.WELCOM_TIPS)
        template.set_background_image(self.ICON_URL)
        renderTemplate = RenderTemplate(template)

        hints = self.getHints()
        outputSpeech = r'你可以对我说播放猫的叫声?'

        return self.getResponse(outputSpeech, renderTemplate, hints,
                                outputSpeech)
Beispiel #21
0
 def launch_request(self):
     """
     打开调用名
     """
     self.wait_answer()
     template = BodyTemplate1()
     template.set_title('智能导购')
     template.set_plain_text_content('欢迎进入智能导购')
     template.set_background_image(
         'http://dbp-resource.gz.bcebos.com/ed4f7f94-fee0-cecf-344e-f4792d94406a/ai_guide_icon.png?authorization=bce-auth-v1%2Fa4d81bbd930c41e6857b989362415714%2F2018-09-06T06%3A07%3A01Z%2F-1%2F%2F16927c417355bb40cb810fe87afbcf2634f94a386781003d8ce93090fa036262'
     )
     template.set_token('0c71de96-15d2-4e79-b97e-e52cec25c254')
     renderTemplate = RenderTemplate(template)
     card = self.getCard('欢迎进入智能导购')
     return {
         'card': card,
         'directives': [renderTemplate],
         'outputSpeech': r'欢迎进入智能导购'
     }
Beispiel #22
0
 def ai_dueros_common_default_intent_intent(self):
     self.wait_answer()
     query = self.request.get_query()
     # self.utils.save_user_query(query)
     couplet_list, find_content = self.utils.get_couplet(
         None, query, None, 3)
     foot = u'你可以对我说: 小度小度' + random.choice(self.common_dialog)
     if couplet_list.__len__() > 0:
         content, outputSpeech = self.get_ssml_content(
             couplet_list, '', foot)
     else:
         content = foot
         outputSpeech = content
     template = BodyTemplate1()
     template.set_title(self.TITLE)
     template.set_plain_text_content(content)
     template.set_background_image(self.BACKGROUD_URL)
     renderTemplate = RenderTemplate(template)
     return self.getResponse(content, renderTemplate, outputSpeech)
    def launch_handler(self):
        """
        处理-打开技能
        :return:
        """
        self.wait_answer()
        template = ListTemplate2()
        template.set_title('樱花动漫-首页')
        template.set_background_image(
            "http://dbp-resource.cdn.bcebos.com/a3b2b130-c212-2241-294f-e13597c9dcc9/WeChat%20Image_20200508190042.jpg"
        )

        template = self.load_main_page(template)

        directive = RenderTemplate(template)

        return {
            'directives': [directive],
            'outputSpeech': r'欢迎使用樱花动漫,在这里你可以找到各种你喜欢看的动漫哦~'
        }
Beispiel #24
0
    def handle_move_help(self):
        self.wait_answer()
        template = BodyTemplate1()
        template.set_background_image(BG)
        content = '技能帮助如下:\n' \
                  '第一:您要先选择查看哪个城市的影讯,比如:"查看北京的"。\n' \
                  '第二:之后选择查看哪部电影的信息,比如:"查看第一个".\n' \
                  '第三:您可以查看选中电影的主要演员列表和预告片,比如:"查看演员列表或者播放预告片"\n' \
                  '第四:如果您想回到列表页面,可以对我说:"返回列表页"\n'
        template.set_plain_text_content(content)
        directive = RenderTemplate(template)

        hint = Hint(['查看北京的'])
        directives = []
        directives.append(hint)
        directives.append(directive)

        return {
            'directives': directives,
            'outputSpeech':
            content + '您可以在任何时候对我说:"帮助" 来获取帮助信息。现在请您告诉我要查看哪个城市的影讯'
        }
Beispiel #25
0
    def getAnimalResponse(self, animal):
        name = Utils.getName(animal)
        content = Utils.getDescribtion(animal)
        imgUrl = Utils.getImageUrl(animal)
        soundUrl = Utils.getSoundUrl(animal)

        self.set_session_attribute('name', name, None)

        play = Play(soundUrl, PlayBehaviorEnum.REPLACE_ALL)

        playerInfo = PlayerInfo()

        playpause = PlayPauseButton()
        previous = PreviousButton()
        next = NextButton()

        previous.set_selected(True)

        controls = [previous, playpause, next]
        playerInfo.set_controls(controls)
        playerInfo.set_title(name)
        playerInfo.set_title_subtext1(content)
        playerInfo.set_art(imgUrl)
        play.set_player_info(playerInfo)

        template = BodyTemplate3()
        template.set_title(name)
        template.set_plain_content(content)
        template.set_image(Utils.getImageUrl(animal))
        template.set_background_image(Utils.getImageUrl(animal))

        renderTemplate = RenderTemplate(template)
        outputSpeech = name

        return {
            'directives': [play],
            'reprompt': content,
            'outputSpeech': outputSpeech
        }
Beispiel #26
0
class RenderTemplateTest(unittest.TestCase):
    '''
    测试卡片
    '''
    def setUp(self):
        self.template = BodyTemplate2()
        self.template.set_plain_content('plain context by set')
        self.template.set_image('http://image-uri.com', '123', '234')
        self.renderTemplate = RenderTemplate(self.template)

    def testGetData(self):

        data = self.renderTemplate.get_data()
        print(type(data))
        data['template']['token'] = 'token'
        print(data)
        ret = {
            'type': 'Display.RenderTemplate',
            'template': {
                'type': 'BodyTemplate2',
                'token': 'token',
                'content': {
                    'type': 'PlainText',
                    'text': 'plain context by set'
                },
                'image': {
                    'url': 'http://image-uri.com',
                    'widthPixels': '123',
                    'heightPixels': '234'
                }
            }
        }

        self.assertEqual(data, ret)

    pass
Beispiel #27
0
    def build_play_list_by_id_1(self):
        datas = fetch_data()
        template = ListTemplate3()
        template.set_title("sdasdfas")
        template.set_background_image(BG)
        index = 0
        for data in datas:
            item = ListTemplateItem()
            # item.set_plain_primary_text(data['audio_name'])
            item.set_image(BG)
            item.set_content(data['audio_name'])
            # if index % 2 == 0:
            #     tag = AuditionTag()
            #     item.set_image_tags(tag)
            # AudioItem(data['audio_name'], data['audio_name'])
            # item.set_favorited(False)
            token = 'playlist:%s' % index
            item.set_token(token)
            index = index + 1
            # directive.add_audio_item(item)
            template.add_item(item)
        directive = RenderTemplate(template)

        return {'directives': [directive]}
Beispiel #28
0
 def setUp(self):
     self.template = BodyTemplate2()
     self.template.set_plain_content('plain context by set')
     self.template.set_image('http://image-uri.com', '123', '234')
     self.renderTemplate = RenderTemplate(self.template)
Beispiel #29
0
    def __baseCommon(self,
                     one,
                     two,
                     result,
                     resultIndex,
                     random1,
                     random2,
                     cType,
                     cRange,
                     listTemplate2,
                     notify=''):

        item1 = ListTemplateItem()
        item1.set_plain_primary_text('等于%s吗' % random1)
        item1.set_image(nums[random1])

        item2 = ListTemplateItem()
        item2.set_plain_primary_text('等于%s吗' % random2)
        item2.set_image(nums[random2])

        item3 = ListTemplateItem()
        item3.set_plain_primary_text('等于%s吗' % result)
        item3.set_image(nums[result])

        self.set_session_attribute('one', one, 0)
        self.set_session_attribute('two', two, 0)
        self.set_session_attribute('result', result, result)
        self.set_session_attribute('index', resultIndex, resultIndex)
        self.set_session_attribute('random1', random1, 0)
        self.set_session_attribute('random2', random2, 0)
        self.set_session_attribute('type', cType, '加法')
        self.set_session_attribute('range', cRange, 10)

        if resultIndex == 1:
            item3.set_token('1')
            item1.set_token('2')
            item2.set_token('3')
            listTemplate2.add_item(item3)
            listTemplate2.add_item(item1)
            listTemplate2.add_item(item2)
        elif resultIndex == 2:
            item1.set_token('1')
            item3.set_token('2')
            item2.set_token('3')
            listTemplate2.add_item(item1)
            listTemplate2.add_item(item3)
            listTemplate2.add_item(item2)
        elif resultIndex == 3:
            item1.set_token('1')
            item2.set_token('2')
            item3.set_token('3')
            listTemplate2.add_item(item1)
            listTemplate2.add_item(item2)
            listTemplate2.add_item(item3)

        if cType == '加法':
            listTemplate2.set_title('%s + %s = ?' % (one, two))
            self.set_session_attribute(
                'speech',
                '<speak><say-as type="number:ordinal">%s</say-as> 加 <say-as type="number:ordinal">%s</say-as> 等于多少呢</speak>'
                % (one, two), '')

            if notify:
                speech = '<speak>%s<say-as type="number:ordinal">%s</say-as> 加 <say-as type="number:ordinal">%s</say-as> 等于多少呢</speak>' % (
                    notify, one, two)
            else:
                speech = '<speak><say-as type="number:ordinal">%s</say-as> 加 <say-as type="number:ordinal">%s</say-as> 等于多少呢</speak>' % (
                    one, two)
        elif cType == '减法':
            if one >= two:
                tuples = (one, two)
            else:
                tuples = (two, one)

            listTemplate2.set_title('%s - %s = ?' % tuples)
            if notify:
                speech = '<speak>%s<say-as type="number:ordinal">%s</say-as> 减 <say-as type="number:ordinal">%s</say-as> 等于多少呢</speak>' % (
                    notify, tuples[0], tuples[1])
            else:
                speech = '<speak><say-as type="number:ordinal">%s</say-as> 减 <say-as type="number:ordinal">%s</say-as> 等于多少呢</speak>' % tuples
            self.set_session_attribute('speech', speech, '')
        template = RenderTemplate(listTemplate2)
        reprompt = '趣味计算没有听懂,可以直接对我说帮助'
        hint = Hint(['第x个或我说等于x', '做10以内的减法'])
        return {
            'outputSpeech': speech,
            'reprompt': reprompt,
            'directives': [hint, template]
        }