caikit.runtime.http_server.pydantic_wrapper

This module holds the Pydantic wrapping required by the REST server, capable of converting to and from Pydantic models to our DataObjects.

Attributes

log

PYDANTIC_TO_DM_MAPPING

Functions

pydantic_to_dataobject(...)

Convert pydantic objects to our DM objects

dataobject_to_pydantic(→ Type[pydantic.BaseModel])

Make a pydantic model based on the given proto message by using the data

_get_pydantic_type(→ type)

Recursive helper to get a valid pydantic type for every field type

_conditionally_convert_dataobject(→ Any)

_from_base64(→ bytes)

pydantic_from_request(pydantic_model, request)

Function to convert a fastapi request into a given pydantic model. This

_parse_form_data_to_pydantic(→ pydantic.BaseModel)

Helper function to parse a fastapi form data into a pydantic model

_get_pydantic_subtypes(→ List[type])

Recursive helper to get the type_hint for a field

Module Contents

caikit.runtime.http_server.pydantic_wrapper.log[source]
caikit.runtime.http_server.pydantic_wrapper.PYDANTIC_TO_DM_MAPPING
caikit.runtime.http_server.pydantic_wrapper.pydantic_to_dataobject(pydantic_model: pydantic.BaseModel) caikit.core.data_model.base.DataBase[source]

Convert pydantic objects to our DM objects

caikit.runtime.http_server.pydantic_wrapper.dataobject_to_pydantic(dm_class: Type[caikit.core.data_model.base.DataBase]) Type[pydantic.BaseModel][source]

Make a pydantic model based on the given proto message by using the data model class annotations to mirror as a pydantic model

caikit.runtime.http_server.pydantic_wrapper._get_pydantic_type(field_type: type) type[source]

Recursive helper to get a valid pydantic type for every field type

caikit.runtime.http_server.pydantic_wrapper._conditionally_convert_dataobject(obj: Any) Any[source]
caikit.runtime.http_server.pydantic_wrapper._from_base64(data: bytes | str) bytes[source]
async caikit.runtime.http_server.pydantic_wrapper.pydantic_from_request(pydantic_model: Type[pydantic.BaseModel], request: fastapi.Request)[source]

Function to convert a fastapi request into a given pydantic model. This function parses the requests Content-Type and then correctly decodes the data. The currently supported Content-Types are application/json and multipart/form-data

caikit.runtime.http_server.pydantic_wrapper._parse_form_data_to_pydantic(pydantic_model: Type[pydantic.BaseModel], form_data: fastapi.datastructures.FormData) pydantic.BaseModel[source]

Helper function to parse a fastapi form data into a pydantic model

caikit.runtime.http_server.pydantic_wrapper._get_pydantic_subtypes(pydantic_model: Type[pydantic.BaseModel], keys: List[str]) List[type][source]

Recursive helper to get the type_hint for a field