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
- .model_id_with_region(model_id, model_data) ⇒ Object
- .models_url ⇒ Object
- .normalize_inference_profile_id(model_id, inference_types, region) ⇒ Object
- .parse_list_models_response(response, slug, capabilities) ⇒ Object
- .region_prefix(region) ⇒ Object
- .with_region_prefix(model_id, region) ⇒ 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 |
.model_id_with_region(model_id, model_data) ⇒ Object
71 72 73 74 75 76 77 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 71 def model_id_with_region(model_id, model_data) normalize_inference_profile_id( model_id, model_data['inferenceTypesSupported'], @config.bedrock_region ) end |
.models_url ⇒ Object
21 22 23 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 21 def models_url 'foundation-models' end |
.normalize_inference_profile_id(model_id, inference_types, region) ⇒ Object
94 95 96 97 98 99 100 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 94 def normalize_inference_profile_id(model_id, inference_types, region) types = Array(inference_types) return model_id unless types.include?('INFERENCE_PROFILE') return model_id if types.include?('ON_DEMAND') with_region_prefix(model_id, region) 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 |
.region_prefix(region) ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 79 def region_prefix(region) region = region.to_s return 'us' if region.empty? region[0, 2] end |
.with_region_prefix(model_id, region) ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/ruby_llm/providers/bedrock/models.rb', line 86 def with_region_prefix(model_id, region) desired_prefix = region_prefix(region) return model_id if model_id.start_with?("#{desired_prefix}.") clean_model_id = model_id.sub(/^[a-z]{2}\./, '') "#{desired_prefix}.#{clean_model_id}" 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 |