arina-hf-spaces-api / app /core /past_conversations.py
adsurkasur's picture
clone from arina-hf-spaces
68964c2
raw
history blame contribute delete
607 Bytes
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 []