覆盖所有模块: - api 层:17 个路由文件,每个接口标注用途、参数、返回值、权限 - services 层:18 个服务文件,每个方法标注作用、参数、返回值、调用方 - repositories 层:13 个仓储文件,每个方法标注查询逻辑和被调用方 - schemas 层:11 个请求/响应体文件,每个字段标注业务含义 - core 层:config、security、exceptions、responses、error_codes - models 层:19 个 ORM 模型类,每个表标注业务含义和关联关系 - scripts:bootstrap_data、smoke_check - migrations:env.py 和版本迁移文件 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
"""AI相关请求体Schema定义。
|
||
|
||
定义了AI识别、纠错和订单解析等功能的请求数据模型,
|
||
用于在API层进行请求参数校验和类型约束。
|
||
"""
|
||
|
||
from pydantic import BaseModel, Field, model_validator
|
||
|
||
|
||
class RecognizeImageRequest(BaseModel):
|
||
"""图片识别请求体。
|
||
|
||
用于提交图片URL进行AI识别,支持按业务类型和业务ID进行关联。
|
||
"""
|
||
|
||
image_url: str # 待识别的图片URL
|
||
biz_type: str # 业务类型标识
|
||
biz_id: int = Field(gt=0) # 业务记录ID,必须大于0
|
||
|
||
|
||
class CorrectRecognizeResultRequest(BaseModel):
|
||
"""AI识别结果纠错请求体。
|
||
|
||
用于用户对AI识别结果进行修正后提交。
|
||
"""
|
||
|
||
corrected_result: dict # 纠正后的识别结果,以字典形式存储
|
||
|
||
|
||
class ParseOrderRequest(BaseModel):
|
||
"""订单解析请求体。
|
||
|
||
支持文本和图片两种输入模式,根据 input_type 决定使用文本或图片进行订单解析。
|
||
通过 model_validator 对不同模式下的必填字段进行校验。
|
||
"""
|
||
|
||
input_type: str = Field(pattern="^(text|image)$") # 输入类型,仅允许 "text" 或 "image"
|
||
text: str | None = None # 文本模式下的输入文本
|
||
image_url: str | None = None # 图片模式下的图片URL
|
||
|
||
@model_validator(mode="after")
|
||
def validate_input(self):
|
||
"""校验输入参数的一致性。
|
||
|
||
根据 input_type 验证必填字段:文本模式要求 text 非空,
|
||
图片模式要求 image_url 非空。
|
||
|
||
Returns:
|
||
ParseOrderRequest: 校验通过后的自身实例。
|
||
"""
|
||
if self.input_type == "text" and not (self.text or "").strip():
|
||
raise ValueError("文本模式下 text 不能为空")
|
||
if self.input_type == "image" and not (self.image_url or "").strip():
|
||
raise ValueError("图片模式下 image_url 不能为空")
|
||
return self
|