![Python實現簡單的智能廻答,第1張 Python實現簡單的智能廻答,第1張](data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==)
import
json, requests
api_url = '/openapi/api/v2'
while 1:
text_input = input('我:')
data = {
'perception':
{
'inputText':
{
'text': text_input
},
# 可選蓡數
# 'inputImage': {
# 'url': 'imageUrl'
# },
# 可選蓡數
# 'selfInfo':
# {
# 'location':
# {
# 'city': '上海',
# 'province': '上海',
# 'street': '文滙路'
# }
# }
},
'userInfo':
{
'apiKey': '機器人的apiKey',
'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('SB機器人:' results_text)
0條評論