Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add notification service and update notification status
  • Loading branch information
StanGirard committed May 8, 2024
commit 87d7334d8413cf4b6ee3d22a7be75b1398d5ed36
14 changes: 14 additions & 0 deletions backend/modules/assistant/ito/ito.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
from modules.assistant.ito.utils.pdf_generator import PDFGenerator, PDFModel
from modules.chat.controller.chat.utils import update_user_usage
from modules.contact_support.controller.settings import ContactsSettings
from modules.notification.dto.inputs import NotificationUpdatableProperties
from modules.notification.entity.notification import NotificationsStatusEnum
from modules.notification.service.notification_service import NotificationService
from modules.upload.controller.upload_routes import upload_file
from modules.user.entity.user_identity import UserIdentity
from modules.user.service.user_usage import UserUsage
Expand All @@ -22,6 +25,8 @@

logger = get_logger(__name__)

notification_service = NotificationService()


class ITO(BaseModel):
input: InputAssistant
Expand Down Expand Up @@ -149,6 +154,7 @@ async def create_and_upload_processed_file(
brain_id: str = None,
email_activated: bool = False,
current_user: UserIdentity = None,
notification_id: str = None,
) -> dict:
"""Handles creation and uploading of the processed file."""
# remove any special characters from the filename that aren't http safe
Expand Down Expand Up @@ -207,4 +213,12 @@ async def create_and_upload_processed_file(

os.remove(new_filename)

notification_service.update_notification_by_id(
notification_id,
NotificationUpdatableProperties(
status=NotificationsStatusEnum.SUCCESS,
title=f"Summary of {original_filename} generated successfully",
),
)

return {"message": f"{file_description} generated successfully"}
3 changes: 2 additions & 1 deletion backend/modules/assistant/ito/summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def check_input(self):

async def process_assistant(self):
try:
notification_service.add_notification(
notification = notification_service.add_notification(
CreateNotification(
user_id=self.current_user.id,
status="info",
Expand Down Expand Up @@ -117,6 +117,7 @@ async def process_assistant(self):
brain_id,
email_activated,
self.current_user.model_dump(mode="json"),
notification.id,
),
)
except Exception as e:
Expand Down
5 changes: 4 additions & 1 deletion backend/modules/assistant/ito/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@


@celery.task(name="task_summary")
def task_summary(split_docs, filename, brain_id, email_activated, current_user):
def task_summary(
split_docs, filename, brain_id, email_activated, current_user, notification_id
):
loop = asyncio.get_event_loop()
# turn split_docs into a list of Document objects
logger.info("split_docs: %s", split_docs)
Expand All @@ -38,5 +40,6 @@ def task_summary(split_docs, filename, brain_id, email_activated, current_user):
brain_id,
email_activated,
current_user,
notification_id,
)
)
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ services:
- "--workers"
- "6"
restart: always
volumes:
- ./backend/:/code/
ports:
- 5050:5050

Expand Down