ai_api_client_sdk.helpers package

Submodules

ai_api_client_sdk.helpers.authenticator module

class Authenticator

Bases: object

Authenticator class is implemented to retrieve and cache the authorization token from the xsuaa server

Parameters:
  • auth_url (str) -- URL of the authorization endpoint. Should be the full URL (including /oauth/token)

  • client_id (str) -- client id to be used for authorization

  • client_secret (str, optional) -- client secret to be used for authorization, either client_secret or (cert_file_path and key_file_path) need to be provided, defaults to None

  • cert_str (str, optional) -- certificate file content, needs to be provided alongside the key_str parameter, defaults to None

  • key_str (str, optional) -- key file content, needs to be provided alongside the cert_str parameter, defaults to None

  • cert_file_path (str, optional) -- path to the certificate file, needs to be provided alongside the key_file_path parameter, defaults to None

  • key_file_path (str, optional) -- path to the key file, needs to be provided alongside the cert_file_path parameter, defaults to None

__init__(auth_url, client_id, client_secret=None, cert_str=None, key_str=None, cert_file_path=None, key_file_path=None)
Parameters:
  • auth_url (str)

  • client_id (str)

  • client_secret (str)

  • cert_str (str)

  • key_str (str)

  • cert_file_path (str)

  • key_file_path (str)

get_token()

Retrieves the token from the xsuaa server or from cache when expiration date not reached.

Raises:

class:ai_api_client_sdk.exception.AIAPIAuthenticatorException if an unexpected exception occurs while trying to retrieve the token

Returns:

The Bearer token

Return type:

str

ai_api_client_sdk.helpers.constants module

class Timeouts

Bases: Enum

CONNECT_TIMEOUT = 60
NUM_REQUEST_RETRIES = 3
READ_TIMEOUT = 60

ai_api_client_sdk.helpers.datetime_parser module

parse_datetime(datetime_str)
Parameters:

datetime_str (str)

Return type:

datetime

ai_api_client_sdk.helpers.llm_helper module

check_if_llm_scenario(scenario)
filter_for_llm_scenarios(response_dict)
get_attr(obj, attr)
get_key(obj, *, attr='key')
get_labels(obj, *, attr='labels')
get_value(obj, *, attr='value')

ai_api_client_sdk.helpers.logging module

get_logger()
get_logger_name()
set_log_level(logger)
Parameters:

logger (Logger)

ai_api_client_sdk.helpers.rest_client module

class RestClient

Bases: object

RestClient is the class implemented for sending the requests to the server.

Parameters:
  • base_url (str) -- Base URL of the server. Should include the base path as well. (i.e., "<base_url>/scenarios" should work)

  • get_token (Callable[[], str]) -- the function which returns the Bearer token, when called

  • resource_group (str) -- The default resource group which will be used while sending the requests to the server, defaults to None

  • client_type (str) -- Used for Metering to distinguish eg AI Launchpad python SDKs etc, defaults to None

  • read_timeout (int) -- Read timeout for requests in seconds, defaults to 60s

  • connect_timeout (int) -- Connect timeout for requests in seconds, defaults to 60s

  • num_request_retries (int) -- Number of retries for failing requests with http status code 429, 500, 502, 503 or 504, defaults to 60s

static raise_ai_api_exception(error_description, response, response_json)
__init__(base_url, get_token, resource_group=None, client_type=None, read_timeout=60, connect_timeout=60, num_request_retries=3)
Parameters:
  • base_url (str)

  • get_token (Callable[[], str])

  • resource_group (str)

  • client_type (str)

delete(path, params=None, headers=None, resource_group=None, **kwargs)

Sends a DELETE request to the server.

Parameters:
  • path (str) -- path of the endpoint the request should be sent to

  • params (Dict[str, str], optional) -- parameters of the request, defaults to None

  • headers (Dict[str, str], optional) -- headers of the request, defaults to None

  • resource_group (str) -- Resource Group which the request should be sent on behalf. Either this, or the resource_group property of this class should be set.

  • kwargs (dict) -- additional keyword arguments to be passed to the request e.g. files, stream, etc.

Raises:

class:ai_api_client_sdk.exception.AIAPIInvalidRequestException if a 400 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIAuthorizationException if a 401 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPINotFoundException if a 404 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIPreconditionFailedException if a 412 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIServerException if a non-2XX response is received from the server

Returns:

The JSON response from the server (The keys decamelized)

Return type:

dict

get(path, params=None, headers=None, resource_group=None, return_bytes_content=False, **kwargs)

Sends a GET request to the server.

Parameters:
  • path (str) -- path of the endpoint the request should be sent to

  • params (Dict[str, str], optional) -- parameters of the request, defaults to None

  • headers (Dict[str, str], optional) -- headers of the request, defaults to None

  • resource_group (str) -- Resource Group which the request should be sent on behalf. Either this, or the resource_group property of this class should be set.

  • return_bytes_content (bool) -- expected response.content is bytes

  • kwargs (dict) -- additional keyword arguments to be passed to the request e.g. files, stream, etc.

Raises:

class:ai_api_client_sdk.exception.AIAPIInvalidRequestException if a 400 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIAuthorizationException if a 401 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPINotFoundException if a 404 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIPreconditionFailedException if a 412 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIServerException if a non-2XX response is received from the server

Returns:

The JSON response from the server (The keys decamelized)

Return type:

Union[dict, int]

patch(path, body, headers=None, resource_group=None, **kwargs)

Sends a PATCH request to the server.

Parameters:
  • path (str) -- path of the endpoint the request should be sent to

  • body (Dict[str, Union[str, dict, list]]) -- body of the request

  • headers (Dict[str, str], optional) -- headers of the request, defaults to None

  • resource_group (str) -- Resource Group which the request should be sent on behalf. Either this, or the resource_group property of this class should be set.

  • kwargs (dict) -- additional keyword arguments to be passed to the request e.g. files, stream, etc.

Raises:

class:ai_api_client_sdk.exception.AIAPIInvalidRequestException if a 400 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIAuthorizationException if a 401 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPINotFoundException if a 404 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIPreconditionFailedException if a 412 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIServerException if a non-2XX response is received from the server

Returns:

The JSON response from the server (The keys decamelized)

Return type:

dict

post(path, body=None, headers=None, resource_group=None, **kwargs)

Sends a POST request to the server.

Parameters:
  • path (str) -- path of the endpoint the request should be sent to

  • body (Dict[str, str], optional) -- body of the request, defaults to None

  • headers (Dict[str, str], optional) -- headers of the request, defaults to None

  • resource_group (str) -- Resource Group which the request should be sent on behalf. Either this, or the resource_group property of this class should be set.

  • kwargs (dict) -- additional keyword arguments to be passed to the request e.g. files, stream, etc.

Raises:

class:ai_api_client_sdk.exception.AIAPIInvalidRequestException if a 400 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIAuthorizationException if a 401 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPINotFoundException if a 404 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIPreconditionFailedException if a 412 response is received from the server

Raises:

class:ai_api_client_sdk.exception.AIAPIServerException if a non-2XX response is received from the server

Returns:

The JSON response from the server (The keys decamelized)

Return type:

dict

logger = <Logger ai-api-client-sdk (WARNING)>