模型添加置信度设置,敏感词分页

This commit is contained in:
2025-09-15 17:43:36 +08:00
parent d9192bd964
commit 5959f9994c
4 changed files with 156 additions and 81 deletions

View File

@ -1,5 +1,6 @@
from datetime import datetime
from pydantic import BaseModel, Field
from typing import List, Optional
# ------------------------------
@ -7,24 +8,31 @@ from pydantic import BaseModel, Field
# ------------------------------
class SensitiveCreateRequest(BaseModel):
"""创建敏感信息记录请求模型"""
# 移除了id字段、由数据库自动生成
name: str = Field(None, max_length=255, description="名称")
name: str = Field(..., max_length=255, description="敏感词内容(必填)")
class SensitiveUpdateRequest(BaseModel):
"""更新敏感信息记录请求模型"""
name: str = Field(None, max_length=255, description="名称")
name: Optional[str] = Field(None, max_length=255, description="敏感词内容(可选修改)")
# ------------------------------
# 响应模型(后端返回数据)
# ------------------------------
class SensitiveResponse(BaseModel):
"""敏感信息记录响应模型"""
id: int = Field(..., description="主键ID") # 响应中仍然包含ID
name: str = Field(None, description="名称")
"""敏感信息单条记录响应模型"""
id: int = Field(..., description="主键ID")
name: str = Field(..., description="敏感词内容")
created_at: datetime = Field(..., description="记录创建时间")
updated_at: datetime = Field(..., description="记录更新时间")
# 支持从数据库查询结果转换
# 支持从数据库查询结果(字典/对象)自动转换
model_config = {"from_attributes": True}
class SensitiveListResponse(BaseModel):
"""敏感信息分页列表响应模型(新增)"""
total: int = Field(..., description="敏感词总记录数")
sensitives: List[SensitiveResponse] = Field(..., description="当前页敏感词列表")
model_config = {"from_attributes": True}