26 lines
767 B
Python
26 lines
767 B
Python
from pydantic import BaseModel, Field, model_validator
|
|
|
|
|
|
class RecognizeImageRequest(BaseModel):
|
|
image_url: str
|
|
biz_type: str
|
|
biz_id: int = Field(gt=0)
|
|
|
|
|
|
class CorrectRecognizeResultRequest(BaseModel):
|
|
corrected_result: dict
|
|
|
|
|
|
class ParseOrderRequest(BaseModel):
|
|
input_type: str = Field(pattern="^(text|image)$")
|
|
text: str | None = None
|
|
image_url: str | None = None
|
|
|
|
@model_validator(mode="after")
|
|
def validate_input(self):
|
|
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
|