-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
64 lines (47 loc) · 1.66 KB
/
app.py
File metadata and controls
64 lines (47 loc) · 1.66 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask, request, jsonify
import kb_agent
import json
app = Flask(__name__)
@app.route('/', methods=['GET'])
def hello():
return 'hello'
@app.route('/user_access', methods=['GET', 'POST'])
def user_access():
data = request.data.decode('utf-8')
myjson = json.loads(data)
user_id = None
user_name = None
if 'user_id' in myjson:
user_id = myjson['user_id']
if 'user_name' in myjson:
user_name = myjson['user_name']
if user_id is None and user_name is None:
return "ERROR: input user_id or user_name"
return kb_agent.user_access(user_name=user_name, user_id=user_id)
@app.route('/respond_to_user_utterance', methods=['GET', 'POST'])
def respond_to_user_utterance():
data = request.data.decode('utf-8')
myjson = json.loads(data)
user_id = None
user_name = None
user_utterance = None
session_id = None
if 'user_id' in myjson:
user_id = myjson['user_id']
if 'user_name' in myjson:
user_name = myjson['user_name']
if user_id is None and user_name is None:
return "ERROR: input user_id or user_name"
if 'user_utterance' in myjson:
user_utterance = myjson['user_utterance']
else:
return "ERROR: input user_utterance"
if 'session_id' in myjson:
session_id = myjson['session_id']
if 'modules' in myjson:
modules = myjson['modules']
else:
modules = []
return kb_agent.respond_to_user_utterance(user_id=user_id, user_name=user_name, user_utterance=user_utterance, session_id=session_id, modules=modules)
if __name__ == "__main__":
app.run(port=8292, host='143.248.135.146', threaded=False)