Skip to content

Module: service_models

Module containing data models used by the service

InfernetInput

Bases: BaseModel

Infernet containers must accept InfernetInput. Depending on the source (onchain vs. offchain), the associated data object is either a hex string from an onchain source meant to be decoded directly, or a data dictionary (off chain source).

Source code in src/infernet_ml/utils/service_models.py
class InfernetInput(BaseModel):
    """
    Infernet containers must accept InfernetInput. Depending on the source (onchain vs.
     offchain), the associated data object is either a hex string from an onchain
    source meant to be decoded directly, or a data dictionary (off chain source).
    """

    source: JobLocation
    destination: JobLocation
    data: Union[HexStr, dict[str, Any]]
    requires_proof: Optional[bool] = False

    @model_validator(mode="after")
    def check_data_correct(self) -> "InfernetInput":
        src = self.source
        dta = self.data
        if (
            src is not None
            and dta is not None
            and (
                (src == JobLocation.ONCHAIN and not isinstance(dta, str))
                or (src == JobLocation.OFFCHAIN and not isinstance(dta, dict))
            )
        ):
            raise ValueError(
                f"InfernetInput data type ({type(dta)}) incorrect for source ({str(src)})"  # noqa: E501
            )
        return self

JobLocation

Bases: IntEnum

Job location

Source code in src/infernet_ml/utils/service_models.py
class JobLocation(IntEnum):
    """Job location"""

    ONCHAIN = 0
    OFFCHAIN = 1
    STREAM = 2