Order conversations by recency and auto-name from first message #24

Merged
ryan merged 1 commits from feat/conversation-ordering-and-naming into main 2026-04-05 10:43:10 -04:00
2 changed files with 7 additions and 1 deletions

View File

@@ -275,7 +275,7 @@ async def create_conversation():
async def get_all_conversations(): async def get_all_conversations():
user_uuid = get_jwt_identity() user_uuid = get_jwt_identity()
user = await blueprints.users.models.User.get(id=user_uuid) user = await blueprints.users.models.User.get(id=user_uuid)
conversations = Conversation.filter(user=user) conversations = Conversation.filter(user=user).order_by("-updated_at")
serialized_conversations = await PydListConversation.from_queryset(conversations) serialized_conversations = await PydListConversation.from_queryset(conversations)
return jsonify(serialized_conversations.model_dump()) return jsonify(serialized_conversations.model_dump())

View File

@@ -19,6 +19,12 @@ async def add_message_to_conversation(
image_key: str | None = None, image_key: str | None = None,
) -> ConversationMessage: ) -> ConversationMessage:
print(conversation, message, speaker) print(conversation, message, speaker)
# Name the conversation after the first user message
if speaker == "user" and not await conversation.messages.all().exists():
conversation.name = message[:100]
await conversation.save()
message = await ConversationMessage.create( message = await ConversationMessage.create(
text=message, text=message,
speaker=speaker, speaker=speaker,