File size: 1,036 Bytes
f1ba785
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Pydantic transport models mirroring numeric-inference.v1.schema.json."""
from typing import Literal

from pydantic import BaseModel, ConfigDict, Field, field_validator

from .contracts import SemanticClass


class NumericRequest(BaseModel):
    model_config = ConfigDict(extra="forbid")
    contractVersion: Literal[1]
    requestId: str = Field(min_length=1, max_length=128)
    zoneId: str = Field(min_length=1, max_length=128)
    imageBase64: str = Field(min_length=1, max_length=8_388_608)
    mimeType: Literal["image/png", "image/jpeg", "image/webp"]
    semanticClass: SemanticClass
    expectedLength: int | None = Field(default=None, ge=1, le=64)
    locale: Literal["ar-EG", "en-EG"] | None = None

    @field_validator("imageBase64")
    @classmethod
    def validate_base64_shape(cls, value: str) -> str:
        if any(char not in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" for char in value):
            raise ValueError("invalid_image_payload")
        return value