gen_ai_hub.proxy.native.sap package

class gen_ai_hub.proxy.native.sap.RPTClient(proxy_client: GenAIHubProxyClient | None = None, timeout: int | float | Timeout | None = None)

Bases: object

Handles interaction with RPT models for making predictions.

This class acts as a client for executing prediction requests using RPT models deployed via the Gen AI Hub. It retrieves deployment information, handles timeouts, and processes request and response data.

Parameters:
  • proxy_client (Optional[GenAIHubProxyClient]) – Proxy client for interacting with the Gen AI Hub API. If not provided, a default implementation is used.

  • timeout (Union[int, float, httpx.Timeout, None]) – Default timeout value for the HTTP client used for requests.

__init__(proxy_client: GenAIHubProxyClient | None = None, timeout: int | float | Timeout | None = None)
async apredict(body: dict | RPTRequest, deployment_url: str | None = None, model_name: str | None = None, model_version: str | None = None, timeout: int | float | Timeout | None = None, **kwargs) RPTResponse

Asynchronously executes a prediction request by sending the provided data and deployment parameters.

The body parameter can be supplied either as a dictionary or as an instance of RPTRequest.

Parameters:
  • body (Union[dict, RPTRequest]) – The input data for the prediction request, represented either as a dictionary or an RPTRequest object.

  • deployment_url (Optional[str]) – The URL of the deployment to use for prediction. If not provided, model_name or other deployment parameters must be specified.

  • model_name (Optional[str]) – The name of the model to use for prediction. If not provided, api_url or other deployment parameters must be specified.

  • model_version (Optional[str]) – The version of the model to use for prediction. Could be provided only if model_name is provided.

  • timeout (Union[int, float, httpx.Timeout, None]) – The time duration to wait for the prediction request to complete. Can be an integer, float, or an instance of httpx.Timeout.

Returns:

The response received from the prediction endpoint, represented as an RPTResponse object.

Return type:

RPTResponse

Raises:

ValueError – If no deployment is found for the given parameters.

predict(body: dict | RPTRequest, deployment_url: str | None = None, model_name: str | None = None, model_version: str | None = None, timeout: int | float | Timeout | None = None, **kwargs) RPTResponse

Executes a prediction request by sending the provided data and deployment parameters.

The body parameter can be supplied either as a dictionary or as an instance of RPTRequest.

Parameters:
  • body (Union[dict, RPTRequest]) – The input data for the prediction request, represented either as a dictionary or an RPTRequest object.

  • deployment_url (Optional[str]) – The URL of the deployment to use for prediction. If not provided, model_name or other deployment parameters must be specified.

  • model_name (Optional[str]) – The name of the model to use for prediction. If not provided, api_url or other deployment parameters must be specified.

  • model_version (Optional[str]) – The version of the model to use for prediction. Could be provided only if model_name is provided.

  • timeout (Union[int, float, httpx.Timeout, None]) – The time duration to wait for the prediction request to complete. Can be an integer, float, or an instance of httpx.Timeout.

Returns:

The response received from the prediction endpoint, represented as an RPTResponse object.

Return type:

RPTResponse

Raises:

ValueError – If no deployment is found for the given parameters.

class gen_ai_hub.proxy.native.sap.TargetColumn(*, name: str, prediction_placeholder: str = '[PREDICT]', task_type: Literal['classification', 'regression'] | None = None)

Bases: BaseModel

Represents a target column in data.

Parameters:
  • name (str) – Name of the target column.

  • prediction_placeholder (str) – Placeholder string denoting where predictions will be inserted. Defaults to "[PREDICT]".

  • task_type (Optional[Literal["classification", "regression"]]) – Task type of the target column. One of "classification" or "regression". Defaults to None.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

name: str
prediction_placeholder: str
task_type: Literal['classification', 'regression'] | None
class gen_ai_hub.proxy.native.sap.RPTRequest(*, prediction_config: PredictionConfig, index_column: str | None = None, rows: list[dict] | None = None, columns: dict[str, list] | None = None, data_schema: dict[str, DataType] | None = None, parse_data_types: bool = True)

Bases: BaseModel

Request model for predictions.

Provide exactly one of rows or columns.

