Exemplo n.º 1
0
    def welcome(self):

        card = TextCard('看图猜成语')
        card.setTitle('看图猜成语引导')
        card.addCueWords("我想猜成语")
        card.addCueWords("开始猜成语")
        card.addCueWords("开始看图猜成语")
        card.setContent("欢迎使用看图猜成语", "说出开始猜成语即可开始", "想出答案以后说出“我认为答案是......”或“答案是”")
        return {
            'card': card
        }
Exemplo n.º 2
0
    def NetPositions(self):
        self.wait_answer()
        openApi = OpenApi(self.token)
        netPosition = openApi.NetPositions()
        instrumentCount = netPosition.InstrumentCount
        pnl = netPosition.PnL
        cost = netPosition.Cost

        balance = OpenApi(self.token).Balance()
        marginPnl = balance.UnrealizedMarginProfitLoss
        nonMarginVal = balance.NonMarginPositionsValue
        exposure = balance.MarginNetExposure
        coverage = balance.MarginExposureCoveragePct

        remark = '风险低'
        if coverage <= 100:
            remark = '覆盖率比较低'

        content = "你有{0}支产品的仓位,股票等非保证金产品市值{1}欧元, 保证金产品风险敞口{2}欧元".format(instrumentCount, nonMarginVal, exposure)
        if instrumentCount == 0:
            content = '目前没有持仓'
        elif exposure > 0:
            content = content + ',目前保证金比率为{0}%, {1}'.format(coverage, remark)
        
        renderTemplate = self.getTemplate( content, "查仓位")
        card = TextCard(content)
        return {
                'card': card,
                'outputSpeech': content
            }
Exemplo n.º 3
0
 def launch_request(self):
     """
     打开技能
     """
     self.wait_answer()
     card = TextCard('欢迎使用我来查税')
     return {'card': card, 'outputSpeech': r'欢迎使用我来查税'}
Exemplo n.º 4
0
 def launchRequest(self):
     '''
     打开调用名
     '''
     self.wait_answer()
     card = TextCard('欢迎来到猜数字游戏')
     self.add_expect_text_response('我猜4')
     return {'card': card, 'outputSpeech': r'欢迎来到猜数字游戏'}
Exemplo n.º 5
0
 def controlRequest(self):
     self.ask('deviceName')
     # deviceName = self.getSlots('deviceName')
     # print('deviceName %s' % (deviceName))
     return {
         'card': TextCard('请告诉您的指令,比如调小空调风速、设置温度为30度'),
         'outputSpeech': '请告诉您的指令,比如调小空调风速、设置温度为30度'
     }
Exemplo n.º 6
0
Arquivo: Animal.py Projeto: twlar/AI
    def game_start_intent(self):
        self.nlu.ask('answer')
        self.int_game()
        self.set_session_attribute('score', '0', '0')

        question = self.populate_game_question()
        card = TextCard(question)
        return {'card': card, 'outputSpeech': question}
Exemplo n.º 7
0
    def ai_dueros_common_next_intent_intent(self):

        index = random.randint(0, len(quotations))
        content = quotations[index]
        card = TextCard(content)

        hint = Hint(['再来一个', '换一个', '换个', '再来一个'])
        return {'card': card, 'directives': [hint], 'outputSpeech': content}
Exemplo n.º 8
0
 def launchRequest(self):
     '''
     打开调用名
     '''
     card = TextCard('欢迎来到猜数字游戏')
     return {
         'card' : card,
         'outputSpeech': r'欢迎来到猜数字游戏'
     }
Exemplo n.º 9
0
Arquivo: Animal.py Projeto: twlar/AI
    def launch_request(self):
        """
        打开技能
        """
        self.wait_answer()

        text = r'小朋友,欢迎来到动物之最。我说最什么的动物,你来猜。准备好了吗?请说开始'
        card = TextCard(text)
        return {'card': card, 'outputSpeech': text}
Exemplo n.º 10
0
    def intentRequest(self):
        self.ask('deviceName')

        card = TextCard('您要查找什么智能设备呢? 比如"查找我的空调"')
        card.addCueWords("百度")
        card.addCueWords("百度")
        card.addCueWords("百度")
        card.setAnchor("http://www.baidu.com", "百度")
        return {
            'card': card,
            'outputSpeech': '<speak>您要查找什么智能设备呢? 比如"查找我的空调"</speak>'
        }
Exemplo n.º 11
0
 def launch_request(self):
     """
     打开技能
     """
     self.wait_answer()
     card = TextCard('欢迎使用技能')
     return {
         'card': card,
         'outputSpeech': r'欢迎使用数字魔法,游戏开始后,需要在5次内猜中,准备好后,请说开始...'
     }
