base.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(
  16. *, session: AsyncSession, purpose: str, file_ids: Optional[List[str]]
  17. ) -> List[File]:
  18. pass
  19. @staticmethod
  20. @abstractmethod
  21. async def create_file(
  22. *, session: AsyncSession, purpose: str, file: UploadFile
  23. ) -> File:
  24. pass
  25. @staticmethod
  26. @abstractmethod
  27. async def get_file(*, session: AsyncSession, file_id: str) -> File:
  28. pass
  29. @staticmethod
  30. @abstractmethod
  31. async def get_file_content(
  32. *, session: AsyncSession, file_id: str
  33. ) -> Tuple[Union[bytes, Generator], str]:
  34. pass
  35. @staticmethod
  36. @abstractmethod
  37. async def delete_file(*, session: AsyncSession, file_id: str) -> DeleteResponse:
  38. pass
  39. @staticmethod
  40. @abstractmethod
  41. def search_in_files(*, query: str, file_keys: List[str]) -> dict:
  42. pass
  43. @staticmethod
  44. @abstractmethod
  45. def list_in_files(
  46. ids: list[str] = None,
  47. offset: int = 0,
  48. limit: int = 100,
  49. ) -> dict:
  50. pass
  51. @staticmethod
  52. @abstractmethod
  53. def list_documents(
  54. id: str = "",
  55. offset: int = 0,
  56. limit: int = 100,
  57. ) -> dict:
  58. pass