Spaces:
Sleeping
Sleeping
Commit
·
b8b4625
1
Parent(s):
4771f50
Update api_routes_v2.py
Browse files- api_routes_v2.py +15 -2
api_routes_v2.py
CHANGED
|
@@ -857,13 +857,26 @@ async def get_session_history(
|
|
| 857 |
CHANGE: Adds 'chat_name' and 'pipelines_history' (added fields only).
|
| 858 |
"""
|
| 859 |
try:
|
| 860 |
-
#
|
| 861 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 862 |
|
| 863 |
# Format datetime objects to ISO strings for JSON serialization
|
|
|
|
|
|
|
| 864 |
formatted_history = []
|
| 865 |
for msg in history:
|
| 866 |
msg_copy = msg.copy()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 867 |
if "timestamp" in msg_copy and isinstance(msg_copy["timestamp"], datetime):
|
| 868 |
msg_copy["timestamp"] = msg_copy["timestamp"].isoformat()
|
| 869 |
formatted_history.append(msg_copy)
|
|
|
|
| 857 |
CHANGE: Adds 'chat_name' and 'pipelines_history' (added fields only).
|
| 858 |
"""
|
| 859 |
try:
|
| 860 |
+
# FIXED: Load conversation history from S3 (where messages are actually stored)
|
| 861 |
+
# Previously was using session_manager.get_session_history() which reads from
|
| 862 |
+
# MongoDB messages collection, but messages are stored in S3 conversation file
|
| 863 |
+
history = _load_conversation_from_s3(session_id)
|
| 864 |
+
|
| 865 |
+
# Apply limit
|
| 866 |
+
if limit and len(history) > limit:
|
| 867 |
+
history = history[-limit:] # Get last N messages
|
| 868 |
|
| 869 |
# Format datetime objects to ISO strings for JSON serialization
|
| 870 |
+
# Also add message_id to each message if not present
|
| 871 |
+
from services.schemas import generate_message_id
|
| 872 |
formatted_history = []
|
| 873 |
for msg in history:
|
| 874 |
msg_copy = msg.copy()
|
| 875 |
+
|
| 876 |
+
# Add message_id if not present
|
| 877 |
+
if "message_id" not in msg_copy:
|
| 878 |
+
msg_copy["message_id"] = generate_message_id()
|
| 879 |
+
|
| 880 |
if "timestamp" in msg_copy and isinstance(msg_copy["timestamp"], datetime):
|
| 881 |
msg_copy["timestamp"] = msg_copy["timestamp"].isoformat()
|
| 882 |
formatted_history.append(msg_copy)
|