Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
@@ -65,6 +65,13 @@ class HealthResponse(BaseModel):
|
|
65 |
message: str
|
66 |
components: Dict[str, str]
|
67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
# Global instances
|
69 |
rag_system: RAGSystem = None
|
70 |
session_manager: SessionManager = None
|
@@ -189,6 +196,33 @@ async def get_chat_history(session_id: str, limit: int = 10):
|
|
189 |
logger.error(f"Error getting chat history: {e}")
|
190 |
raise HTTPException(status_code=500, detail=f"Failed to get chat history: {str(e)}")
|
191 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
@app.post("/chat", response_model=ChatResponse)
|
193 |
async def chat(request: ChatRequest):
|
194 |
"""Main chat endpoint for legal questions with session support"""
|
|
|
65 |
message: str
|
66 |
components: Dict[str, str]
|
67 |
|
68 |
+
class SessionListResponse(BaseModel):
|
69 |
+
sessions: List[Dict[str, Any]]
|
70 |
+
total_count: int
|
71 |
+
limit: int
|
72 |
+
offset: int
|
73 |
+
has_more: bool
|
74 |
+
|
75 |
# Global instances
|
76 |
rag_system: RAGSystem = None
|
77 |
session_manager: SessionManager = None
|
|
|
196 |
logger.error(f"Error getting chat history: {e}")
|
197 |
raise HTTPException(status_code=500, detail=f"Failed to get chat history: {str(e)}")
|
198 |
|
199 |
+
@app.get("/sessions", response_model=SessionListResponse)
|
200 |
+
async def list_all_sessions(limit: int = 100, offset: int = 0):
|
201 |
+
"""List all sessions with pagination"""
|
202 |
+
if not session_manager:
|
203 |
+
raise HTTPException(status_code=503, detail="Session manager not initialized")
|
204 |
+
|
205 |
+
try:
|
206 |
+
# Validate parameters
|
207 |
+
if limit < 1 or limit > 1000:
|
208 |
+
raise HTTPException(status_code=400, detail="Limit must be between 1 and 1000")
|
209 |
+
|
210 |
+
if offset < 0:
|
211 |
+
raise HTTPException(status_code=400, detail="Offset must be non-negative")
|
212 |
+
|
213 |
+
result = session_manager.list_all_sessions(limit=limit, offset=offset)
|
214 |
+
|
215 |
+
if "error" in result:
|
216 |
+
raise HTTPException(status_code=500, detail=result["error"])
|
217 |
+
|
218 |
+
return SessionListResponse(**result)
|
219 |
+
|
220 |
+
except HTTPException:
|
221 |
+
raise
|
222 |
+
except Exception as e:
|
223 |
+
logger.error(f"Error listing sessions: {e}")
|
224 |
+
raise HTTPException(status_code=500, detail=f"Failed to list sessions: {str(e)}")
|
225 |
+
|
226 |
@app.post("/chat", response_model=ChatResponse)
|
227 |
async def chat(request: ChatRequest):
|
228 |
"""Main chat endpoint for legal questions with session support"""
|