gen_ai_hub.proxy.native.sap package

Submodules

gen_ai_hub.proxy.native.sap.client module

class RPTClient

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=None, timeout=None)
Parameters:
async apredict(body, deployment_url=None, model_name=None, timeout=None, **kwargs)

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.

  • 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, deployment_url=None, model_name=None, timeout=None, **kwargs)

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.

  • 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.

gen_ai_hub.proxy.native.sap.models module

exception RPTException

Bases: Exception

Exception representing an error response from the RPT service.

Parameters:
__init__(status, detail=None)
Parameters:
class DataType

Bases: BaseModel

Schema definition for a column.

Parameters:

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

dtype: Literal['string', 'numeric', 'date']
model_config: ClassVar[ConfigDict] = {}

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

class ErrorResponseDetails

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.

loc: list
model_config: ClassVar[ConfigDict] = {}

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

msg: str
type: str
class Prediction

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 PredictionConfig

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 PredictionItem

Bases: BaseModel

Single prediction result.

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

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

confidence: float | None
model_config: ClassVar[ConfigDict] = {}

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

prediction: str | float
class RPTRequest

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_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

columns: dict[str, list] | None
data_schema: dict[str, DataType] | None
index_column: str | None
model_config: ClassVar[ConfigDict] = {}

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

parse_data_types: bool
prediction_config: PredictionConfig
rows: list[dict] | None
class RPTResponse

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.

id: str
metadata: ResponseMetadata
model_config: ClassVar[ConfigDict] = {}

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

predictions: list[Prediction]
status: ResponseStatus
class ResponseMetadata

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_columns: int
num_predictions: int
num_query_rows: int
num_rows: int
class ResponseStatus

Bases: BaseModel

Status information for a prediction request.

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

  • message (str) -- Status message.

code: int
message: str
model_config: ClassVar[ConfigDict] = {}

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

class TargetColumn

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