Parameters:
  • prediction_config (PredictionConfig) – Configuration describing what to predict.

  • index_column (Optional[str]) – Name of a column used to identify the row. This column is not used as an input feature and may be returned in the response objects.

  • rows (Optional[list[dict]]) – Array of objects representing table rows (both context and query rows).

  • columns (Optional[dict[str, list]]) – Mapping from column name to array of column values.

  • data_schema (Optional[dict[str, DataType]]) – Schema definition for all columns, e.g. {"columnA": {"dtype": "string"}, "columnB": {"dtype": "numeric"}}.

  • parse_data_types (bool) – Relevant when data_schema is not provided. Whether to parse data types (e.g., interpret strings as numbers or dates). Defaults to True.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

model_dump(**kwargs)

Serialize the model to a dictionary.

Ensures the non-provided alternative (rows or columns) is omitted from the dump and that None values are excluded.

Parameters:

kwargs (Any) – Keyword arguments forwarded to pydantic.BaseModel.model_dump.

Returns:

Serialized dictionary representation of the model.

Return type:

dict

validate_rows_xor_columns()

Validate that exactly one of rows or columns is provided.

Raises:

ValueError – If neither or both of rows and columns are provided.

Returns:

The validated request instance.

Return type:

RPTRequest

prediction_config: PredictionConfig
index_column: str | None
rows: list[dict] | None
columns: dict[str, list] | None
data_schema: dict[str, DataType] | None
parse_data_types: bool
class gen_ai_hub.proxy.native.sap.RPTResponse(*, id: str, status: ResponseStatus, predictions: list[Prediction], metadata: ResponseMetadata)

Bases: BaseModel

Response model for an RPT request.

Parameters:
  • id (str) – Unique identifier for the response.

  • status (ResponseStatus) – Status describing the outcome of the request.

  • predictions (list[Prediction]) – Prediction data returned by the service.

  • metadata (ResponseMetadata) – Metadata about the request/response.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

id: str
status: ResponseStatus
predictions: list[Prediction]
metadata: ResponseMetadata
exception gen_ai_hub.proxy.native.sap.RPTException(status: ResponseStatus, detail: list[ErrorResponseDetails] | None = None)

Bases: Exception

Exception representing an error response from the RPT service.

Parameters:
__init__(status: ResponseStatus, detail: list[ErrorResponseDetails] | None = None)
class gen_ai_hub.proxy.native.sap.ResponseStatus(*, code: int, message: str)

Bases: BaseModel

Status information for a prediction request.

Parameters:
  • code (int) – Numeric status code.

  • message (str) – Status message.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

code: int
message: str
class gen_ai_hub.proxy.native.sap.ResponseMetadata(*, num_rows: int, num_columns: int, num_predictions: int, num_query_rows: int)

Bases: BaseModel

Response metadata.

Parameters:
  • num_rows (int) – Total number of input rows.

  • num_columns (int) – Total number of input columns.

  • num_predictions (int) – Number of table cells containing the specified placeholder values, summed over all target columns.

  • num_query_rows (int) – Number of query rows for which a prediction was made.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

num_rows: int
num_columns: int
num_predictions: int
num_query_rows: int
class gen_ai_hub.proxy.native.sap.Prediction(root: RootModelRootType = PydanticUndefined)

Bases: RootModel[dict[str, Union[list[PredictionItem], Any]]]

Container for prediction results keyed by target column name.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

root: RootModelRootType
class gen_ai_hub.proxy.native.sap.PredictionItem(*, prediction: str | float, confidence: float | None = None)

Bases: BaseModel

Single prediction result.

Parameters:
  • prediction (Union[str, float]) – The predicted value.

  • confidence (Optional[float]) – Confidence score for classification tasks. Defaults to None.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

prediction: str | float
confidence: float | None
class gen_ai_hub.proxy.native.sap.PredictionConfig(*, target_columns: list[TargetColumn])

Bases: BaseModel

The configuration object specifying which columns to predict

Parameters:

target_columns (list[TargetColumn]) – List of target columns to predict.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

target_columns: list[TargetColumn]
class gen_ai_hub.proxy.native.sap.ErrorResponseDetails(*, loc: list, msg: str, type: str)

Bases: BaseModel

Details of an error response.

Parameters:
  • loc (list) – Location in the request where the error occurred.

  • msg (str) – Human-readable error message.

  • type (str) – Error category/type.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

loc: list
msg: str
type: str
class gen_ai_hub.proxy.native.sap.DataType(*, dtype: Literal['string', 'numeric', 'date'])

Bases: BaseModel

Schema definition for a column.

Parameters:

dtype (Literal["string", "numeric", "date"]) – The data type of the column.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

dtype: Literal['string', 'numeric', 'date']

Submodules