Files
onyx/backend/danswer/server/settings/models.py
T
2024-08-16 21:29:15 -07:00

65 lines
1.8 KiB
Python

from datetime import datetime
from enum import Enum
from pydantic import BaseModel
from danswer.configs.constants import NotificationType
from danswer.db.models import Notification as NotificationDBModel
class PageType(str, Enum):
CHAT = "chat"
SEARCH = "search"
class Notification(BaseModel):
id: int
notif_type: NotificationType
dismissed: bool
last_shown: datetime
first_shown: datetime
@classmethod
def from_model(cls, notif: NotificationDBModel) -> "Notification":
return cls(
id=notif.id,
notif_type=notif.notif_type,
dismissed=notif.dismissed,
last_shown=notif.last_shown,
first_shown=notif.first_shown,
)
class Settings(BaseModel):
"""General settings"""
chat_page_enabled: bool = True
search_page_enabled: bool = True
default_page: PageType = PageType.SEARCH
maximum_chat_retention_days: int | None = None
def check_validity(self) -> None:
chat_page_enabled = self.chat_page_enabled
search_page_enabled = self.search_page_enabled
default_page = self.default_page
if chat_page_enabled is False and search_page_enabled is False:
raise ValueError(
"One of `search_page_enabled` and `chat_page_enabled` must be True."
)
if default_page == PageType.CHAT and chat_page_enabled is False:
raise ValueError(
"The default page cannot be 'chat' if the chat page is disabled."
)
if default_page == PageType.SEARCH and search_page_enabled is False:
raise ValueError(
"The default page cannot be 'search' if the search page is disabled."
)
class UserSettings(Settings):
notifications: list[Notification]
needs_reindexing: bool