gen_ai_hub.proxy.gen_ai_hub_proxy.client module

class gen_ai_hub.proxy.gen_ai_hub_proxy.client.GenAIHubRestClient(proxy_client: GenAIHubProxyClient)

Bases: object

REST client with automatic header injection.

This client wraps the AI Core rest_client and ensures that all requests include: - Instance-level headers (set via proxy_client.set_headers_addition) - Request-level headers (set via temporary_headers_addition context manager)

Parameters:

proxy_client – The GenAIHubProxyClient instance to get the rest_client and headers from.

__init__(proxy_client: GenAIHubProxyClient)

Initialize the GenAIHubRestClient.

Parameters:

proxy_client – The GenAIHubProxyClient instance to get the rest_client and headers from.

get(path: str, **kwargs)

Send a GET request with injected headers.

Parameters:
  • path – The API path.

  • kwargs – Additional arguments to pass to the underlying rest_client.

Returns:

The response from the rest_client.

post(path: str, **kwargs)

Send a POST request with injected headers.

Parameters:
  • path – The API path.

  • kwargs – Additional arguments to pass to the underlying rest_client.

Returns:

The response from the rest_client.

delete(path: str, **kwargs)

Send a DELETE request with injected headers.

Parameters:
  • path – The API path.

  • kwargs – Additional arguments to pass to the underlying rest_client.

Returns:

The response from the rest_client.

patch(path: str, **kwargs)

Send a PATCH request with injected headers.

Parameters:
  • path – The API path.

  • kwargs – Additional arguments to pass to the underlying rest_client.

Returns:

The response from the rest_client.

gen_ai_hub.proxy.gen_ai_hub_proxy.client.temporary_headers_addition(headers: Dict[str, str])

Context manager to temporarily add headers to requests made by the GenAIHubProxyClient.

Parameters:

headers (Dict[str, str]) – Headers to add temporarily.

class gen_ai_hub.proxy.gen_ai_hub_proxy.client.Deployment(*, url: str, config_id: str, config_name: str, deployment_id: str, model_name: str, model_version: str | None = None, created_at: ~datetime.datetime, additonal_parameters: ~typing.Dict[str, str] = <factory>, custom_prediction_suffix: str | None = None)

Bases: BaseDeployment

Deployment class represents a deployment of a foundational model in the GenAI Hub.

url: str
config_id: str
config_name: str
deployment_id: str
model_name: str
model_version: str | None
created_at: datetime
additonal_parameters: Dict[str, str]
custom_prediction_suffix: str | None
additional_request_body_kwargs() Dict[str, Any]
classmethod get_model_identification_kwargs() Tuple[str]

Get model identification keywords.

Returns:

Tuple of model identification keywords.

Return type:

Tuple[str]

property prediction_url
model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

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

class gen_ai_hub.proxy.gen_ai_hub_proxy.client.FoundationalModelScenario(*, scenario_id: str, config_names: List[str] | str | None = None, model_name_parameter: str = 'model_name', prediction_url_suffix: str | None = None)

Bases: BaseModel

Represents a foundational model scenario in the GenAI Hub.

model_config: ClassVar[ConfigDict] = {'protected_namespaces': ()}

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

scenario_id: str
config_names: List[str] | str | None
model_name_parameter: str
prediction_url_suffix: str | None
classmethod adjust(data: Any) Any

Adjust input data before model initialization.

Parameters:

data (Any) – Input data to adjust.

Returns:

Adjusted data.

Return type:

Any

class gen_ai_hub.proxy.gen_ai_hub_proxy.client.InvalidDeploymentBehavior(*values)

Bases: str, Enum

warn = 'warn'
raise_error = 'raise_error'
ignore = 'ignore'
class gen_ai_hub.proxy.gen_ai_hub_proxy.client.GenAIHubProxyClient(*, base_url: str | None = None, auth_url: str | None = None, client_id: str | None = None, client_secret: str | None = None, resource_group: str | None = None, ai_core_client: AICoreV2Client | None = None, **extra_data: Any)

