翻老项目的时候翻到的,没记错的话好像是跟着一个教程整的( ̄∇ ̄)
不知道还能用不
import json, requests
api_url = "http://openapi.tuling123.com/openapi/api/v2"
while 1:
text_input = input('你:')
data = {
"perception":
{
"inputText":
{
"text": text_input
},
},
"userInfo":
{
"apiKey": '211758c0166f45218de5a5a97b5e0c67',
"userId": "AA"
}
}
data = json.dumps(data).encode('utf8')
response_str = requests.post(api_url, data=data, headers={'content-type': 'application/json'})
response_dic = response_str.json()
results_text = response_dic['results'][0]['values']['text']
print('图灵:' + results_text)