本文整理汇总了Python中ai.AI.respond方法的典型用法代码示例。如果您正苦于以下问题:Python AI.respond方法的具体用法?Python AI.respond怎么用?Python AI.respond使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.AI
的用法示例。
在下文中一共展示了AI.respond方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_text
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import respond [as 别名]
def process_text(self):
bot = AI(self.msg)
print self.msg
result = bot.respond(self.msg.content)
if options.debug:
logging.info('bot response %s',result)
if isinstance(result, list):
return ObjectDict(msg_type=MSG_TYPE_NEWS,response=result)
else:
return ObjectDict(msg_type=MSG_TYPE_TEXT,response=sender.decode(result))
示例2: post
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import respond [as 别名]
def post(self):
signature = self.get_argument('signature', '')
timestamp = self.get_argument('timestamp', '')
nonce = self.get_argument('nonce', '')
try:
check_signature(options.token, signature, timestamp, nonce)
except InvalidSignatureException:
logging.warning("Signature check failed.")
return
self.set_header("Content-Type", "application/xml;charset=utf-8")
body = self.request.body
msg = parse_message(body)
if not msg:
logging.info('Empty message, ignored')
return
# new bot
bot = AI(msg)
if msg.type == 'text':
if options.debug:
logging.info('message type text from %s', msg.source)
response = bot.respond(msg.content, msg)
reply = create_reply(response, msg, render=True)
self.write(reply)
if options.debug:
logging.info('Replied to %s with "%s"', msg.source, response)
elif msg.type == 'location':
if options.debug:
logging.info('message type location from %s', msg.source)
elif msg.type == 'image':
if options.debug:
logging.info('message type image from %s', msg.source)
else:
logging.info('message type unknown')
示例3: post
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import respond [as 别名]
def post(self):
if not self.check_signature():
logging.warning("Signature check failed.")
return
self.set_header("Content-Type", "application/xml;charset=utf-8")
body = self.request.body
msg = wechat.parse_user_msg(body)
if not msg:
logging.info('Empty message, ignored')
return
self.touser = msg.touser
self.fromuser = msg.fromuser
# new bot
bot = AI(msg)
if msg.type == wechat.MSG_TYPE_TEXT:
if options.debug:
logging.info('message type text from %s', msg.fromuser)
response = bot.respond(msg.content, msg)
reply = wechat.generate_reply(msg.touser, msg.fromuser, response)
self.write(reply)
if options.debug:
logging.info('Replied to %s with "%s"', msg.fromuser, response)
elif msg.type == wechat.MSG_TYPE_LOCATION:
if options.debug:
logging.info('message type location from %s', msg.fromuser)
elif msg.type == wechat.MSG_TYPE_IMAGE:
if options.debug:
logging.info('message type image from %s', msg.fromuser)
else:
logging.info('message type unknown')