def test_parse_response(self, m): """ Dialogue().parse() should parse request to api. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') ret = c.apis['Dialogue'].parse(c.last_response) self.assertTrue(isinstance(ret, dict))
def test_context(self, m): """ Dialogue().parse() should extract context. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') ret = c.apis['Dialogue'].parse(c.last_response) self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
def test_context(self, m): """ Dialogue().parse() should extract context. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') ret = c.apis['Dialogue'].parse(c.last_response) self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
def test_parse_response(self, m): """ Dialogue().parse() should parse request to api. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') ret = c.apis['Dialogue'].parse(c.last_response) self.assertTrue(isinstance(ret, dict))
def main(): args = parse_option() apikey = args.apikey if apikey is None: apikey = os.environ['DOCO_API_KEY'] if apikey is None: sys.exit(1) level = logging.INFO if args.verbose is True else logging.ERROR logging.basicConfig(level=level, format=DocoInterface.debug_log_format) shiritori = args.shiritori options = {} if shiritori is True: options['mode'] = 'srtr' if args.type is not None: options['t'] = args.type client = Client(apikey=apikey, user=options) if args.intaractive is False: if args.utt is None: sys.exit(1) res = client.send(utt=args.utt, apiname='Dialogue') write(str(res)) else: console = Console() console.client = client sys.ps1 = '>>> ' console.interact('Welcome to docomo dialogue cli.\n^D to exit.')
def docomo_response(text): docomo_client = Client(apikey=os.environ['DOCOMO_API_KEY']) response = docomo_client.send(utt=text, apiname='Dialogue') logger.debug(response) return [{"type": "text", "text": response['utt']}]
def main(): args = parse_option() apikey = args.apikey if apikey is None: apikey = os.environ['DOCO_API_KEY'] if apikey is None: sys.exit(1) level = logging.INFO if args.verbose is True else logging.ERROR logging.basicConfig(level=level, format=DocoInterface.debug_log_format) shiritori = args.shiritori options = {} if shiritori is True: options['mode'] = 'srtr' if args.type is not None: options['t'] = args.type client = Client(apikey=apikey, user=options) if args.intaractive is False: if args.utt is None: sys.exit(1) res = client.send(utt=args.utt, apiname='Dialogue') write(str(res)) else: console = Console() console.client = client sys.ps1 = '>>> ' console.interact('Welcome to docomo dialogue cli.\n^D to exit.')
def replay_chat(self, word): """ チャットを返す :param word: :return: """ c = Client(apikey=docomo_key) res = c.send(utt=word, apiname='Dialogue') return res['utt']
class DocomoDialogAPI(object): def __init__(self, api_key=None): api_key = os.environ.get('DOCOMO_DIALOGUE_API_KEY', api_key) self.__client = Client(apikey=api_key) def reply(self, text): response = self.__client.send(utt=text, apiname='Dialogue') utt = response['utt'] return utt
def test_last_response(self, m): """ Client().send() should send request to api and set response. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') self.assertEqual(c.last_response.status_code, 200)
def test_send(self, m): """ Client().send() should send request to api. """ dummy_response(m) c = Client(apikey='') ret = c.send(utt=u'ぬるぽ', apiname='Dialogue') self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')
def test_last_response(self, m): """ Client().send() should send request to api and set response. """ dummy_response(m) c = Client(apikey='') c.send(utt=u'ぬるぽ', apiname='Dialogue') self.assertEqual(c.last_response.status_code, 200)
def test_send(self, m): """ Client().send() should send request to api. """ dummy_response(m) c = Client(apikey='') ret = c.send(utt=u'ぬるぽ', apiname='Dialogue') self.assertEqual(ret['context'], 'D0yHgwljc_mhTPIGs--toQ')