base.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from abc import ABC, abstractmethod
  2. from typing import List, Union, Generator, Tuple, Optional
  3. from sqlalchemy.orm import Session
  4. from sqlalchemy.ext.asyncio import AsyncSession
  5. from fastapi import UploadFile
  6. from app.models import File
  7. from app.schemas.common import DeleteResponse
  8. class BaseFileService(ABC):
  9. @staticmethod
  10. @abstractmethod
  11. def get_file_list_by_ids(*, session: Session, file_ids: List[str]) -> List[File]:
  12. pass
  13. @staticmethod
  14. @abstractmethod
  15. async def get_file_list(*, session: AsyncSession, purpose: str, file_ids: Optional[List[str]]) -> List[File]:
  16. pass
  17. @staticmethod
  18. @abstractmethod
  19. async def create_file(*, session: AsyncSession, purpose: str, file: UploadFile) -> File:
  20. pass
  21. @staticmethod
  22. @abstractmethod
  23. async def get_file(*, session: AsyncSession, file_id: str) -> File:
  24. pass
  25. @staticmethod
  26. @abstractmethod
  27. async def get_file_content(*, session: AsyncSession, file_id: str) -> Tuple[Union[bytes, Generator], str]:
  28. pass
  29. @staticmethod
  30. @abstractmethod
  31. async def delete_file(*, session: AsyncSession, file_id: str) -> DeleteResponse:
  32. pass
  33. @staticmethod
  34. @abstractmethod
  35. def search_in_files(*, query: str, file_keys: List[str]) -> dict:
  36. pass