简单构建高并发
This commit is contained in:
74
app/schemas.py
Normal file
74
app/schemas.py
Normal file
@ -0,0 +1,74 @@
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import Optional, List
|
||||
|
||||
# ===================================================================
|
||||
# 基础模型 (Base Models)
|
||||
# ===================================================================
|
||||
|
||||
class UserInfo(BaseModel):
|
||||
"""用户的基本信息"""
|
||||
id: int = Field(..., description="用户的唯一ID", example=1001)
|
||||
name: str = Field(..., description="用户的姓名", example="张三")
|
||||
registered_faces_count: int = Field(..., description="该用户已注册的人脸数量", example=2)
|
||||
|
||||
class FaceLocation(BaseModel):
|
||||
"""人脸在图片中的位置和尺寸"""
|
||||
x: int = Field(..., description="人脸框左上角的X坐标")
|
||||
y: int = Field(..., description="人脸框左上角的Y坐标")
|
||||
width: int = Field(..., description="人脸框的宽度")
|
||||
height: int = Field(..., description="人脸框的高度")
|
||||
|
||||
# ===================================================================
|
||||
# API 请求模型 (Request Models)
|
||||
# ===================================================================
|
||||
|
||||
class ImageSource(BaseModel):
|
||||
"""图片来源,可以是URL或Base64编码的数据"""
|
||||
url: Optional[str] = Field(None, description="图片的URL地址", example="http://example.com/image.jpg")
|
||||
face_data: Optional[str] = Field(None, description="图片的Base64编码字符串")
|
||||
|
||||
class RegisterRequest(ImageSource):
|
||||
"""注册新用户的请求体"""
|
||||
id: int = Field(..., description="要注册用户的唯一ID", example=1001)
|
||||
name: str = Field(..., description="要注册用户的姓名", example="张三")
|
||||
|
||||
class VerifyRequest(ImageSource):
|
||||
"""1:1人脸认证的请求体"""
|
||||
id: int = Field(..., description="要验证的用户ID", example=1001)
|
||||
|
||||
# ===================================================================
|
||||
# API 响应模型 (Response Models)
|
||||
# ===================================================================
|
||||
|
||||
class StandardResponse(BaseModel):
|
||||
"""标准API响应模型"""
|
||||
code: int = Field(0, description="响应码,0为成功,非0为失败", example=0)
|
||||
message: str = Field("success", description="响应消息", example="操作成功")
|
||||
data: Optional[dict] = None
|
||||
|
||||
class UserListResponse(StandardResponse):
|
||||
"""获取用户列表的响应"""
|
||||
data: List[UserInfo]
|
||||
|
||||
class RegisterResponse(StandardResponse):
|
||||
"""注册成功后的响应"""
|
||||
data: UserInfo
|
||||
|
||||
class VerificationResult(BaseModel):
|
||||
"""1:1认证结果"""
|
||||
match: bool = Field(..., description="是否匹配")
|
||||
confidence: float = Field(..., description="置信度 (0.0 to 1.0)")
|
||||
|
||||
class VerifyResponse(StandardResponse):
|
||||
"""1:1人脸认证的响应"""
|
||||
data: VerificationResult
|
||||
|
||||
class DetectedFace(UserInfo):
|
||||
"""1:N识别结果中的单个人脸信息"""
|
||||
location: FaceLocation
|
||||
confidence: float = Field(..., description="识别的置信度")
|
||||
|
||||
class DetectResponse(StandardResponse):
|
||||
"""1:N人脸识别的响应"""
|
||||
data: List[DetectedFace]
|
Reference in New Issue
Block a user