Spaces:
Runtime error
Runtime error
import logging | |
from app.core.db_setup import conversations_collection | |
from app.core.logging_setup import logger | |
def get_past_conversations(limit=3): | |
"""Retrieve past conversations limited to the most recent ones.""" | |
try: | |
conversations = list( | |
conversations_collection.find({}, {"_id": 0}).sort("timestamp", -1).limit(limit) | |
) | |
return [ | |
(conv["conversation_id"], conv["role"], conv["message"], conv["timestamp"]) | |
for conv in conversations | |
] | |
except Exception as e: | |
logger.error(f"Unexpected error: {e}") | |
return [] |