File size: 1,503 Bytes
fa397dd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
"""
청크 관련 Pydantic 모델
"""
from typing import Optional, List
from pydantic import BaseModel, Field
class ChunkMetadata(BaseModel):
"""청크 메타데이터 모델"""
pov: Optional[str] = Field(None, description="화자/시점")
characters: Optional[List[str]] = Field(default_factory=list, description="등장인물 목록")
time_background: Optional[str] = Field(None, description="시간적 배경")
chapter: Optional[int] = Field(None, description="챕터 번호")
class Config:
"""Pydantic 설정"""
json_schema_extra = {
"example": {
"pov": "1인칭 주인공",
"characters": ["홍길동", "김철수"],
"time_background": "현재 시점",
"chapter": 1
}
}
class ChunkCreate(BaseModel):
"""청크 생성 요청 모델"""
file_id: int = Field(..., description="파일 ID")
chunk_index: int = Field(..., description="청크 인덱스")
content: str = Field(..., min_length=1, description="청크 내용")
metadata: Optional[ChunkMetadata] = Field(None, description="청크 메타데이터")
class ChunkResponse(BaseModel):
"""청크 응답 모델"""
id: int
file_id: int
chunk_index: int
content: str
metadata: Optional[ChunkMetadata] = None
class Config:
"""Pydantic 설정"""
from_attributes = True
|