In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to achieve Turing chat robot in Python". In daily operation, I believe that many people have doubts about how to achieve Turing chat robot in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to achieve Turing chat robot in Python". Next, please follow the editor to study!
Determine the goal
This time, a chat robot with artificial mental retardation is made through the API interface of Turing robot platform.
Analysis target
You need to sign up for an account before using it, and then enter this interface.
Uh. I've already created two robots.
Then randomly click on a robot to find its apikey
There is an api document at the bottom. Open it and have a look:
You can see that there are many interfaces. The first one is selected in this article. After opening it, it looks like this:
Here is the interface address of the request, followed by the description of the request method, and finally tells you the format and content of the parameters of the request.
It is simply not too convenient, that is, it is not detailed enough for how to use it, which is very sad.
The content of the parameters is not too much, and it is clearly written in that document.
Let's go straight to the code. Haha.
Code operation
Here we are only used for text chat, because I think pictures and other things are too difficult to enter url. In fact, it has many functions and can be set up in the background, but after I tried, it seems that the link is useless in the terminal. Import requests,random,json,time
Print (''
Silly Niu provides you with the following services:
1, chat dialogue 2, Chinese-English translation 3, weather inquiry
Press 886 to exit service'')
While 1: # because you type it once and reply it once, so use a loop to keep the conversation going userid = str (random.randint) # personal understanding is to simulate a lot of users to have a conversation Maybe it will be annoying to chat with one person. Haha ~ text = input ('you:') if text = = '886': # set the exit condition print ('Bye~') break url =' http://openapi.tuling123.com/openapi/api/v2' data = json.dumps ({"reqType": 0) # represents the text type "perception": {"inputText": {"text": text # is what we want to enter},}, "userInfo": {"apiKey": "96c9ccc339f54d63bfbc7f68cb8a9ecb", # this is the apikey "userId": userid}} mentioned earlier) res = requests.post (url Data) js = res.json () # because the data it returns is mes = js ['results'] [0] [' values'] ['text'] print (f' silly girl: {mes}') in json format
Effect test
At this point, the study on "how to achieve the Turing chat robot in Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.