-
Notifications
You must be signed in to change notification settings - Fork 202
/
ais_cli.py
38 lines (30 loc) · 1.17 KB
/
ais_cli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
"""
This is the client to public AIs' API for voice_assistant.
"""
import requests
class tuling123(object):
def __init__(self, user_id, api_key, base_url='http://openapi.tuling123.com/openapi/api/v2'):
self._session = requests.Session()
self._base_url = base_url
self._base_data = { 'reqType': 0,
'userInfo': {
'apiKey': api_key,
'userId': user_id
},
'perception': {
'inputText': {
'text': ''
}
}
}
def command(self, input_sentence):
data = self._base_data
data['perception']['inputText']['text'] = input_sentence
r = self._session.post(url=self._base_url, json = data)
output = r.json()
ouput_sentence = None
for result in output['results']:
if result['resultType']=='text':
ouput_sentence = result['values']['text']
break
return(ouput_sentence)