-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLinaTalk.py
43 lines (31 loc) · 1.02 KB
/
LinaTalk.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
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import json
import types
KEY = '55702e566f352f5744767a71644d32796f544a58506866716b776d7569726e33544b7538427652414a7943'
#エンドポイントの設定
endpoint = 'https://api.apigw.smt.docomo.ne.jp/dialogue/v1/dialogue?APIKEY=REGISTER_KEY'
url = endpoint.replace('REGISTER_KEY', KEY)
#1回目の会話の入力
#utt_content = input('>>')
payload = {'utt' : utt_content, 'context': ''}
headers = {'Content-type': 'application/json'}
#送信
r = requests.post(url, data=json.dumps(payload), headers=headers)
data = r.json()
#jsonの解析
response = data['utt']
context = data['context']
#表示
print ("response: %s" %(response))
#2回目以降の会話(Ctrl+Cで終了)
while True:
utt_content = input('>>')
payload['utt'] = utt_content
payload['context'] = data['context']
r = requests.post(url, data=json.dumps(payload), headers=headers)
data = r.json()
response = data['utt']
context = data['context']
print ("response: %s" %(response))