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`

    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    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`

    15
    16
    17
    18
    19
    20
    class JobLocation(IntEnum):
        """Job location"""

        ONCHAIN = 0
        OFFCHAIN = 1
        STREAM = 2