bedrock_client#

AWS Bedrock ModelClient integration.

Functions

get_first_message_content(completion)

When we only need the content of the first message.

Classes

BedrockAPIClient([aws_profile_name, ...])

A component wrapper for the Bedrock API client.

Constants

bedrock_runtime_exceptions = <botocore.errorfactory.BedrockRuntimeExceptions object>#
class BedrockAPIClient(aws_profile_name=None, aws_region_name=None, aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, aws_connection_timeout=None, aws_read_timeout=None, chat_completion_parser: Callable = None)[source]#

Bases: ModelClient

A component wrapper for the Bedrock API client. Visit https://docs.aws.amazon.com/bedrock/latest/APIReference/welcome.html for more api details.

init_sync_client()[source]#

There is no need to pass both profile and secret key and access key. Path one of them. if the compute power assume a role that have access to bedrock, no need to pass anything.

init_async_client()[source]#
parse_chat_completion(completion)[source]#

Parse the chat completion to str.

track_completion_usage(completion: Dict) CompletionUsage[source]#

Track the completion usage.

convert_inputs_to_api_kwargs(input: Any | None = None, model_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED)[source]#

check the converse api doc here: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/bedrock-runtime/client/converse.html

call(api_kwargs: Dict = {}, model_type: ModelType = ModelType.UNDEFINED)[source]#

kwargs is the combined input and model_kwargs

async acall()[source]#

Subclass use this to call the API with the async client.

get_first_message_content(completion: Dict) str[source]#

When we only need the content of the first message. It is the default parser for chat completion.