Spaces:
Sleeping
Sleeping
bigwolfe
commited on
Commit
·
1a2df94
1
Parent(s):
92d421d
bugs
Browse files
backend/src/api/routes/rag.py
CHANGED
|
@@ -2,6 +2,11 @@ from fastapi import APIRouter, Depends, HTTPException, status
|
|
| 2 |
from ..middleware import AuthContext, get_auth_context
|
| 3 |
from ...models.rag import ChatRequest, ChatResponse, StatusResponse
|
| 4 |
from ...services.rag_index import RAGIndexService
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
router = APIRouter(prefix="/api/rag", tags=["rag"])
|
| 7 |
|
|
@@ -17,31 +22,21 @@ async def get_status(
|
|
| 17 |
return rag_service.get_status(auth.user_id)
|
| 18 |
|
| 19 |
@router.post("/chat", response_model=ChatResponse)
|
| 20 |
-
|
| 21 |
async def chat(
|
| 22 |
-
|
| 23 |
request: ChatRequest,
|
| 24 |
-
|
| 25 |
auth: AuthContext = Depends(get_auth_context),
|
| 26 |
-
|
| 27 |
rag_service: RAGIndexService = Depends(get_rag_service)
|
| 28 |
-
|
| 29 |
):
|
| 30 |
-
|
| 31 |
"""
|
| 32 |
-
|
| 33 |
Chat with the vault RAG agent.
|
| 34 |
-
|
| 35 |
"""
|
| 36 |
-
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
return await rag_service.chat(auth.user_id, request.messages)
|
| 40 |
-
|
| 41 |
except ValueError as e:
|
| 42 |
-
|
| 43 |
raise HTTPException(status_code=400, detail=str(e))
|
| 44 |
-
|
| 45 |
except Exception as e:
|
| 46 |
-
|
|
|
|
|
|
|
| 47 |
raise HTTPException(status_code=500, detail=f"RAG Error: {str(e)}")
|
|
|
|
|
|
| 2 |
from ..middleware import AuthContext, get_auth_context
|
| 3 |
from ...models.rag import ChatRequest, ChatResponse, StatusResponse
|
| 4 |
from ...services.rag_index import RAGIndexService
|
| 5 |
+
import logging
|
| 6 |
+
import traceback
|
| 7 |
+
import sys
|
| 8 |
+
|
| 9 |
+
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
router = APIRouter(prefix="/api/rag", tags=["rag"])
|
| 12 |
|
|
|
|
| 22 |
return rag_service.get_status(auth.user_id)
|
| 23 |
|
| 24 |
@router.post("/chat", response_model=ChatResponse)
|
|
|
|
| 25 |
async def chat(
|
|
|
|
| 26 |
request: ChatRequest,
|
|
|
|
| 27 |
auth: AuthContext = Depends(get_auth_context),
|
|
|
|
| 28 |
rag_service: RAGIndexService = Depends(get_rag_service)
|
|
|
|
| 29 |
):
|
|
|
|
| 30 |
"""
|
|
|
|
| 31 |
Chat with the vault RAG agent.
|
|
|
|
| 32 |
"""
|
|
|
|
| 33 |
try:
|
|
|
|
| 34 |
return await rag_service.chat(auth.user_id, request.messages)
|
|
|
|
| 35 |
except ValueError as e:
|
|
|
|
| 36 |
raise HTTPException(status_code=400, detail=str(e))
|
|
|
|
| 37 |
except Exception as e:
|
| 38 |
+
# Log full traceback
|
| 39 |
+
logger.exception("RAG Chat failed")
|
| 40 |
+
traceback.print_exc(file=sys.stderr)
|
| 41 |
raise HTTPException(status_code=500, detail=f"RAG Error: {str(e)}")
|
| 42 |
+
|