-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.py
51 lines (38 loc) · 1.57 KB
/
routes.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
from flask_cors import CORS
from flask import Blueprint, json, jsonify, request
from ai import VectorDB
from ai import Model
blueprint = Blueprint('routes', __name__)
@blueprint.route('/test', methods=['GET'])
def test():
return jsonify({'message': 'Hello, World!' , 'data' : "data" })
@blueprint.route('/ingest', methods=['POST'])
def ingest_data():
data = json.loads(request.data)
db = VectorDB()
if data['doctype'] not in ['health', 'finance']:
return jsonify({'message': 'Invalid doctype'}), 400
db.add(data)
return jsonify({'message': 'Data ingested successfully'})
@blueprint.route('/search', methods=['POST'])
def get_data():
data = json.loads(request.data)
db = VectorDB()
res = db.search(data['query'], data['user'])
return jsonify({"message": "Data retrieved successfully", "data": res})
@blueprint.route('/chat', methods=['POST'])
def chat():
data = json.loads(request.data)
print(data['user'])
if data['user'] not in ['doctor', 'admin', 'dean', 'nurse', 'finance']:
return jsonify({'message': 'Invalid user'}), 400
model = Model()
res = model.rag(data['content'], data['user'])
return jsonify({"message": "Chat response retrieved successfully", "data": res})
# @blueprint.route('/test', methods=['POST'])
# def test():
# data = json.loads(request.data)
# if data['user'] not in ['doctor', 'admin', 'dean', 'nurse', 'finance']:
# return jsonify({'message': 'Invalid user'}), 400
# res = data
# return jsonify({"message": "Chat response retrieved successfully", "data": res})