gen_ai_hub.proxy.native.sap package
Submodules
gen_ai_hub.proxy.native.sap.client module
- class RPTClient
Bases:
objectHandles 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:
proxy_client (GenAIHubProxyClient | None)
timeout (int | float | Timeout | None)
- 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:
- 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:
- Raises:
ValueError -- If no deployment is found for the given parameters.
gen_ai_hub.proxy.native.sap.models module
- exception RPTException
Bases:
ExceptionException representing an error response from the RPT service.
- Parameters:
status (ResponseStatus) -- Status indicating the error category/type.
detail (Optional[list[ErrorResponseDetails]]) -- Optional list of additional error details.
- __init__(status, detail=None)
- Parameters:
status (ResponseStatus)
detail (list[ErrorResponseDetails] | None)
- class DataType
Bases:
BaseModelSchema 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:
BaseModelDetails 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:
BaseModelThe 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:
BaseModelSingle 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:
BaseModelRequest model for predictions.
Provide exactly one of
rowsorcolumns.- 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_schemais not provided. Whether to parse data types (e.g., interpret strings as numbers or dates). Defaults toTrue.
- model_dump(**kwargs)
Serialize the model to a dictionary.
Ensures the non-provided alternative (
rowsorcolumns) is omitted from the dump and thatNonevalues 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
rowsorcolumnsis provided.- Raises:
ValueError -- If neither or both of
rowsandcolumnsare provided.- Returns:
The validated request instance.
- Return type:
- 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:
BaseModelResponse 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:
BaseModelResponse 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:
BaseModelStatus 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:
BaseModelRepresents 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 toNone.
- 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