Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -263,17 +263,27 @@ def chat_with_bot(message: ChatMessage):
|
|
| 263 |
- If session_id is provided but doesn't exist: Creates a new session with that ID
|
| 264 |
- If session_id exists: Continues the existing conversation
|
| 265 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
try:
|
| 267 |
-
is_new_session = message.session_id is None
|
| 268 |
|
| 269 |
response, session_id = get_rag_response(message.query, message.session_id)
|
| 270 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
return {
|
| 272 |
"response": response,
|
| 273 |
"session_id": session_id,
|
| 274 |
"is_new_session": is_new_session
|
| 275 |
}
|
| 276 |
except Exception as e:
|
|
|
|
| 277 |
raise HTTPException(status_code=500, detail=f"Error processing chat: {str(e)}")
|
| 278 |
|
| 279 |
@app.get("/chat/{session_id}/history", response_model=ChatHistoryResponse)
|
|
|
|
| 263 |
- If session_id is provided but doesn't exist: Creates a new session with that ID
|
| 264 |
- If session_id exists: Continues the existing conversation
|
| 265 |
"""
|
| 266 |
+
print(f"📨 Received chat request:")
|
| 267 |
+
print(f" Query: {message.query}")
|
| 268 |
+
print(f" Session ID: {message.session_id}")
|
| 269 |
+
|
| 270 |
try:
|
| 271 |
+
is_new_session = message.session_id is None or message.session_id == ""
|
| 272 |
|
| 273 |
response, session_id = get_rag_response(message.query, message.session_id)
|
| 274 |
|
| 275 |
+
print(f"📤 Sending response:")
|
| 276 |
+
print(f" Session ID: {session_id}")
|
| 277 |
+
print(f" Is New Session: {is_new_session}")
|
| 278 |
+
print(f" Response: {response[:100]}...")
|
| 279 |
+
|
| 280 |
return {
|
| 281 |
"response": response,
|
| 282 |
"session_id": session_id,
|
| 283 |
"is_new_session": is_new_session
|
| 284 |
}
|
| 285 |
except Exception as e:
|
| 286 |
+
print(f"❌ Error in chat endpoint: {str(e)}")
|
| 287 |
raise HTTPException(status_code=500, detail=f"Error processing chat: {str(e)}")
|
| 288 |
|
| 289 |
@app.get("/chat/{session_id}/history", response_model=ChatHistoryResponse)
|