Exemplo n.º 12
0
 def launch_request(self):
     """
     打开技能
     """
     self.wait_answer()
     welcome = r'欢迎来到古诗问答。我将念两句古诗并给你四个诗人的名字。需要你告诉我哪一个是正确的作者。'
     card = TextCard(welcome)
     return {
         'card': card,
         'outputSpeech': welcome + r'是否现在开始答题?'
     }
Exemplo n.º 13
0
    def inquiry_tax_intent(self):
        salary = self.get_slots('salaryMonthly')
        if not salary:
            self.nlu.ask('salaryMonthly')
            return {'outputSpeech': r'你一个月工资多少?'}

        loc = self.get_slots('Location')
        if not loc:
            self.nlu.ask('Location')
            return {'outputSpeech': r'你在哪里上班?'}
        card = TextCard('你的税额是100元')
        return {'card': card, 'outputSpeech': r'你的税额是100元'}
Exemplo n.º 14
0
    def testBuild(self):
        '''
        测试build方法
        :return:
        '''

        self.response.set_should_end_session(False)
        card = TextCard("测试服务")
        ret = {'card': card, 'outputSpeech': '测试服务,欢迎光临'}
        json = self.response.build(ret)

        rt = {
            "version": "2.0",
            "context": {
                "intent": {
                    "name": "intentName",
                    "score": 100,
                    "confirmationStatus": "NONE",
                    "slots": {
                        "city": {
                            "name": "city",
                            "value": "北京",
                            "score": 0,
                            "confirmationStatus": "NONE"
                        }
                    }
                }
            },
            "session": {
                "attributes": {}
            },
            "response": {
                "directives": [],
                "shouldEndSession": False,
                "card": {
                    "type": "txt",
                    "content": "测试服务"
                },
                "resource": None,
                "outputSpeech": {
                    "type": "PlainText",
                    "text": "测试服务,欢迎光临"
                },
                'reprompt': {
                    'outputSpeech': None
                }
            }
        }
        self.assertEquals(json, rt)
Exemplo n.º 15
0
 def GetApps(self):
     self.wait_answer()
     openApi = OpenApi(self.token)
     apps = openApi.GetApps()
     if apps.__len__() == 0:
         content = "目前你还没有App,可以创建一个"
     else:
         content = '现在你有{0}个App, 比如名字叫{1}的'.format( apps.__len__(), apps[0].Name)
     
     renderTemplate = self.getTemplate( content, "查App")
     card = TextCard(content)
     return {
         'card': card,
         'outputSpeech': content
     }
Exemplo n.º 16
0
 def Balance(self):
     self.wait_answer()
     balance = OpenApi(self.token).Balance()
     cashAvailable = balance.CashBalance + balance.TransactionsNotBooked
     accountValue = balance.TotalValue
     unit = "美元"
     if balance.Currency == "EUR":
         unit = "欧元"
     
     content = "账户总值: {0}{1}, 可用现金:{2}{1}".format(accountValue, unit, cashAvailable)
     renderTemplate = self.getTemplate( content, "查余额")
     card = TextCard(content)
     return {
             'card' : card,
             'outputSpeech': content
         }
Exemplo n.º 17
0
 def answer(self):
     
     answer = self.getSlots('sys.idiom')
     if not answer:
         self.nlu.ask('sys.idiom')
         card = TextCard('你的答案是什么呢')
         return {
             'card': card,
             'outputSpeech': '<speak>你的答案是什么呢?</speak>'
         }
     elif answer ==  self.imageurl[self.number][0]:
         return {
             'outputSpeech': '<speak>你答对了!真聪明!再来一道吧</speak>'
         }
     else:
         return {
             'outputSpeech': '<speak>' + '好遗憾,答错了,正确答案是:' + self.imageurl[self.number][0] + '不要气馁,再来一道' + '</speak>'
         }
Exemplo n.º 18
0
class TextCardTest(unittest.TestCase):
    '''
    TextCard单元测试
    '''
    def setUp(self):
        self.card = TextCard('这是TextCard')

    def testAddCueWords(self):
        '''
        测试添加关键字
        :return:
        '''
        self.card.add_cue_words(['cuewords1', 'cuewords2'])
        card = {
            'type': 'txt',
            'content': '这是TextCard',
            'cueWords': ['cuewords1', 'cuewords2']
        }
        self.assertEquals(self.card.get_data(), card)

    def testSetAnchor(self):
        '''
        测试setAnchor方法
        :return:
        '''
        self.card.set_anchor('http://www.baidu.com', '百度')
        card = {
            'type': 'txt',
            'content': '这是TextCard',
            'url': 'http://www.baidu.com',
            'anchorText': '百度'
        }
        self.assertEquals(self.card.get_data(), card)

    def testGetData(self):
        '''
        测试getData方法
        :return:
        '''
        card = {
            'type': 'txt',
            'content': '这是TextCard',
        }
        self.assertEquals(self.card.get_data(), card)

    pass
