gen_ai_hub.proxy.native.amazon package

gen_ai_hub.proxy.native.amazon.set_deployment(value)

Sets the current deployment in a context.

Parameters:

value (Any) – The deployment to set.

gen_ai_hub.proxy.native.amazon.get_current_deployment()

Gets the current deployment from the context.

Returns:

The current deployment.

Return type:

Any

gen_ai_hub.proxy.native.amazon.prepare_request_dict(request_dict, aicore_deployment, aicore_proxy_client)

Prepares the request dictionary for the AI Core proxy.

Parameters:
  • request_dict (dict) – the request dictionary to prepare

  • aicore_deployment (object) – the AI Core deployment

  • aicore_proxy_client (object) – the AI Core proxy client

Returns:

the prepared request dictionary

Return type:

dict

gen_ai_hub.proxy.native.amazon.tolerate_missing_model_id(kwargs)

Tolerates missing modelId in kwargs.

class gen_ai_hub.proxy.native.amazon.ClientWrapper(client, aicore_deployment, aicore_proxy_client)

Bases: BaseClient

Wraps and extends the boto3 BedrockRuntime class. boto3 is implemented in a way that a bedrock runtime class is created on the fly. Regular inheritance is therefor not possible. Instead, this wrapper inherits from the boto3 BaseClient class and is initialised with an instance of the bedrock runtime object. All attributes of the bedrock runtime object are copied over to the ClientWrapper object. Methods that need to be adjusted are regularly overwritten in case they are defined in the base class BaseClient (orginating from botocore). In case methods need to be adjusted that are dynamically added, they are also overwritten in regular fashion. The linter will not be able to verify the super methods existence though.

__init__(client, aicore_deployment, aicore_proxy_client)

Initializes the ClientWrapper.

Parameters:
  • client (BaseClient) – the boto3 bedrock runtime client

  • aicore_deployment (object) – the AI Core deployment

  • aicore_proxy_client (object) – the AI Core proxy client

converse(*args, **kwargs)

Tolerates missing parameters and calls original converse method.

converse_stream(*args, **kwargs)

Tolerates missing parameters and calls original converse_stream method.

invoke_model(*args, **kwargs)

Tolerates missing parameters and calls original invoke_model method.

invoke_model_with_response_stream(*args, **kwargs)

Tolerates missing parameters and calls original invoke_model_with_response_stream method.

If the user provides a timeout parameter, it is removed and ignored. Issues a deprecation warning.

class gen_ai_hub.proxy.native.amazon.Session(aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, region_name=None, botocore_session=None, profile_name=None, aws_account_id=None)

Bases: Session

Drop-in replacement for boto3.Session that uses the current deployment for amazon bedrock models

client(*args, model: str = '', deployment_id: str = '', model_name: str = '', model_version: str = '', config_id: str = '', config_name: str = '', proxy_client: BaseProxyClient | None = None, **kwargs)

Creates client for the bedrock runtime service.

Parameters:
  • model (str, optional) – the model identifier, defaults to “”

  • deployment_id (str, optional) – the deployment identifier, defaults to “”

  • model_name (str, optional) – the model name, defaults to “”

  • model_version (str, optional) – the model version, defaults to “”

  • config_id (str, optional) – the config identifier, defaults to “”

  • config_name (str, optional) – the config name, defaults to “”

  • proxy_client (Optional[BaseProxyClient], optional) – the proxy client, defaults to None

Raises:

NotImplementedError – if service_name is not bedrock-runtime

Returns:

the bedrock runtime client

Return type:

ClientWrapper

class gen_ai_hub.proxy.native.amazon.AsyncSession(**_kwargs)

Bases: object

Async session for Amazon Bedrock models that uses

the current deployment for amazon bedrock models.

Uses aiobotocore directly for async operations.

__init__(**_kwargs)

Initializes the AsyncSession.

All keyword arguments are passed to aiobotocore session configuration.

async async_client(*args, model: str = '', deployment_id: str = '', model_name: str = '', model_version: str = '', config_id: str = '', config_name: str = '', proxy_client: BaseProxyClient | None = None, **kwargs)

Creates async client for the bedrock runtime service.

Parameters:
  • model (str, optional) – the model identifier, defaults to “”

  • deployment_id (str, optional) – the deployment identifier, defaults to “”

  • model_name (str, optional) – the model name, defaults to “”

  • model_version (str, optional) – the model version, defaults to “”

  • config_id (str, optional) – the config identifier, defaults to “”

  • config_name (str, optional) – the config name, defaults to “”

  • proxy_client (Optional[BaseProxyClient], optional) – the proxy client, defaults to None

Raises:

NotImplementedError – if service_name is not bedrock-runtime

Returns:

the bedrock runtime async client

Return type:

AsyncClientWrapper

class gen_ai_hub.proxy.native.amazon.AsyncClientWrapper(client, aicore_deployment, aicore_proxy_client, context_manager)

Bases: AioBaseClient

Async client wrapper extending AioBaseClient of aiobotocore which provides async support for botocore.

__init__(client, aicore_deployment, aicore_proxy_client, context_manager)

Initializes the AsyncClientWrapper.

Parameters:
  • client (AioBaseClient) – the aiobotocore bedrock runtime client

  • aicore_deployment (object) – the AI Core deployment

  • aicore_proxy_client (object) – the AI Core proxy client

  • context_manager (context manager) – the client context manager for cleanup

async close()

Closes the client and releases resources.

async converse(*args, **kwargs)

Tolerates missing parameters and calls original converse method.

async converse_stream(*args, **kwargs)

Tolerates missing parameters and calls original converse method.

async invoke_model(*args, **kwargs)

Tolerates missing parameters and calls original invoke_model method.

async invoke_model_with_response_stream(*args, **kwargs)

Tolerates missing parameters and calls original invoke_model_with_response_stream method.

If the user provides a timeout parameter, it is removed and ignored. Issues a deprecation warning.

Submodules