Bases: BaseProxyClient

GenAIHubProxyClient is a proxy client for interacting with the GenAI Hub.

model_config: ClassVar[ConfigDict] = {'arbitrary_types_allowed': True, 'extra': 'allow', 'protected_namespaces': ()}

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

base_url: str | None
auth_url: str | None
client_id: str | None
client_secret: str | None
resource_group: str | None
ai_core_client: AICoreV2Client | None
AI_CLIENT_TYPE_VAL: ClassVar[str] = 'GenAI Hub SDK (Python)'
foundational_model_scenarios: ClassVar[List[FoundationalModelScenario]] = [FoundationalModelScenario(scenario_id='foundation-models', config_names=['*'], model_name_parameter='model_name', prediction_url_suffix=None)]
default_values: ClassVar[Dict[str, Any]] = {}
on_invalid_deployments: ClassVar[InvalidDeploymentBehavior] = 'warn'
classmethod init_client(data: Any) Any

Initialize the client with the provided data.

Parameters:

data (Any) – Input data for client initialization.

Returns:

Initialized data.

Return type:

Any

property request_header: Dict[str, Any]
property deployments: List[Deployment]
property deployment_class: Type[Deployment]
select_deployment(raise_on_multiple: bool = False, **search_key_value)
get_additional_headers() Dict[str, str]

Get only the additional headers (instance-level and request-level).

Returns:

Additional headers.

Return type:

Dict[str, str]

set_headers_addition(headers: Dict[str, str])

Set additional headers for requests made by the client.

Parameters:

headers (Dict[str, str]) – Headers to add.

get_request_header()

Get the request headers for requests made by the client.

Returns:

Request headers.

Return type:

Dict[str, str]

get_deployments()

Get the list of deployments.

Returns:

List of deployments.

Return type:

List[Deployment]

update_deployments()

Update the list of deployments from the GenAI Hub.

Returns:

List of updated deployments.

Return type:

List[Deployment]

classmethod add_foundation_model_scenario(scenario_id, config_names: List[str] | None = None, prediction_url_suffix: str | None = None, model_name_parameter: str = 'model_name')

Add a foundational model scenario to the client.

Parameters:
  • scenario_id (str) – the scenario ID.

  • config_names (Optional[List[str]], optional) – list of configuration names, defaults to None

  • prediction_url_suffix (Optional[str], optional) – prediction URL suffix, defaults to None

  • model_name_parameter (str, optional) – model name parameter, defaults to ‘model_name’

get_ai_core_token()

Get the AI core token for authentication.

Returns:

AI core token.

Return type:

str

classmethod set_default_values(**kwargs)

Set default values for the client.

classmethod for_profile(profile: str = None)

Create a GenAIHubProxyClient instance for the given profile.

Parameters:

profile (str, optional) – Profile name, defaults to None

Returns:

GenAIHubProxyClient instance.

Return type:

GenAIHubProxyClient

model_post_init(context: Any, /) None

This function is meant to behave like a BaseModel method to initialize private attributes.

It takes context as an argument since that’s what pydantic-core passes when calling it.

Parameters:
  • self – The BaseModel instance.

  • context – The context.

gen_ai_hub.proxy.gen_ai_hub_proxy.client.camel_to_snake(name)

Convert camelCase or PascalCase string to snake_case.

Parameters:

name (str) – Input string in camelCase or PascalCase.

Returns:

String converted to snake_case.

Return type:

str

gen_ai_hub.proxy.gen_ai_hub_proxy.client.config_parameters(model_name_parameter, ai_core_client, deployment)

Get configuration parameters for a deployment.

Parameters:
  • model_name_parameter (str) – the model name parameter.

  • ai_core_client (AICoreV2Client) – the AI core client.

  • deployment (Deployment) – the deployment.

Returns:

Dictionary with model name and additional parameters.

Return type:

Dict[str, Any]