-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
70 lines (63 loc) · 1.54 KB
/
app.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# imports
import qna
import knowbase
from flask import Flask, request, jsonify
from flask_cors import CORS
# app setup
app = Flask(__name__)
CORS(app, support_credentials=True)
# endpoints
# default endpoint
@app.route('/', methods=['GET'])
def default_endpoint():
res = jsonify({
"success": True
})
return res
# post a question | respond with answer
@app.route('/answer/ask', methods=['POST'])
def question():
try:
req = request.json
ans = qna.ask(req['question'])
return jsonify({
'success': True,
'answer': ans
})
except:
return jsonify({
'success': False,
})
# post a question | respond with top 3 matches
@app.route('/answer/search', methods=['POST'])
def search_ans():
try:
req = request.json
results = qna.search(req['question'])
return jsonify({
'success': True,
'answer': results
})
except:
return jsonify({
'success': False,
})
# post a qna | add a new qna to kb
@app.route('/kb/new', methods=['POST'])
def new_qna():
req = request.json
msg = knowbase.addNewQNA(req['question'], req['answer'])
return jsonify({
'success': msg,
})
# post a question and id | add a new question
@app.route('/kb/update', methods=['POST'])
def update_qna():
req = request.json
msg = knowbase.updateQNA(req['qid'], req['question'])
return jsonify({
'success': msg
})
# main
if __name__ == "__main__":
app.run(debug=True)