2023-08-02 00:03:47 +03:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from datetime import datetime
|
|
|
|
from uuid import UUID
|
|
|
|
|
2023-08-03 11:37:13 +03:00
|
|
|
from models.brain_entity import BrainEntity
|
|
|
|
|
2023-08-02 00:03:47 +03:00
|
|
|
|
|
|
|
class Repository(ABC):
|
|
|
|
@abstractmethod
|
2023-08-03 11:37:13 +03:00
|
|
|
def get_user_brains(self, user_id: str) -> list[BrainEntity]:
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_brain_for_user(self, user_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_brain_user_by_id(self, user_id: str, brain_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_brain_vector(self, brain_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-09-25 15:22:59 +03:00
|
|
|
def delete_brain_users(self, brain_id: str):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_brain(self, brain_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-03 11:37:13 +03:00
|
|
|
def create_brain(self, brain: str):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create_brain_user(
|
|
|
|
self, user_id: UUID, brain_id: UUID, rights: str, default_brain: bool
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create_brain_vector(self, brain_id: UUID, vector_id: UUID, file_sha1: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_vector_ids_from_file_sha1(self, file_sha1: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_brain_vector_ids(self, brain_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_file_from_brain(self, brain_id: UUID, file_name: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-03 11:37:13 +03:00
|
|
|
def get_default_user_brain_id(self, user_id: UUID) -> UUID:
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_brain_by_id(self, brain_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-21 15:05:13 +03:00
|
|
|
def create_user_daily_usage(self, user_id: UUID, user_email: str, date: datetime):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-21 15:05:13 +03:00
|
|
|
def get_user_usage(self, user_id: UUID):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-21 15:05:13 +03:00
|
|
|
def get_user_requests_count_for_day(self, user_id: UUID, date: datetime):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
2023-08-21 15:05:13 +03:00
|
|
|
def update_user_request_count(self, user_id: UUID, date: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def increment_user_request_count(
|
|
|
|
self, user_id: UUID, date: str, current_request_count
|
|
|
|
):
|
2023-08-02 00:03:47 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_user_email(self, user_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def set_file_vectors_ids(self, file_sha1: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_brain_vectors_by_brain_id_and_file_sha1(
|
|
|
|
self, brain_id: UUID, file_sha1: str
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create_subscription_invitation(
|
|
|
|
self, brain_id: UUID, user_email: str, rights: str
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def update_subscription_invitation(
|
|
|
|
self, brain_id: UUID, user_email: str, rights: str
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_subscription_invitations_by_brain_id_and_email(
|
|
|
|
self, brain_id: UUID, user_email: str
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create_api_key(self, new_key_id: UUID, new_api_key: str, user_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_api_key(self, key_id: UUID, user_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_active_api_key(self, api_key: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_user_id_by_api_key(self, api_key: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def create_chat(self, new_chat):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_chat_by_id(self, chat_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_chat_history(self, chat_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_user_chats(self, user_id: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def update_chat_history(self, chat_id: str, user_message: str, assistant: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def update_chat(self, chat_id: UUID, updates):
|
|
|
|
pass
|
|
|
|
|
2023-10-12 10:39:56 +03:00
|
|
|
@abstractmethod
|
|
|
|
def add_question_and_answer(self, chat_id: str, question_and_answer):
|
|
|
|
pass
|
|
|
|
|
2023-08-02 00:03:47 +03:00
|
|
|
@abstractmethod
|
|
|
|
def update_message_by_id(self, message_id: UUID, updates):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_chat_details(self, chat_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_chat(self, chat_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_chat_history(self, chat_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_vectors_by_file_name(self, file_name: str):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def similarity_search(
|
|
|
|
self, query_embedding, table: str, top_k: int, threshold: float
|
|
|
|
):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def update_summary(self, document_id: UUID, summary_id: int):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_vectors_by_batch(self, batch_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_vectors_in_batch(self, batch_ids):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_vectors_by_file_sha1(self, file_sha1):
|
|
|
|
pass
|
2023-08-03 10:53:38 +03:00
|
|
|
|
2023-09-07 14:22:06 +03:00
|
|
|
@abstractmethod
|
|
|
|
def add_notification(self, notification):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def update_notification_by_id(self, id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def remove_notification_by_id(self, id: UUID):
|
|
|
|
pass
|
|
|
|
|
2023-09-07 18:23:31 +03:00
|
|
|
@abstractmethod
|
|
|
|
def remove_notifications_by_chat_id(self, chat_id: UUID):
|
|
|
|
pass
|
|
|
|
|
2023-09-07 14:22:06 +03:00
|
|
|
@abstractmethod
|
|
|
|
def get_notifications_by_chat_id(self, chat_id: UUID):
|
|
|
|
pass
|
2023-09-20 10:35:37 +03:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def insert_knowledge(self, brain_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def remove_knowledge_by_id(self, knowledge_id: UUID):
|
|
|
|
pass
|
|
|
|
|
2023-11-06 18:58:03 +03:00
|
|
|
@abstractmethod
|
|
|
|
def remove_brain_all_knowledge(self, brain_id: UUID):
|
|
|
|
pass
|
|
|
|
|
2023-09-20 10:35:37 +03:00
|
|
|
@abstractmethod
|
|
|
|
def get_knowledge_by_id(self, knowledge_id: UUID):
|
|
|
|
pass
|
2023-09-22 17:06:04 +03:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def get_all_knowledge_in_brain(self, brain_id: UUID):
|
|
|
|
pass
|
2023-10-05 10:47:29 +03:00
|
|
|
|
2023-11-07 16:03:50 +03:00
|
|
|
@abstractmethod
|
|
|
|
def get_api_brain_definition(self, brain_id: UUID):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def add_api_brain_definition(self, brain_id: UUID, config):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def delete_api_brain_definition(self, brain_id: UUID):
|
|
|
|
pass
|