-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(frontend|backend) - adjust conversation apis to have improved end…
…point url /conversation/{session_id}/... -> History = GET /conversations/{session_id}/messages -> Send Message = POST /conversations/{session_id}/messages -> Experiences = /conversations/{session_id}/experiences - move conversation api to its own module - adjust frontend service to call on updated endpoints - add tests to conversation routes.py feat(backend) - add reaction endpoints -> Upsert reaction = PUT /conversations/{session_id}/messages/{message_id}/reactions -> Delete reaction = DELETE /conversations/{session_id}/messages/{message_id}/reactions feat(backend) - add api feature to block adding reaction to user message chore(frontend): - implement reactions button component - add reaction service - add reaction reason popover chore(backend) - integrate frontend/backend fix(backend) - change /reaction to /reactions chore(backend) - prettier format [pulumi up] chore(backend) - move validation tests to test_model - add checks to verify user is accessing reactions on messages in their own session chore: adjust alignment and font size for message reactions - fix state issues on popover close - expect 201 on add reaction in storybook fix(frontend): rebase footers refactor fix(backend): move user message check logic to conversation_memory_manager chore(backend) - add migration script that adds message_id to all the existing messages fix chore(backend) - review
- Loading branch information
1 parent
3dd7e40
commit 6e05069
Showing
102 changed files
with
5,059 additions
and
806 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
""" | ||
Constants related to conversations. | ||
""" | ||
|
||
MAX_MESSAGE_LENGTH = 1000 | ||
|
||
UNEXPECTED_FAILURE_MESSAGE = "Oops! something went wrong" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
""" | ||
This module contains the repository layer for handling reactions. | ||
""" | ||
import logging | ||
from abc import ABC, abstractmethod | ||
from typing import Optional, List | ||
|
||
from motor.motor_asyncio import AsyncIOMotorDatabase | ||
|
||
from app.server_dependencies.database_collections import Collections | ||
from app.conversations.reactions.types import Reaction | ||
|
||
|
||
class IReactionRepository(ABC): | ||
""" | ||
Interface for the reaction repository. | ||
Allows to mock the repository in tests | ||
""" | ||
|
||
@abstractmethod | ||
async def add(self, reaction: Reaction) -> Optional[str]: | ||
""" | ||
Creates or updates a reaction. | ||
:param reaction: ReactionModel - the reaction to create or update | ||
:return: str - the id of the created/updated reaction document id | ||
""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
async def delete(self, session_id: int, message_id: str): | ||
""" | ||
Deletes a reaction. | ||
:param session_id: the id of the session containing the message | ||
:param message_id: the id of the message that was reacted to | ||
""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
async def get_reactions(self, session_id: int) -> Optional[List[Reaction]]: | ||
""" | ||
Gets the full list of reactions for the given session | ||
:param session_id: the id of the session containing the messages | ||
:return: Optional[List[Reaction]] - the reactions if found, otherwise None | ||
""" | ||
raise NotImplementedError() | ||
|
||
|
||
class ReactionRepository(IReactionRepository): | ||
def __init__(self, db: AsyncIOMotorDatabase): | ||
self._db = db | ||
self._logger = logging.getLogger(ReactionRepository.__name__) | ||
self._collection = db.get_collection(Collections.REACTIONS) | ||
|
||
async def add(self, reaction: Reaction) -> Optional[str]: | ||
# Convert the pydantic model to a dictionary | ||
payload = reaction.model_dump() | ||
|
||
# Use upsert to either create a new document or update an existing one | ||
# We use session_id and message_id as the unique key | ||
result = await self._collection.update_one( | ||
{ | ||
"session_id": {"$eq": reaction.session_id}, | ||
"message_id": {"$eq": reaction.message_id} | ||
}, | ||
{"$set": payload}, | ||
upsert=True | ||
) | ||
|
||
# Return the upserted ID if it was an insert, otherwise None | ||
return str(result.upserted_id) if result.upserted_id else None | ||
|
||
async def delete(self, session_id: int, message_id: str): | ||
await self._collection.delete_one({ | ||
"session_id": {"$eq": session_id}, | ||
"message_id": {"$eq": message_id} | ||
}) | ||
|
||
async def get_reactions(self, session_id: int) -> Optional[List[Reaction]]: | ||
""" | ||
Gets the full list of reactions for a session | ||
:param session_id: the id of the session containing the message | ||
:return: Optional[List[Reaction]] - the list of reactions if found, otherwise None | ||
""" | ||
cursor = self._collection.find({ | ||
"session_id": {"$eq": session_id}, | ||
}) | ||
|
||
reactions = [] | ||
async for doc in cursor: | ||
reactions.append(Reaction.from_dict(doc)) | ||
|
||
return reactions if reactions else None |
Oops, something went wrong.