Exemplo n.º 19
0
    def preprocess(self, bot):
        if not self.threshold:
            return

        # NLU尝试slot提取,异常次数
        da_exception = bot.getSlots('da_system_not_understand')
        # bot 自身slot检查,不合法次数
        bot_exception = bot.getSlots('bot_not_understand')
        count = 0
        if da_exception:
            count = count + da_exception

        if bot_exception:
            count = count + bot_exception

        if count >= self.threshold:
            bot.clear_session_attribute()
            bot.end_session()
            card = TextCard(self.tip)
            return {'card': card}
Exemplo n.º 20
0
    def preprocess(self, bot):
        if (not self.threshold):
            return

        # NLU尝试slot提取,异常次数
        daException = bot.getSlots('da_system_not_understand')
        # bot 自身slot检查,不合法次数
        botException = bot.getSlots('bot_not_understand')
        count = 0
        if (daException):
            count = count + daException

        if (botException):
            count = count + botException

        if (count >= self.threshold):
            bot.clearSessionAttribute()
            bot.endDialog()
            card = TextCard(self.tip)
            return {'card': card}
Exemplo n.º 21
0
    def CreateApp(self):
        self.wait_answer()
        openApi = OpenApi(self.token)
        name = self.get_slots('name')
        if not name:
            self.ask('name')
            return {
                'outputSpeech': '请告诉我App的名称',
                'reprompt': '请告诉我App的名称'
            }

        openApi.CreateApp(name)
        ret = self.GetApps()
        
        content = '创建完成。' + ret['outputSpeech']
        renderTemplate = self.getTemplate( content, "创建App")
        card = TextCard(content)
        return {
            'card': card,
            'outputSpeech': content
        }
Exemplo n.º 22
0
    def Trade(self):
        self.wait_answer()
        uic = self.get_slots('Instrument')
        action = self.get_slots('Actions')
        if not uic:
            self.nlu.ask('Instrument')
            renderTemplate = self.getTemplate(r'需要买什么', '')

            return {
                'directives': [renderTemplate],
                'reprompt': r'需要买什么',
                'outputSpeech': r'需要买什么'
            }

        assetType = self.get_slots('AssetType')
        if not assetType:
            assetType = 'FxSpot';
        
        amount = self.get_slots('Amount')
        if not amount:
            amount = self.get_slots('Quantity')
            if not amount:
                amount = 1000;

        openApi = OpenApi(self.token)
        accountKey = openApi.Accounts()[0].AccountKey
        ret = openApi.TradeAsMarket( uic, amount, assetType, accountKey, action)
        orderId = ret.OrderId

        content = "小宝已下交易指令,指令编号:" + orderId
        renderTemplate = self.getTemplate( content, "下指令")
        card = TextCard(content)
        return {
                'card': card,
                'outputSpeech': content
            }
Exemplo n.º 23
0
    def getInfoPrice(self):
        self.wait_answer()
        uic = self.get_slots('Instrument')
        if not uic:
            self.nlu.ask('Instrument')
            renderTemplate = self.getTemplate(r'需要查哪个产品', '')

            return {
                'directives': [renderTemplate],
                'reprompt': r'需要查哪个产品',
                'outputSpeech': r'需要查哪个产品'
            }

        result = self.QueryInfoPrice(uic)
        title = '{0} - {1}\n'.format( result['time'], result['name'])
        content = title
        for prop in result['props']:
            content = content + '{0} {1}\n'.format(prop['name'], prop['value'])
        renderTemplate = self.getTemplate(content, title)
        card = TextCard(content)
        return {
            'card': card,
            'outputSpeech': content
        }
Exemplo n.º 24
0
 def launchRequest(self):
     return {
         'card': TextCard(r'欢迎使用家居控制!请告诉我您要查找什么智能设备,比如查找我的空调'),
         'outputSpeech': r'<speak>欢迎使用家居控制!请告诉我您要查找什么智能设备,比如查找我的空调</speak>'
     }
Exemplo n.º 25
0
 def setUp(self):
     self.card = TextCard('这是TextCard')
Exemplo n.º 26
0
 def inquiry(self):
     return {
         'card': TextCard('请告诉您的指令,比如调小空调风速、设置温度为30度'),
         'outputSpeech': '请告诉您的指令,比如调小空调风速、设置温度为30度'
     }
Exemplo n.º 27
0
 def getCard(self, content):
     card = TextCard(content)
     return card