yera.models.interfaces.llms.aws_bedrock
Module containing the interface to AWS bedrock LLMs.
Symbols
AwsBedrockLLM
BaseLLMInterfaceInterface to AWS Bedrock LLM models.
This class provides a wrapper around the AWS Bedrock runtime client, enabling interactions with various LLM models available through Bedrock (AWS Bedrock Claude, Qwen, OpenAI, DeepSeek, Google Gemini, and others). It supports both standard chat completions and structured output generation for models that support it.
The class automatically detects whether the selected model natively supports structured outputs or requires a tool-use fallback.
Attributes
Configuration settings for the LLM including model_id and inference parameters.
AWS connection configuration including credentials and region information.
Whether the selected model supports native structured output generation.
Lazy-initialized AWS Bedrock runtime client instance.
Methods
AwsBedrockLLM.start
start() → NoneInitialise the AWS Bedrock API client.
Creates and stores an AWS Bedrock client instance using the configured connection settings. This method must be called before making any API requests via the client property.
AwsBedrockLLM.stop
stop() → NoneShut down and clear the AWS Bedrock API client.
Releases the AWS Bedrock client instance by setting it to None. After calling this method, start() must be called again before further API requests can be made.
AwsBedrockLLM.chat
chat(
messages: list[Message],
**bedrock_kw,
) → Iterator[str]Stream a chat completion response from AWS Bedrock.
Sends a conversation to the configured Bedrock model and streams the response as text tokens. Messages are converted to Bedrock's message format, with system messages extracted and passed separately.
Parameters
List of Message objects representing the conversation history. Messages with role="system" are extracted and passed as system prompts. Other messages are converted to Bedrock message format.
Additional keyword arguments passed to the Bedrock API. The "inferenceConfig" key can be provided to customize model behavior (e.g., temperature, maxTokens).
AwsBedrockLLM.make_struct
make_struct(
messages: list[Message],
**bedrock_kw,
) → Iterator[str]Stream a structured output response conforming to a provided schema.
Generates a response that conforms to the structure defined by the provided Pydantic model class. Uses tool use to enforce strict adherence to the schema. Messages are converted to Bedrock's message format, with system messages extracted and passed separately.
Parameters
List of Message objects representing the conversation history. Messages with role="system" are extracted and passed as system prompts. Other messages are converted to Bedrock message format.
A Pydantic model class defining the desired output structure. The model will be transformed into a JSON schema for the tool.
Additional keyword arguments passed to the Bedrock API. The "inferenceConfig" key can be provided to customise model behaviour. Defaults to maxTokens=16384 and temperature=0.0 if not specified.