File size: 1,324 Bytes
3024ca5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ae0839f
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
from flask.views import MethodView
from flask import request,Response

import json
import traceback
import logging

import lib.api.vector.VectorStore as cv

class VectorStoreAPI(MethodView):
    lv_logger = logging.getLogger(__name__)
    
    def get(self):
        resp = { "test message": "working"}
        status = 200
        return Response(json.dumps(resp), status=status, mimetype='application/json')

    def post(self):
        try:
            # Saving file
            lv_file = request.files['file']
            lv_domain = request.form['domain']
            lv_file_name = 'storage/' + lv_domain + ".xlsx"
            lv_file.save(lv_file_name)
            
            # Processing the file
            lv_status = cv.fn_create_vector_store(lv_file_name, lv_domain)

            return Response(
                                json.dumps({"status":lv_status}), 
                                status=200, 
                                mimetype='application/json'
                           )
        except Exception as e:
            self.lv_logger.error(e)
            self.lv_logger.error(type(e))
            self.lv_logger.error(traceback.format_exc())

            return Response(json.dumps({"error_message":str(e)}), status=500, mimetype='application/json')