tech5 commited on
Commit
e6b1ea5
·
1 Parent(s): e27c97c

Fix query JSON body and improve error handling

Browse files
Files changed (1) hide show
  1. backend/api.py +19 -12
backend/api.py CHANGED
@@ -136,17 +136,24 @@ class QueryRequest(BaseModel):
136
  # This Endpoint Load the VectorDataBase and answer the User question
137
  @app.post("/query")
138
  async def get_response(req: QueryRequest):
139
- vectorstore = get_vectorstore()
140
- retriever = vectorstore.as_retriever(
141
- search_type="mmr",
142
- search_kwargs={"k": 3}
143
- )
144
- chain = get_rag_chain(retriever)
145
- response = chain.invoke(req.input)
 
146
 
147
- system_stats["total_queries"] += 1
148
 
149
- return {
150
- "question": req.input,
151
- "response": response.content
152
- }
 
 
 
 
 
 
 
136
  # This Endpoint Load the VectorDataBase and answer the User question
137
  @app.post("/query")
138
  async def get_response(req: QueryRequest):
139
+ try:
140
+ vectorstore = get_vectorstore()
141
+ retriever = vectorstore.as_retriever(
142
+ search_type="mmr",
143
+ search_kwargs={"k": 3}
144
+ )
145
+ chain = get_rag_chain(retriever)
146
+ response = chain.invoke(req.input)
147
 
148
+ system_stats["total_queries"] += 1
149
 
150
+ return {
151
+ "question": req.input,
152
+ "response": response.content
153
+ }
154
+
155
+ except Exception as e:
156
+ raise HTTPException(
157
+ status_code=500,
158
+ detail=f"Query processing failed: {str(e)}"
159
+ )