yera.models.interfaces.llms.aws_bedrock

Module containing the interface to AWS bedrock LLMs.

Symbols

class AwsBedrockLLM — Interface to AWS Bedrock LLM models.

AwsBedrockLLM

Interface 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

config
type: LLMConfig

Configuration settings for the LLM including model_id and inference parameters.

connection
type: AWSConnection

AWS connection configuration including credentials and region information.

native_struct
type: bool

Whether the selected model supports native structured output generation.

client
type: BaseClient

Lazy-initialized AWS Bedrock runtime client instance.

Methods

start — Initialise the AWS Bedrock API client.
stop — Shut down and clear the AWS Bedrock API client.
chat — Stream a chat completion response from AWS Bedrock.
make_struct — Stream a structured output response conforming to a provided schema.

AwsBedrockLLM.start

start() → None

Initialise 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() → None

Shut 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

messages
type: list[Message]

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.

**bedrock_kw
type: str | int | float | bool

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

messages
type: list[Message]

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.

cls
type: type[TStruct]

A Pydantic model class defining the desired output structure. The model will be transformed into a JSON schema for the tool.

**bedrock_kw
type: str | int | float | bool

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.