responses.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from typing import Any, Optional, TypeVar
  2. from uuid import UUID
  3. from pydantic import BaseModel, Field
  4. from shared.api.models.base import PaginatedR2RResult, R2RResults
  5. T = TypeVar("T")
  6. class IngestionResponse(BaseModel):
  7. message: str = Field(
  8. ...,
  9. description="A message describing the result of the ingestion request.",
  10. )
  11. task_id: Optional[UUID] = Field(
  12. None,
  13. description="The task ID of the ingestion request.",
  14. )
  15. document_id: UUID = Field(
  16. ...,
  17. description="The ID of the document that was ingested.",
  18. )
  19. class Config:
  20. json_schema_extra = {
  21. "example": {
  22. "message": "Ingestion task queued successfully.",
  23. "task_id": "c68dc72e-fc23-5452-8f49-d7bd46088a96",
  24. "document_id": "9fbe403b-c11c-5aae-8ade-ef22980c3ad1",
  25. }
  26. }
  27. class UpdateResponse(BaseModel):
  28. message: str = Field(
  29. ...,
  30. description="A message describing the result of the ingestion request.",
  31. )
  32. task_id: Optional[UUID] = Field(
  33. None,
  34. description="The task ID of the ingestion request.",
  35. )
  36. document_ids: list[UUID] = Field(
  37. ...,
  38. description="The ID of the document that was ingested.",
  39. )
  40. class Config:
  41. json_schema_extra = {
  42. "example": {
  43. "message": "Update task queued successfully.",
  44. "task_id": "c68dc72e-fc23-5452-8f49-d7bd46088a96",
  45. "document_ids": ["9fbe403b-c11c-5aae-8ade-ef22980c3ad1"],
  46. }
  47. }
  48. # TODO: This can probably be cleaner
  49. class ListVectorIndicesResponse(BaseModel):
  50. indices: list[dict[str, Any]]
  51. WrappedIngestionResponse = R2RResults[IngestionResponse]
  52. WrappedMetadataUpdateResponse = R2RResults[IngestionResponse]
  53. WrappedUpdateResponse = R2RResults[UpdateResponse]
  54. WrappedListVectorIndicesResponse = PaginatedR2RResult[
  55. ListVectorIndicesResponse
  56. ]