From 698e69621da245483edf28c1e4f86a3d5a33c9f7 Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 11 Aug 2025 12:59:32 +0200 Subject: [PATCH 1/5] Set region as prefix instead of hardcoding US --- lib/ruby_llm/providers/bedrock/models.rb | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/ruby_llm/providers/bedrock/models.rb b/lib/ruby_llm/providers/bedrock/models.rb index c985f8f4d..6d82d9703 100644 --- a/lib/ruby_llm/providers/bedrock/models.rb +++ b/lib/ruby_llm/providers/bedrock/models.rb @@ -74,7 +74,17 @@ 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') - "us.#{model_id}" + region_prefix = inference_profile_region_prefix + "#{region_prefix}.#{model_id}" + end + + 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 end end From 0fe40e42e68b8859de86bdb56188774399df0b64 Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 11 Aug 2025 12:59:48 +0200 Subject: [PATCH 2/5] Add backward compatible tests + new cases --- .../ruby_llm/providers/bedrock/models_spec.rb | 101 +++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/spec/ruby_llm/providers/bedrock/models_spec.rb b/spec/ruby_llm/providers/bedrock/models_spec.rb index 961b52e40..76c94ee08 100644 --- a/spec/ruby_llm/providers/bedrock/models_spec.rb +++ b/spec/ruby_llm/providers/bedrock/models_spec.rb @@ -3,6 +3,8 @@ require 'spec_helper' RSpec.describe RubyLLM::Providers::Bedrock::Models do + include_context 'with configured RubyLLM' + let(:slug) { 'bedrock' } let(:capabilities) { class_double(RubyLLM::Providers::Bedrock::Capabilities) } @@ -36,7 +38,8 @@ } end - it 'adds us. prefix to model ID' do + it 'adds region-appropriate prefix to model ID based on configured region' do + # Default US region model_info = described_class.create_model_info(model_data, slug, capabilities) expect(model_info.id).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') end @@ -101,4 +104,100 @@ end end end + + describe '#model_id_with_region' do + let(:inference_profile_model) do + { + 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + end + + let(:on_demand_model) do + { + 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', + 'inferenceTypesSupported' => ['ON_DEMAND'] + } + end + + context 'with different regions' do + { + 'us-east-1' => 'us', + 'eu-west-3' => 'eu', + 'ap-south-1' => 'ap', + 'ca-central-1' => 'ca' + }.each do |region, expected_prefix| + it "adds #{expected_prefix}. prefix for inference profile models in #{region}" do + allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) + + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + result = provider.send(:model_id_with_region, + inference_profile_model['modelId'], + inference_profile_model) + + expect(result).to eq("#{expected_prefix}.anthropic.claude-3-7-sonnet-20250219-v1:0") + end + end + end + + it 'does not add prefix for on-demand models' do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') + + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + result = provider.send(:model_id_with_region, + on_demand_model['modelId'], + on_demand_model) + + expect(result).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') + end + + it 'defaults to us. prefix for empty region' do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('') + + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + result = provider.send(:model_id_with_region, + inference_profile_model['modelId'], + inference_profile_model) + + expect(result).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') + end + end + + describe '#inference_profile_region_prefix' do + it 'extracts region prefix from bedrock_region' do + regions_and_prefixes = { + 'us-east-1' => 'us', + 'eu-west-3' => 'eu', + 'ap-south-1' => 'ap', + 'ca-central-1' => 'ca', + 'sa-east-1' => 'sa' + } + + regions_and_prefixes.each do |region, expected_prefix| + allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) + + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + result = provider.send(:inference_profile_region_prefix) + expect(result).to eq(expected_prefix) + end + end + + it 'defaults to us for empty region' do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('') + + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + result = provider.send(:inference_profile_region_prefix) + expect(result).to eq('us') + end + end end From 23f2579ee3f43822bab444302317b94922e0e36f Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 11 Aug 2025 13:38:56 +0200 Subject: [PATCH 3/5] Refactor tests --- .../ruby_llm/providers/bedrock/models_spec.rb | 112 ------------------ 1 file changed, 112 deletions(-) diff --git a/spec/ruby_llm/providers/bedrock/models_spec.rb b/spec/ruby_llm/providers/bedrock/models_spec.rb index 76c94ee08..b7168c7a8 100644 --- a/spec/ruby_llm/providers/bedrock/models_spec.rb +++ b/spec/ruby_llm/providers/bedrock/models_spec.rb @@ -23,87 +23,6 @@ ) end - describe '.create_model_info' do - context 'when model supports INFERENCE_PROFILE only' do - let(:model_data) do - { - 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', - 'modelName' => 'Claude 3.7 Sonnet', - 'providerName' => 'Anthropic', - 'inferenceTypesSupported' => ['INFERENCE_PROFILE'], - 'inputModalities' => %w[TEXT IMAGE], - 'outputModalities' => ['TEXT'], - 'responseStreamingSupported' => true, - 'customizationsSupported' => [] - } - end - - it 'adds region-appropriate prefix to model ID based on configured region' do - # Default US region - model_info = described_class.create_model_info(model_data, slug, capabilities) - expect(model_info.id).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') - end - end - - context 'when model supports ON_DEMAND' do - let(:model_data) do - { - 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', - 'modelName' => 'Claude 3.5 Sonnet', - 'providerName' => 'Anthropic', - 'inferenceTypesSupported' => ['ON_DEMAND'], - 'inputModalities' => %w[TEXT IMAGE], - 'outputModalities' => ['TEXT'], - 'responseStreamingSupported' => true, - 'customizationsSupported' => [] - } - end - - it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) - expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') - end - end - - context 'when model supports both INFERENCE_PROFILE and ON_DEMAND' do - let(:model_data) do - { - 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', - 'modelName' => 'Claude 3.5 Sonnet', - 'providerName' => 'Anthropic', - 'inferenceTypesSupported' => %w[ON_DEMAND INFERENCE_PROFILE], - 'inputModalities' => %w[TEXT IMAGE], - 'outputModalities' => ['TEXT'], - 'responseStreamingSupported' => true, - 'customizationsSupported' => [] - } - end - - it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) - expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') - end - end - - context 'when inferenceTypesSupported is nil' do - let(:model_data) do - { - 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', - 'modelName' => 'Claude 3.5 Sonnet', - 'providerName' => 'Anthropic', - 'inputModalities' => %w[TEXT IMAGE], - 'outputModalities' => ['TEXT'], - 'responseStreamingSupported' => true, - 'customizationsSupported' => [] - } - end - - it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) - expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') - end - end - end describe '#model_id_with_region' do let(:inference_profile_model) do @@ -169,35 +88,4 @@ end end - describe '#inference_profile_region_prefix' do - it 'extracts region prefix from bedrock_region' do - regions_and_prefixes = { - 'us-east-1' => 'us', - 'eu-west-3' => 'eu', - 'ap-south-1' => 'ap', - 'ca-central-1' => 'ca', - 'sa-east-1' => 'sa' - } - - regions_and_prefixes.each do |region, expected_prefix| - allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) - - provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) - provider.extend(described_class) - - result = provider.send(:inference_profile_region_prefix) - expect(result).to eq(expected_prefix) - end - end - - it 'defaults to us for empty region' do - allow(RubyLLM.config).to receive(:bedrock_region).and_return('') - - provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) - provider.extend(described_class) - - result = provider.send(:inference_profile_region_prefix) - expect(result).to eq('us') - end - end end From 5d115b79214698694c76aa64c4849b41418bcc97 Mon Sep 17 00:00:00 2001 From: Enrique Date: Mon, 11 Aug 2025 13:42:53 +0200 Subject: [PATCH 4/5] Add spec --- .../ruby_llm/providers/bedrock/models_spec.rb | 223 +++++++++++++----- 1 file changed, 170 insertions(+), 53 deletions(-) diff --git a/spec/ruby_llm/providers/bedrock/models_spec.rb b/spec/ruby_llm/providers/bedrock/models_spec.rb index b7168c7a8..0225bef37 100644 --- a/spec/ruby_llm/providers/bedrock/models_spec.rb +++ b/spec/ruby_llm/providers/bedrock/models_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe RubyLLM::Providers::Bedrock::Models do - include_context 'with configured RubyLLM' - let(:slug) { 'bedrock' } let(:capabilities) { class_double(RubyLLM::Providers::Bedrock::Capabilities) } @@ -23,69 +21,188 @@ ) end + describe '.create_model_info' do + context 'when model supports INFERENCE_PROFILE only' do + let(:model_data) do + { + 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', + 'modelName' => 'Claude 3.7 Sonnet', + 'providerName' => 'Anthropic', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'], + 'inputModalities' => %w[TEXT IMAGE], + 'outputModalities' => ['TEXT'], + 'responseStreamingSupported' => true, + 'customizationsSupported' => [] + } + end - describe '#model_id_with_region' do - let(:inference_profile_model) do - { - 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', - 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] - } + it 'adds us. prefix to model ID' do + model_info = described_class.create_model_info(model_data, slug, capabilities) + expect(model_info.id).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') + end end - let(:on_demand_model) do - { - 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', - 'inferenceTypesSupported' => ['ON_DEMAND'] - } + context 'when model supports ON_DEMAND' do + let(:model_data) do + { + 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', + 'modelName' => 'Claude 3.5 Sonnet', + 'providerName' => 'Anthropic', + 'inferenceTypesSupported' => ['ON_DEMAND'], + 'inputModalities' => %w[TEXT IMAGE], + 'outputModalities' => ['TEXT'], + 'responseStreamingSupported' => true, + 'customizationsSupported' => [] + } + end + + it 'does not add us. prefix to model ID' do + model_info = described_class.create_model_info(model_data, slug, capabilities) + expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') + end end - context 'with different regions' do - { - 'us-east-1' => 'us', - 'eu-west-3' => 'eu', - 'ap-south-1' => 'ap', - 'ca-central-1' => 'ca' - }.each do |region, expected_prefix| - it "adds #{expected_prefix}. prefix for inference profile models in #{region}" do - allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) - - provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) - provider.extend(described_class) - - result = provider.send(:model_id_with_region, - inference_profile_model['modelId'], - inference_profile_model) - - expect(result).to eq("#{expected_prefix}.anthropic.claude-3-7-sonnet-20250219-v1:0") - end + context 'when model supports both INFERENCE_PROFILE and ON_DEMAND' do + let(:model_data) do + { + 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', + 'modelName' => 'Claude 3.5 Sonnet', + 'providerName' => 'Anthropic', + 'inferenceTypesSupported' => %w[ON_DEMAND INFERENCE_PROFILE], + 'inputModalities' => %w[TEXT IMAGE], + 'outputModalities' => ['TEXT'], + 'responseStreamingSupported' => true, + 'customizationsSupported' => [] + } + end + + it 'does not add us. prefix to model ID' do + model_info = described_class.create_model_info(model_data, slug, capabilities) + expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') end end - it 'does not add prefix for on-demand models' do - allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') - - provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) - provider.extend(described_class) - - result = provider.send(:model_id_with_region, - on_demand_model['modelId'], - on_demand_model) - - expect(result).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') + context 'when inferenceTypesSupported is nil' do + let(:model_data) do + { + 'modelId' => 'anthropic.claude-3-5-sonnet-20240620-v1:0', + 'modelName' => 'Claude 3.5 Sonnet', + 'providerName' => 'Anthropic', + 'inputModalities' => %w[TEXT IMAGE], + 'outputModalities' => ['TEXT'], + 'responseStreamingSupported' => true, + 'customizationsSupported' => [] + } + end + + it 'does not add us. prefix to model ID' do + model_info = described_class.create_model_info(model_data, slug, capabilities) + expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') + end end + end - it 'defaults to us. prefix for empty region' do - allow(RubyLLM.config).to receive(:bedrock_region).and_return('') - + # New specs for region-aware inference profile handling + describe '#model_id_with_region with region awareness' do + let(:provider_instance) do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('eu-west-3') provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) provider.extend(described_class) - - result = provider.send(:model_id_with_region, - inference_profile_model['modelId'], - inference_profile_model) - - expect(result).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') + provider end - end + context 'with EU region configured' do + let(:inference_profile_model) do + { + 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + end + + let(:us_prefixed_model) do + { + 'modelId' => 'us.anthropic.claude-opus-4-1-20250805-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + end + + it 'adds eu. prefix for inference profile models' do + result = provider_instance.send(:model_id_with_region, + inference_profile_model['modelId'], + inference_profile_model) + expect(result).to eq('eu.anthropic.claude-3-7-sonnet-20250219-v1:0') + end + + it 'replaces us. prefix with eu. prefix' do + result = provider_instance.send(:model_id_with_region, + us_prefixed_model['modelId'], + us_prefixed_model) + expect(result).to eq('eu.anthropic.claude-opus-4-1-20250805-v1:0') + end + end + + context 'with AP region configured' do + let(:provider_instance) do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('ap-south-1') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + provider + end + + it 'replaces existing region prefix with ap. prefix' do + model_data = { + 'modelId' => 'us.anthropic.claude-opus-4-1-20250805-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + + result = provider_instance.send(:model_id_with_region, + model_data['modelId'], + model_data) + expect(result).to eq('ap.anthropic.claude-opus-4-1-20250805-v1:0') + end + end + + context 'region prefix edge cases' do + it 'handles empty region gracefully' do + allow(RubyLLM.config).to receive(:bedrock_region).and_return('') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_data = { + 'modelId' => 'anthropic.claude-opus-4-1-20250805-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + + result = provider.send(:model_id_with_region, + model_data['modelId'], + model_data) + expect(result).to eq('us.anthropic.claude-opus-4-1-20250805-v1:0') + end + + it 'extracts region prefix from various AWS regions' do + regions_and_expected_prefixes = { + 'eu-west-3' => 'eu', + 'ap-south-1' => 'ap', + 'ca-central-1' => 'ca', + 'sa-east-1' => 'sa' + } + + regions_and_expected_prefixes.each do |region, expected_prefix| + allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_data = { + 'modelId' => 'anthropic.claude-opus-4-1-20250805-v1:0', + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] + } + + result = provider.send(:model_id_with_region, + model_data['modelId'], + model_data) + expect(result).to eq("#{expected_prefix}.anthropic.claude-opus-4-1-20250805-v1:0") + end + end + end + end end From 0684e4186f54fae89c49e65e3f3cc021ead389d9 Mon Sep 17 00:00:00 2001 From: Enrique Date: Tue, 2 Sep 2025 20:05:23 +0200 Subject: [PATCH 5/5] Fix --- lib/ruby_llm/providers/bedrock/models.rb | 14 +++- .../ruby_llm/providers/bedrock/models_spec.rb | 66 ++++++++++++------- 2 files changed, 54 insertions(+), 26 deletions(-) diff --git a/lib/ruby_llm/providers/bedrock/models.rb b/lib/ruby_llm/providers/bedrock/models.rb index 09adb51fe..645842ad7 100644 --- a/lib/ruby_llm/providers/bedrock/models.rb +++ b/lib/ruby_llm/providers/bedrock/models.rb @@ -72,15 +72,23 @@ 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') - region_prefix = inference_profile_region_prefix - "#{region_prefix}.#{model_id}" + 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 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 diff --git a/spec/ruby_llm/providers/bedrock/models_spec.rb b/spec/ruby_llm/providers/bedrock/models_spec.rb index 0225bef37..ffc7478f9 100644 --- a/spec/ruby_llm/providers/bedrock/models_spec.rb +++ b/spec/ruby_llm/providers/bedrock/models_spec.rb @@ -37,7 +37,12 @@ end it 'adds us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) + # Mock a provider instance to test the region functionality + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_info = provider.send(:create_model_info, model_data, slug, capabilities) expect(model_info.id).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0') end end @@ -57,7 +62,12 @@ end it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) + # Mock a provider instance to test the region functionality + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_info = provider.send(:create_model_info, model_data, slug, capabilities) expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') end end @@ -77,7 +87,12 @@ end it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) + # Mock a provider instance to test the region functionality + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_info = provider.send(:create_model_info, model_data, slug, capabilities) expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') end end @@ -96,7 +111,12 @@ end it 'does not add us. prefix to model ID' do - model_info = described_class.create_model_info(model_data, slug, capabilities) + # Mock a provider instance to test the region functionality + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) + provider.extend(described_class) + + model_info = provider.send(:create_model_info, model_data, slug, capabilities) expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0') end end @@ -127,16 +147,16 @@ end it 'adds eu. prefix for inference profile models' do - result = provider_instance.send(:model_id_with_region, - inference_profile_model['modelId'], - inference_profile_model) + result = provider_instance.send(:model_id_with_region, + inference_profile_model['modelId'], + inference_profile_model) expect(result).to eq('eu.anthropic.claude-3-7-sonnet-20250219-v1:0') end - it 'replaces us. prefix with eu. prefix' do - result = provider_instance.send(:model_id_with_region, - us_prefixed_model['modelId'], - us_prefixed_model) + it 'adds eu. prefix to us. prefixed model' do + result = provider_instance.send(:model_id_with_region, + us_prefixed_model['modelId'], + us_prefixed_model) expect(result).to eq('eu.anthropic.claude-opus-4-1-20250805-v1:0') end end @@ -149,20 +169,20 @@ provider end - it 'replaces existing region prefix with ap. prefix' do + it 'adds ap. prefix to existing us. prefixed model' do model_data = { 'modelId' => 'us.anthropic.claude-opus-4-1-20250805-v1:0', 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] } - result = provider_instance.send(:model_id_with_region, - model_data['modelId'], - model_data) + result = provider_instance.send(:model_id_with_region, + model_data['modelId'], + model_data) expect(result).to eq('ap.anthropic.claude-opus-4-1-20250805-v1:0') end end - context 'region prefix edge cases' do + context 'with region prefix edge cases' do it 'handles empty region gracefully' do allow(RubyLLM.config).to receive(:bedrock_region).and_return('') provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) @@ -173,16 +193,16 @@ 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] } - result = provider.send(:model_id_with_region, - model_data['modelId'], - model_data) + result = provider.send(:model_id_with_region, + model_data['modelId'], + model_data) expect(result).to eq('us.anthropic.claude-opus-4-1-20250805-v1:0') end it 'extracts region prefix from various AWS regions' do regions_and_expected_prefixes = { 'eu-west-3' => 'eu', - 'ap-south-1' => 'ap', + 'ap-south-1' => 'ap', 'ca-central-1' => 'ca', 'sa-east-1' => 'sa' } @@ -197,9 +217,9 @@ 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] } - result = provider.send(:model_id_with_region, - model_data['modelId'], - model_data) + result = provider.send(:model_id_with_region, + model_data['modelId'], + model_data) expect(result).to eq("#{expected_prefix}.anthropic.claude-opus-4-1-20250805-v1:0") end end