Spaces:
Sleeping
Sleeping
Commit
·
ba6916c
1
Parent(s):
6424c78
- backend/main.py +18 -3
- nginx.conf +2 -0
backend/main.py
CHANGED
@@ -583,15 +583,30 @@ def rag_chain_depender(app: FastAPI = Depends(lambda: app)) -> Any:
|
|
583 |
raise HTTPException(status_code=500, detail="RAG chain not initialized")
|
584 |
return chain
|
585 |
|
|
|
|
|
|
|
586 |
@app.post("/api/rag", response_model=RAGResponse)
|
587 |
async def ask_rag(
|
588 |
req: RAGRequest,
|
589 |
rag_chain = Depends(rag_chain_depender)
|
590 |
):
|
591 |
-
|
592 |
-
|
593 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
594 |
|
|
|
|
|
|
|
|
|
|
|
|
|
595 |
# ---------------------------------------------------------------------------- #
|
596 |
# Data Endpoints #
|
597 |
# ---------------------------------------------------------------------------- #
|
|
|
583 |
raise HTTPException(status_code=500, detail="RAG chain not initialized")
|
584 |
return chain
|
585 |
|
586 |
+
import traceback
|
587 |
+
from fastapi import HTTPException
|
588 |
+
|
589 |
@app.post("/api/rag", response_model=RAGResponse)
|
590 |
async def ask_rag(
|
591 |
req: RAGRequest,
|
592 |
rag_chain = Depends(rag_chain_depender)
|
593 |
):
|
594 |
+
try:
|
595 |
+
result = await rag_chain.acall({"question": req.query})
|
596 |
+
# make sure it really is a dict
|
597 |
+
if not isinstance(result, dict):
|
598 |
+
raise ValueError(f"Expected dict from chain, got {type(result)}")
|
599 |
+
answer = result.get("answer")
|
600 |
+
docs = result.get("source_documents", [])
|
601 |
+
sources = [d.metadata.get("id","") for d in docs]
|
602 |
+
return RAGResponse(answer=answer, source_ids=sources)
|
603 |
|
604 |
+
except Exception as e:
|
605 |
+
# print full traceback to your container logs
|
606 |
+
traceback.print_exc()
|
607 |
+
# return a proper JSON 500
|
608 |
+
raise HTTPException(status_code=500, detail=str(e))
|
609 |
+
|
610 |
# ---------------------------------------------------------------------------- #
|
611 |
# Data Endpoints #
|
612 |
# ---------------------------------------------------------------------------- #
|
nginx.conf
CHANGED
@@ -47,6 +47,8 @@ http {
|
|
47 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
48 |
proxy_cache_bypass $http_upgrade;
|
49 |
proxy_read_timeout 86400;
|
|
|
|
|
50 |
proxy_redirect off;
|
51 |
}
|
52 |
}
|
|
|
47 |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
48 |
proxy_cache_bypass $http_upgrade;
|
49 |
proxy_read_timeout 86400;
|
50 |
+
proxy_connect_timeout 86400;
|
51 |
+
proxy_send_timeout 86400;
|
52 |
proxy_redirect off;
|
53 |
}
|
54 |
}
|