2025-05-23 22:42:22 +02:00

188 lines
7.2 KiB
Python

from typing import List, Optional, Dict, Any, ClassVar
from datetime import datetime
from pydantic import BaseModel, Field, HttpUrl
class ImageBase(BaseModel):
"""Base schema for image data"""
description: Optional[str] = Field(None, description="Image description", max_length=500)
tags: List[str] = Field(default=[], description="Image tags")
class ImageUpload(ImageBase):
"""Schema for uploading an image"""
# Note: The file itself is handled by FastAPI's UploadFile
pass
class ImageUpdate(BaseModel):
"""Schema for updating an image"""
description: Optional[str] = Field(None, description="Image description", max_length=500)
tags: Optional[List[str]] = Field(None, description="Image tags")
metadata: Optional[Dict[str, Any]] = Field(None, description="Image metadata")
class ImageResponse(ImageBase):
"""Schema for image response"""
id: str
filename: str
original_filename: str
file_size: int
content_type: str
public_url: Optional[HttpUrl] = None
team_id: str
uploader_id: str
upload_date: datetime
last_accessed: Optional[datetime] = None
metadata: Dict[str, Any] = Field(default={})
has_embedding: bool = False
model_config: ClassVar[dict] = {
"from_attributes": True,
"json_schema_extra": {
"example": {
"id": "507f1f77bcf86cd799439011",
"filename": "1234567890abcdef.jpg",
"original_filename": "sunset.jpg",
"file_size": 1024000,
"content_type": "image/jpeg",
"public_url": "https://storage.googleapis.com/bucket/1234567890abcdef.jpg",
"team_id": "507f1f77bcf86cd799439022",
"uploader_id": "507f1f77bcf86cd799439033",
"upload_date": "2023-10-20T10:00:00",
"last_accessed": "2023-10-21T10:00:00",
"description": "Beautiful sunset over the mountains",
"tags": ["sunset", "mountains", "nature"],
"metadata": {
"width": 1920,
"height": 1080,
"location": "Rocky Mountains"
},
"has_embedding": True
}
}
}
class ImageListResponse(BaseModel):
"""Schema for image list response"""
images: List[ImageResponse]
total: int
page: int
page_size: int
total_pages: int
model_config: ClassVar[dict] = {
"json_schema_extra": {
"example": {
"images": [
{
"id": "507f1f77bcf86cd799439011",
"filename": "1234567890abcdef.jpg",
"original_filename": "sunset.jpg",
"file_size": 1024000,
"content_type": "image/jpeg",
"public_url": "https://storage.googleapis.com/bucket/1234567890abcdef.jpg",
"team_id": "507f1f77bcf86cd799439022",
"uploader_id": "507f1f77bcf86cd799439033",
"upload_date": "2023-10-20T10:00:00",
"last_accessed": "2023-10-21T10:00:00",
"description": "Beautiful sunset over the mountains",
"tags": ["sunset", "mountains", "nature"],
"metadata": {
"width": 1920,
"height": 1080,
"location": "Rocky Mountains"
},
"has_embedding": True
}
],
"total": 1,
"page": 1,
"page_size": 10,
"total_pages": 1
}
}
}
class ImageSearchQuery(BaseModel):
"""Schema for image search query"""
query: str = Field(..., description="Search query", min_length=1)
limit: int = Field(10, description="Maximum number of results", ge=1, le=100)
model_config: ClassVar[dict] = {
"json_schema_extra": {
"example": {
"query": "mountain sunset",
"limit": 10
}
}
}
class ImageSearchResult(BaseModel):
"""Schema for image search result"""
image: ImageResponse
score: float
model_config: ClassVar[dict] = {
"json_schema_extra": {
"example": {
"image": {
"id": "507f1f77bcf86cd799439011",
"filename": "1234567890abcdef.jpg",
"original_filename": "sunset.jpg",
"file_size": 1024000,
"content_type": "image/jpeg",
"public_url": "https://storage.googleapis.com/bucket/1234567890abcdef.jpg",
"team_id": "507f1f77bcf86cd799439022",
"uploader_id": "507f1f77bcf86cd799439033",
"upload_date": "2023-10-20T10:00:00",
"last_accessed": "2023-10-21T10:00:00",
"description": "Beautiful sunset over the mountains",
"tags": ["sunset", "mountains", "nature"],
"metadata": {
"width": 1920,
"height": 1080,
"location": "Rocky Mountains"
},
"has_embedding": True
},
"score": 0.95
}
}
}
class ImageSearchResponse(BaseModel):
"""Schema for image search response"""
results: List[ImageSearchResult]
total: int
query: str
model_config: ClassVar[dict] = {
"json_schema_extra": {
"example": {
"results": [
{
"image": {
"id": "507f1f77bcf86cd799439011",
"filename": "1234567890abcdef.jpg",
"original_filename": "sunset.jpg",
"file_size": 1024000,
"content_type": "image/jpeg",
"public_url": "https://storage.googleapis.com/bucket/1234567890abcdef.jpg",
"team_id": "507f1f77bcf86cd799439022",
"uploader_id": "507f1f77bcf86cd799439033",
"upload_date": "2023-10-20T10:00:00",
"last_accessed": "2023-10-21T10:00:00",
"description": "Beautiful sunset over the mountains",
"tags": ["sunset", "mountains", "nature"],
"metadata": {
"width": 1920,
"height": 1080,
"location": "Rocky Mountains"
},
"has_embedding": True
},
"score": 0.95
}
],
"total": 1,
"query": "mountain sunset"
}
}
}