gen_ai_hub.proxy.native.amazon package
Submodules
gen_ai_hub.proxy.native.amazon.clients module
This module provides client wrappers for synchronous and asynchronous interactions with the Amazon Bedrock Runtime service.
- class AsyncClientWrapper
Bases:
AioBaseClientAsync 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.
- class AsyncSession
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='', deployment_id='', model_name='', config_id='', config_name='', proxy_client=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 ""
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:
- class ClientWrapper
Bases:
BaseClientWraps 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 Session
Bases:
SessionDrop-in replacement for boto3.Session that uses the current deployment for amazon bedrock models
- client(*args, model='', deployment_id='', model_name='', config_id='', config_name='', proxy_client=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 ""
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:
- get_current_deployment()
Gets the current deployment from the context.
- Returns:
The current deployment.
- Return type:
Any
- 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
- set_deployment(value)
Sets the current deployment in a context.
- Parameters:
value (Any) -- The deployment to set.
- tolerate_missing_model_id(kwargs)
Tolerates missing modelId in kwargs.