work in progress
This commit is contained in:
parent
7b76c8cfef
commit
a217eb05f2
64
src/app.py
64
src/app.py
@ -32,6 +32,68 @@ def health_healthz():
|
||||
return jsonify("OK"), 200
|
||||
|
||||
|
||||
@app.post("/add_points")
|
||||
def add_points():
|
||||
#doc uuid and clauses: [{},{}]
|
||||
if request.content_type == 'application/json':
|
||||
try:
|
||||
data = request.get_json(force=True)
|
||||
if data is None:
|
||||
raise BadRequest
|
||||
except BadRequest:
|
||||
return jsonify({"error": "Invalid JSON"}), 400
|
||||
else:
|
||||
|
||||
data = request.form.to_dict()
|
||||
|
||||
doc_uuid=data.get("doc_uuid")
|
||||
clauses = data.get("clauses", [])
|
||||
if not doc_uuid or not clauses:
|
||||
return jsonify({"error": "Missing 'doc_uuid' or 'clauses' in request"}), 400
|
||||
|
||||
vector_points = []
|
||||
|
||||
for clause in clauses:
|
||||
clause_id = clause.get("clause_id")
|
||||
line_item = clause.get("line_item")
|
||||
line_number = clause.get("line_number")
|
||||
|
||||
if not clause_id or not line_item:
|
||||
return jsonify({"error":"Missing fileds in clause"}), 400
|
||||
|
||||
try:
|
||||
clause_vectors=Embedding.call(line_item)
|
||||
logger.info("clause_vectors STAR %s" % (clause_vectors))
|
||||
logger.info(f"type of clause_vectors: {type(clause_vectors)}")
|
||||
logger.info(f"LENGTH JOUNR of clause_vectors: {len(clause_vectors)}")
|
||||
logger.info("TEST +++++")
|
||||
except Exception as e:
|
||||
return jsonify({"error": f"Embedding failed: {str(e)}"}), 500
|
||||
|
||||
payload = {
|
||||
"doc_id": doc_uuid,
|
||||
"clause_id": clause_id,
|
||||
"line_item": line_item,
|
||||
"line_number": line_number
|
||||
}
|
||||
logger.info(f"length of clause_vectors: {len(clause_vectors)}")
|
||||
for vector in clause_vectors:
|
||||
point = PointStruct(
|
||||
id=str(uuid.uuid7()),
|
||||
vector=vector.tolist(),
|
||||
payload=payload
|
||||
)
|
||||
vector_points.append(point)
|
||||
logger.info(f"length of vector_points: {len(vector_points)}")
|
||||
try:
|
||||
result = Qdrant.get_client().upsert(
|
||||
points= vector_points
|
||||
)
|
||||
except Exception as e:
|
||||
return jsonify({"error": f"Qdrant upsert failed: {str(e)}"}), 500
|
||||
|
||||
return jsonify({"message": f"{len(vector_points)} points added successfully"}), 200
|
||||
|
||||
@app.post("/add")
|
||||
def add():
|
||||
if request.content_type == 'application/json':
|
||||
@ -61,7 +123,7 @@ def add():
|
||||
payload["user_meta"] = user_meta if isinstance(user_meta, dict) else json.loads(user_meta)
|
||||
|
||||
clause_vectors = Embedding.call(clause_text)
|
||||
|
||||
logger.info(f"clause vectors line 126: {clause_vectors}")
|
||||
result = Qdrant.get_client().upsert(
|
||||
points=[
|
||||
PointStruct(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user