Class: RubyLLM::Providers::Bedrock

Inherits:
RubyLLM::Provider show all
Includes:
Auth, Chat, Media, Models, Streaming
Defined in:
lib/ruby_llm/providers/bedrock.rb,
lib/ruby_llm/providers/bedrock/auth.rb,
lib/ruby_llm/providers/bedrock/chat.rb,
lib/ruby_llm/providers/bedrock/media.rb,
lib/ruby_llm/providers/bedrock/models.rb,
lib/ruby_llm/providers/bedrock/streaming.rb

Overview

AWS Bedrock Converse API integration.

Defined Under Namespace

Modules: Auth, Chat, Media, Models, Streaming

Constant Summary

Constants included from Models

Models::REGION_PREFIXES

Instance Attribute Summary

Attributes inherited from RubyLLM::Provider

#config, #connection

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Models

create_model_info, model_id_with_region, models_api_base, models_url, normalize_inference_profile_id, normalize_modalities, parse_capabilities, parse_context_window, parse_list_models_response, reasoning_embedded?, region_prefix, region_prefixed?, with_region_prefix

Methods included from Media

empty_content?, render_attachment, render_content, render_content_object, render_document_attachment, render_image_attachment, render_raw_content, sanitize_document_name, unique_document_name

Methods included from Chat

budget_reasoning_config, completion_url, default_input_schema, effort_reasoning_config, normalize_tool_result_block, parse_completion_response, parse_reasoning_content_block, parse_text_content, parse_thinking, parse_tool_calls, render_additional_model_request_fields, render_inference_config, render_message_content, render_messages, render_non_tool_message, render_payload, render_raw_content, render_raw_tool_result_content, render_reasoning_fields, render_role, render_system, render_thinking_block, render_tool, render_tool_config, render_tool_result_block, render_tool_result_content, sanitize_non_assistant_raw_blocks, tool_result_content_block?

Methods inherited from RubyLLM::Provider

assume_models_exist?, #assume_models_exist?, capabilities, #capabilities, #configuration_requirements, configured?, #configured?, configured_providers, configured_remote_providers, #embed, for, #format_messages, #format_tool_calls, #initialize, #local?, local?, local_providers, #moderate, #name, name, #paint, #parse_tool_calls, providers, register, remote?, #remote?, remote_providers, resolve, slug, #slug, #transcribe

Methods included from Streaming

build_on_data_handler, build_stream_error_response, error_chunk?, faraday_1?, handle_data, handle_error_chunk, handle_error_event, handle_failed_response, handle_json_error_chunk, handle_parsed_error, handle_sse, handle_stream, json_error_payload?, parse_error_from_json, parse_streaming_error, process_stream_chunk, stream_response

Constructor Details

This class inherits a constructor from RubyLLM::Provider

Class Method Details

.configuration_requirementsObject



52
53
54
# File 'lib/ruby_llm/providers/bedrock.rb', line 52

def configuration_requirements
  %i[bedrock_api_key bedrock_secret_key bedrock_region]
end

Instance Method Details

#api_baseObject



13
14
15
# File 'lib/ruby_llm/providers/bedrock.rb', line 13

def api_base
  "https://bedrock-runtime.#{bedrock_region}.amazonaws.com"
end

#complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil) ⇒ Object

rubocop:disable Metrics/ParameterLists



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ruby_llm/providers/bedrock.rb', line 21

def complete(messages, tools:, temperature:, model:, params: {}, headers: {}, schema: nil, thinking: nil, &) # rubocop:disable Metrics/ParameterLists
  normalized_params = normalize_params(params, model:)

  super(
    messages,
    tools: tools,
    temperature: temperature,
    model: model,
    params: normalized_params,
    headers: headers,
    schema: schema,
    thinking: thinking,
    &
  )
end

#headersObject



17
18
19
# File 'lib/ruby_llm/providers/bedrock.rb', line 17

def headers
  {}
end

#list_modelsObject



46
47
48
49
# File 'lib/ruby_llm/providers/bedrock.rb', line 46

def list_models
  response = signed_get(models_api_base, models_url)
  parse_list_models_response(response, slug, capabilities)
end

#parse_error(response) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/ruby_llm/providers/bedrock.rb', line 37

def parse_error(response)
  return if response.body.nil? || response.body.empty?

  body = try_parse_json(response.body)
  return body if body.is_a?(String)

  body['message'] || body['Message'] || body['error'] || body['__type'] || super
end