rahgadda's picture
Initial Draft
3024ca5 verified
raw
history blame
1.32 kB
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')