feat(backend): 添加 API Schemas 定义
- 添加 Chunk 数据结构 (chunk.py) - 添加 Dataset Schema (dataset.py) - 添加 Evaluation Schema (eval.py) - 添加 File Schema (file.py) - 添加 Project Schema (project.py) - 添加 Question Schema (question.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
46
backend/app/schemas/chunk.py
Normal file
46
backend/app/schemas/chunk.py
Normal file
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Chunk Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional, Any
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class ChunkBase(BaseModel):
|
||||
"""Base chunk schema"""
|
||||
name: Optional[str] = Field(None, max_length=255)
|
||||
content: str = Field(..., min_length=1)
|
||||
summary: Optional[str] = None
|
||||
word_count: Optional[int] = None
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class ChunkCreate(ChunkBase):
|
||||
"""Chunk create schema"""
|
||||
project_id: Optional[UUID] = None
|
||||
file_id: Optional[UUID] = None
|
||||
|
||||
|
||||
class ChunkUpdate(BaseModel):
|
||||
"""Chunk update schema"""
|
||||
name: Optional[str] = Field(None, max_length=255)
|
||||
content: Optional[str] = Field(None, min_length=1)
|
||||
summary: Optional[str] = None
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class ChunkResponse(ChunkBase):
|
||||
"""Chunk response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: UUID
|
||||
file_id: Optional[UUID]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
ChunkCreateSchema = ChunkCreate
|
||||
ChunkUpdateSchema = ChunkUpdate
|
||||
43
backend/app/schemas/dataset.py
Normal file
43
backend/app/schemas/dataset.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Dataset Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional, Any
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class DatasetBase(BaseModel):
|
||||
"""Base dataset schema"""
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
description: Optional[str] = Field(None, max_length=2000)
|
||||
dataset_type: Optional[str] = Field(None, max_length=50)
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class DatasetCreate(DatasetBase):
|
||||
"""Dataset create schema"""
|
||||
pass
|
||||
|
||||
|
||||
class DatasetUpdate(BaseModel):
|
||||
"""Dataset update schema"""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
description: Optional[str] = Field(None, max_length=2000)
|
||||
dataset_type: Optional[str] = Field(None, max_length=50)
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class DatasetResponse(DatasetBase):
|
||||
"""Dataset response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: UUID
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
DatasetCreateSchema = DatasetCreate
|
||||
DatasetUpdateSchema = DatasetUpdate
|
||||
60
backend/app/schemas/eval.py
Normal file
60
backend/app/schemas/eval.py
Normal file
@@ -0,0 +1,60 @@
|
||||
"""
|
||||
Evaluation Dataset Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional, Any
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class EvalDatasetBase(BaseModel):
|
||||
"""Base eval dataset schema"""
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
question_type: Optional[str] = Field("mixed", max_length=50)
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class EvalDatasetCreate(EvalDatasetBase):
|
||||
"""Eval dataset create schema"""
|
||||
pass
|
||||
|
||||
|
||||
class EvalDatasetUpdate(BaseModel):
|
||||
"""Eval dataset update schema"""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
question_type: Optional[str] = Field(None, max_length=50)
|
||||
extra_data: Optional[dict] = None
|
||||
|
||||
|
||||
class EvalDatasetResponse(EvalDatasetBase):
|
||||
"""Eval dataset response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: UUID
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
class TaskBase(BaseModel):
|
||||
"""Base task schema"""
|
||||
task_type: str = Field(..., max_length=50)
|
||||
status: Optional[str] = "pending"
|
||||
progress: Optional[int] = Field(0, ge=0, le=100)
|
||||
result: Optional[Any] = None
|
||||
error: Optional[str] = None
|
||||
|
||||
|
||||
class TaskResponse(TaskBase):
|
||||
"""Task response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: Optional[UUID]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
EvalDatasetCreateSchema = EvalDatasetCreate
|
||||
EvalDatasetUpdateSchema = EvalDatasetUpdate
|
||||
43
backend/app/schemas/file.py
Normal file
43
backend/app/schemas/file.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
File Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class FileBase(BaseModel):
|
||||
"""Base file schema"""
|
||||
filename: str = Field(..., min_length=1, max_length=255)
|
||||
file_type: str = Field(..., max_length=50)
|
||||
size: Optional[int] = None
|
||||
|
||||
|
||||
class FileCreate(FileBase):
|
||||
"""File create schema"""
|
||||
project_id: UUID
|
||||
file_path: Optional[str] = None
|
||||
status: str = "pending"
|
||||
|
||||
|
||||
class FileUpdate(BaseModel):
|
||||
"""File update schema"""
|
||||
status: Optional[str] = None
|
||||
|
||||
|
||||
class FileResponse(FileBase):
|
||||
"""File response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: UUID
|
||||
file_path: Optional[str]
|
||||
status: str
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
FileCreateSchema = FileCreate
|
||||
FileUpdateSchema = FileUpdate
|
||||
38
backend/app/schemas/project.py
Normal file
38
backend/app/schemas/project.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""
|
||||
Project Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class ProjectBase(BaseModel):
|
||||
"""Base project schema"""
|
||||
name: str = Field(..., min_length=1, max_length=255)
|
||||
description: Optional[str] = Field(None, max_length=2000)
|
||||
|
||||
|
||||
class ProjectCreate(ProjectBase):
|
||||
"""Project create schema"""
|
||||
pass
|
||||
|
||||
|
||||
class ProjectUpdate(BaseModel):
|
||||
"""Project update schema"""
|
||||
name: Optional[str] = Field(None, min_length=1, max_length=255)
|
||||
description: Optional[str] = Field(None, max_length=2000)
|
||||
|
||||
|
||||
class ProjectResponse(ProjectBase):
|
||||
"""Project response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
ProjectCreateSchema = ProjectCreate
|
||||
ProjectUpdateSchema = ProjectUpdate
|
||||
43
backend/app/schemas/question.py
Normal file
43
backend/app/schemas/question.py
Normal file
@@ -0,0 +1,43 @@
|
||||
"""
|
||||
Question Schemas
|
||||
"""
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
from uuid import UUID
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class QuestionBase(BaseModel):
|
||||
"""Base question schema"""
|
||||
content: str = Field(..., min_length=1)
|
||||
answer: Optional[str] = None
|
||||
question_type: Optional[str] = Field(None, max_length=50)
|
||||
source: Optional[str] = "manual"
|
||||
|
||||
|
||||
class QuestionCreate(QuestionBase):
|
||||
"""Question create schema"""
|
||||
chunk_id: Optional[UUID] = None
|
||||
|
||||
|
||||
class QuestionUpdate(BaseModel):
|
||||
"""Question update schema"""
|
||||
content: Optional[str] = Field(None, min_length=1)
|
||||
answer: Optional[str] = None
|
||||
question_type: Optional[str] = Field(None, max_length=50)
|
||||
|
||||
|
||||
class QuestionResponse(QuestionBase):
|
||||
"""Question response schema"""
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: UUID
|
||||
project_id: UUID
|
||||
chunk_id: Optional[UUID]
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
|
||||
|
||||
# Alias for CRUD
|
||||
QuestionCreateSchema = QuestionCreate
|
||||
QuestionUpdateSchema = QuestionUpdate
|
||||
Reference in New Issue
Block a user