-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assistant notifications + update assistant context (#2816)
* add assistant notifications * nit * update context * validated * ensure context passed properly * validated + cleaned * nit: naming * k * k * final validation + new ui * nit + video * nit * nit * nit * k * fix typos
- Loading branch information
Showing
37 changed files
with
822 additions
and
346 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
backend/alembic/versions/1b10e1fda030_add_additional_data_to_notifications.py
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,26 @@ | ||
"""add additional data to notifications | ||
Revision ID: 1b10e1fda030 | ||
Revises: 6756efa39ada | ||
Create Date: 2024-10-15 19:26:44.071259 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "1b10e1fda030" | ||
down_revision = "6756efa39ada" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
op.add_column( | ||
"notification", sa.Column("additional_data", postgresql.JSONB(), nullable=True) | ||
) | ||
|
||
|
||
def downgrade() -> None: | ||
op.drop_column("notification", "additional_data") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from fastapi import APIRouter | ||
from fastapi import Depends | ||
from fastapi import HTTPException | ||
from sqlalchemy.orm import Session | ||
|
||
from danswer.auth.users import current_user | ||
from danswer.db.engine import get_session | ||
from danswer.db.models import User | ||
from danswer.db.notification import dismiss_notification | ||
from danswer.db.notification import get_notification_by_id | ||
from danswer.db.notification import get_notifications | ||
from danswer.server.settings.models import Notification as NotificationModel | ||
from danswer.utils.logger import setup_logger | ||
|
||
logger = setup_logger() | ||
|
||
router = APIRouter(prefix="/notifications") | ||
|
||
|
||
@router.get("") | ||
def get_notifications_api( | ||
user: User = Depends(current_user), | ||
db_session: Session = Depends(get_session), | ||
) -> list[NotificationModel]: | ||
notifications = [ | ||
NotificationModel.from_model(notif) | ||
for notif in get_notifications(user, db_session, include_dismissed=False) | ||
] | ||
return notifications | ||
|
||
|
||
@router.post("/{notification_id}/dismiss") | ||
def dismiss_notification_endpoint( | ||
notification_id: int, | ||
user: User | None = Depends(current_user), | ||
db_session: Session = Depends(get_session), | ||
) -> None: | ||
try: | ||
notification = get_notification_by_id(notification_id, user, db_session) | ||
except PermissionError: | ||
raise HTTPException( | ||
status_code=403, detail="Not authorized to dismiss this notification" | ||
) | ||
except ValueError: | ||
raise HTTPException(status_code=404, detail="Notification not found") | ||
|
||
dismiss_notification(notification, db_session) |
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
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
Oops, something went wrong.