How Python invokes the API for smart reply functionality

Source: Internet
Author: User
This time for you to bring Python how to invoke the API to implement the smart Reply function, Python Call API to implement the Smart Reply function of the note, the following is the actual case, together to see.

The example of this article for everyone to share the Python call API implementation of the specific code of the robot, for your reference, the specific content as follows

Precautions:

The Apikey in the following code needs to be replaced

Need to have their own public number platform, and become an administrator,

Http://www.tuling123.com

To have an account on this website and create a bot, you can get apikey in the Help center and fill in the code below.

#图灵机器人 def talks_robot (info = ' What's your Name '):   api_url = ' Http://www.tuling123.com/openapi/api '   apikey = ' 4fede3c4384846b9a7d0456a5e1e2943 '   data = {' key ': Apikey,         ' info ': info}   req = Requests.post (Api_url, Data= Data). Text   Replys = json.loads (req) [' text ']   return replys  #自动回复 robot = Bot () # Reply to messages from other friends, group chats and public numbers @ Robot.register () def reply_my_friend (msg):   message = ' {} '. Format (msg.text)   replys = Talks_robot (info=message )   return replys  # start listening and automatically process messages Robot.start ()

Alternatively, you can use the following code:

#-*-Coding:utf-8-*-Import requests Import Itchat # This is a library for reply  key = ' 8edce3ce905a4c1dbb965e6b35c3834d ' # This key can be straight To   send a request with # to the API Def get_response (msg):   apiurl = ' Http://www.tuling123.com/openapi/api '   data = {     ' key ' : KEY,     ' info ': msg,     ' userid ': ' Pth-robot ',   }   try:     r = Requests.post (Apiurl, Data=data). JSON ()     return r.get (' text ')   except:     return  # Registration method @itchat. Msg_register (Itchat.content.TEXT) def Tuling_reply (msg):   # In order to ensure that there is a problem in Turing key can still reply, here set a default reply   defaultreply = ' I Received: ' + msg[' Text ']   # If there is a problem with Turing key, then reply will be none   reply = Get_response (msg[' Text ")   # A or b means, if a has content, then return a, otherwise return B returns   Reply or defaultreply   # in order to have the modifier not be scanned multiple times, use hot start Itchat.auto_login (hotreload=true) Itchat.run ()

Above the two ends of the code to use one paragraph, the recent use, confirm the available

After the code is run, a QR code interface will pop up, scanning and waiting for a period of time.

At this time, their own operation of the public number will have a smart reply function, in the background to the public number directly to send information, he will be smart reply.

Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!

Recommended reading:

How object is converted to float data

2018 PHP Real-Combat development function Summary Daquan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.