| 131 | return _validate_base64_payload(value, 'image') |
| 132 | |
| 133 | class OCRRequest(Base64Image): |
| 134 | probability: bool = Field(False, description="是否返回识别概率") |
| 135 | colors: List[str] = Field(default_factory=list, description="颜色过滤列表") |
| 136 | custom_color_ranges: Optional[Dict[str, List[List[int]]]] = Field(None, description="自定义颜色范围") |
| 137 | |
| 138 | @field_validator('colors') |
| 139 | def validate_colors(cls, value): |
| 140 | if value is None: |
| 141 | return [] |
| 142 | if not isinstance(value, list): |
| 143 | raise ValueError('colors 必须是字符串列表') |
| 144 | normalized = [] |
| 145 | for item in value: |
| 146 | if not isinstance(item, str): |
| 147 | raise ValueError('colors 中的元素必须是字符串') |
| 148 | stripped = item.strip() |
| 149 | if not stripped: |
| 150 | raise ValueError('colors 不允许包含空字符串') |
| 151 | normalized.append(stripped) |
| 152 | return normalized |
| 153 | |
| 154 | @field_validator('custom_color_ranges') |
| 155 | def validate_custom_ranges(cls, value): |
| 156 | if value is None: |
| 157 | return value |
| 158 | return _validate_custom_range_dict(value) |
| 159 | |
| 160 | class SlideMatchRequest(BaseModel): |
| 161 | target_image: str = Field(..., description="目标图片的Base64编码") |
no outgoing calls
no test coverage detected
searching dependent graphs…