目前可以成功动态更换模型运行的
This commit is contained in:
@ -1,30 +1,41 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 请求模型(前端传参校验)
|
||||
# 请求模型(前端传参校验)- 保留update的eigenvalue(如需更新特征值)
|
||||
# ------------------------------
|
||||
class FaceCreateRequest(BaseModel):
|
||||
"""创建人脸记录请求模型(无需ID、由数据库自增)"""
|
||||
name: str = Field(None, max_length=255, description="名称(可选、最长255字符)")
|
||||
name: Optional[str] = Field(None, max_length=255, description="名称(可选、最长255字符)")
|
||||
|
||||
|
||||
class FaceUpdateRequest(BaseModel):
|
||||
"""更新人脸记录请求模型(不变)"""
|
||||
name: str = Field(None, max_length=255, description="名称")
|
||||
eigenvalue: str = Field(None, max_length=255, description="特征(文件处理后可更新)")
|
||||
"""更新人脸记录请求模型 - 保留eigenvalue(如需更新特征值,不影响返回)"""
|
||||
name: Optional[str] = Field(None, max_length=255, description="名称(可选)")
|
||||
eigenvalue: Optional[str] = Field(None, description="特征值(可选,文件处理后可更新)") # 保留更新能力
|
||||
address: Optional[str] = Field(None, description="图片完整路径(可选,更新图片时使用)")
|
||||
|
||||
|
||||
# ------------------------------
|
||||
# 响应模型(后端返回数据)
|
||||
# 响应模型(后端返回数据)- 核心修改:删除eigenvalue字段
|
||||
# ------------------------------
|
||||
class FaceResponse(BaseModel):
|
||||
"""人脸记录响应模型(仍包含ID、由数据库生成后返回)"""
|
||||
"""人脸记录响应模型(仅返回需要的字段,移除eigenvalue)"""
|
||||
id: int = Field(..., description="主键ID(数据库自增)")
|
||||
name: str = Field(None, description="名称")
|
||||
eigenvalue: str | None = Field(None, description="特征(可为空)")
|
||||
created_at: datetime = Field(..., description="记录创建时间")
|
||||
updated_at: datetime = Field(..., description="记录更新时间")
|
||||
name: Optional[str] = Field(None, description="名称")
|
||||
address: Optional[str] = Field(None, description="人脸图片完整保存路径(数据库新增字段)") # 仅保留address
|
||||
created_at: datetime = Field(..., description="记录创建时间(数据库自动生成)")
|
||||
updated_at: datetime = Field(..., description="记录更新时间(数据库自动生成)")
|
||||
|
||||
# 关键配置:支持从数据库查询结果(字典)直接转换
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class FaceListResponse(BaseModel):
|
||||
"""人脸列表分页响应模型(结构不变,内部FaceResponse已移除eigenvalue)"""
|
||||
total: int = Field(..., description="筛选后的总记录数")
|
||||
faces: List[FaceResponse] = Field(..., description="当前页的人脸记录列表")
|
||||
|
||||
model_config = {"from_attributes": True}
|
37
schema/model_schema.py
Normal file
37
schema/model_schema.py
Normal file
@ -0,0 +1,37 @@
|
||||
from datetime import datetime
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
# 请求模型
|
||||
class ModelCreateRequest(BaseModel):
|
||||
name: str = Field(..., max_length=255, description="模型名称(必填,如:yolo-v8s-car)")
|
||||
description: Optional[str] = Field(None, description="模型描述(可选)")
|
||||
is_default: Optional[bool] = Field(False, description="是否设为默认模型")
|
||||
|
||||
|
||||
class ModelUpdateRequest(BaseModel):
|
||||
name: Optional[str] = Field(None, max_length=255, description="模型名称(可选修改)")
|
||||
description: Optional[str] = Field(None, description="模型描述(可选修改)")
|
||||
is_default: Optional[bool] = Field(None, description="是否设为默认模型(可选切换)")
|
||||
|
||||
|
||||
# 响应模型
|
||||
class ModelResponse(BaseModel):
|
||||
id: int = Field(..., description="模型ID")
|
||||
name: str = Field(..., description="模型名称")
|
||||
path: str = Field(..., description="模型文件相对路径")
|
||||
is_default: bool = Field(..., description="是否默认模型")
|
||||
description: Optional[str] = Field(None, description="模型描述")
|
||||
file_size: Optional[int] = Field(None, description="文件大小(字节)")
|
||||
created_at: datetime = Field(..., description="创建时间")
|
||||
updated_at: datetime = Field(..., description="更新时间")
|
||||
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class ModelListResponse(BaseModel):
|
||||
total: int = Field(..., description="总记录数")
|
||||
models: List[ModelResponse] = Field(..., description="当前页模型列表")
|
||||
|
||||
model_config = {"from_attributes": True}
|
@ -1,6 +1,6 @@
|
||||
from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional
|
||||
|
||||
|
||||
# ------------------------------
|
||||
@ -30,3 +30,11 @@ class UserResponse(BaseModel):
|
||||
|
||||
# Pydantic V2 配置(支持从数据库查询结果转换)
|
||||
model_config = {"from_attributes": True}
|
||||
|
||||
|
||||
class UserListResponse(BaseModel):
|
||||
"""用户列表分页响应模型(与设备/人脸列表结构对齐)"""
|
||||
total: int = Field(..., description="用户总数")
|
||||
users: List[UserResponse] = Field(..., description="当前页用户列表")
|
||||
|
||||
model_config = {"from_attributes": True}
|
Reference in New Issue
Block a user