base.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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(
  42. *, query: str, file_keys: List[str], folder_keys: List[str] = None
  43. ) -> dict:
  44. pass
  45. @staticmethod
  46. @abstractmethod
  47. def list_in_files(
  48. ids: list[str] = None,
  49. offset: int = 0,
  50. limit: int = 100,
  51. ) -> dict:
  52. pass
  53. @staticmethod
  54. @abstractmethod
  55. def list_documents(
  56. id: str = "",
  57. offset: int = 0,
  58. limit: int = 100,
  59. ) -> dict:
  60. pass
  61. @staticmethod
  62. @abstractmethod
  63. def list_chunks(ids: Optional[list[str]] = None) -> dict:
  64. pass