Module: RubyLLM::Providers::Bedrock::Models
- Included in:
- RubyLLM::Providers::Bedrock
- Defined in:
- lib/ruby_llm/providers/bedrock/models.rb
Overview
Models methods for the AWS Bedrock API implementation
Class Method Summary collapse
- .create_model_info(model_data, slug, _capabilities) ⇒ Object
- .inference_profile_region_prefix ⇒ Object
- .model_id_with_region(model_id, model_data) ⇒ Object
- .models_url ⇒ Object
- .parse_list_models_response(response, slug, capabilities) ⇒ Object
Instance Method Summary collapse
Class Method Details
.create_model_info(model_data, slug, _capabilities) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 53 def create_model_info(model_data, slug, _capabilities) model_id = model_data['modelId'] Model::Info.new( id: model_id_with_region(model_id, model_data), name: model_data['modelName'] || model_id, provider: slug, family: 'claude', created_at: nil, context_window: 200_000, max_output_tokens: 4096, modalities: { input: ['text'], output: ['text'] }, capabilities: [], pricing: {}, metadata: {} ) end |
.inference_profile_region_prefix ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 87 def inference_profile_region_prefix # Extract region prefix from bedrock_region (e.g., "eu-west-3" -> "eu") region = @config.bedrock_region.to_s return 'us' if region.empty? # Default fallback # Take first two characters as the region prefix region[0, 2] end |
.model_id_with_region(model_id, model_data) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 71 def model_id_with_region(model_id, model_data) return model_id unless model_data['inferenceTypesSupported']&.include?('INFERENCE_PROFILE') return model_id if model_data['inferenceTypesSupported']&.include?('ON_DEMAND') desired_region_prefix = inference_profile_region_prefix # Return unchanged if model already has the correct region prefix return model_id if model_id.start_with?("#{desired_region_prefix}.") # Remove any existing region prefix (e.g., "us.", "eu.", "ap.") clean_model_id = model_id.sub(/^[a-z]{2}\./, '') # Apply the desired region prefix "#{desired_region_prefix}.#{clean_model_id}" end |
.models_url ⇒ Object
21 22 23 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 21 def models_url 'foundation-models' end |
.parse_list_models_response(response, slug, capabilities) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 25 def parse_list_models_response(response, slug, capabilities) models = Array(response.body['modelSummaries']) models.select { |m| m['modelId'].include?('claude') }.map do |model_data| model_id = model_data['modelId'] Model::Info.new( id: model_id_with_region(model_id, model_data), name: model_data['modelName'] || capabilities.format_display_name(model_id), provider: slug, family: capabilities.model_family(model_id), created_at: nil, context_window: capabilities.context_window_for(model_id), max_output_tokens: capabilities.max_tokens_for(model_id), modalities: capabilities.modalities_for(model_id), capabilities: capabilities.capabilities_for(model_id), pricing: capabilities.pricing_for(model_id), metadata: { provider_name: model_data['providerName'], inference_types: model_data['inferenceTypesSupported'] || [], streaming_supported: model_data['responseStreamingSupported'] || false, input_modalities: model_data['inputModalities'] || [], output_modalities: model_data['outputModalities'] || [] } ) end end |
Instance Method Details
#list_models ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 8 def list_models mgmt_api_base = "https://bedrock.#{@config.bedrock_region}.amazonaws.com" full_models_url = "#{mgmt_api_base}/#{models_url}" signature = sign_request(full_models_url, method: :get) response = @connection.get(full_models_url) do |req| req.headers.merge! signature.headers end parse_list_models_response(response, slug, capabilities) end |