|
37 | 37 | end
|
38 | 38 |
|
39 | 39 | it 'adds us. prefix to model ID' do
|
40 |
| - model_info = described_class.create_model_info(model_data, slug, capabilities) |
| 40 | + # Mock a provider instance to test the region functionality |
| 41 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') |
| 42 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 43 | + provider.extend(described_class) |
| 44 | + |
| 45 | + model_info = provider.send(:create_model_info, model_data, slug, capabilities) |
41 | 46 | expect(model_info.id).to eq('us.anthropic.claude-3-7-sonnet-20250219-v1:0')
|
42 | 47 | end
|
43 | 48 | end
|
|
57 | 62 | end
|
58 | 63 |
|
59 | 64 | it 'does not add us. prefix to model ID' do
|
60 |
| - model_info = described_class.create_model_info(model_data, slug, capabilities) |
| 65 | + # Mock a provider instance to test the region functionality |
| 66 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') |
| 67 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 68 | + provider.extend(described_class) |
| 69 | + |
| 70 | + model_info = provider.send(:create_model_info, model_data, slug, capabilities) |
61 | 71 | expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0')
|
62 | 72 | end
|
63 | 73 | end
|
|
77 | 87 | end
|
78 | 88 |
|
79 | 89 | it 'does not add us. prefix to model ID' do
|
80 |
| - model_info = described_class.create_model_info(model_data, slug, capabilities) |
| 90 | + # Mock a provider instance to test the region functionality |
| 91 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') |
| 92 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 93 | + provider.extend(described_class) |
| 94 | + |
| 95 | + model_info = provider.send(:create_model_info, model_data, slug, capabilities) |
81 | 96 | expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0')
|
82 | 97 | end
|
83 | 98 | end
|
|
96 | 111 | end
|
97 | 112 |
|
98 | 113 | it 'does not add us. prefix to model ID' do
|
99 |
| - model_info = described_class.create_model_info(model_data, slug, capabilities) |
| 114 | + # Mock a provider instance to test the region functionality |
| 115 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('us-east-1') |
| 116 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 117 | + provider.extend(described_class) |
| 118 | + |
| 119 | + model_info = provider.send(:create_model_info, model_data, slug, capabilities) |
100 | 120 | expect(model_info.id).to eq('anthropic.claude-3-5-sonnet-20240620-v1:0')
|
101 | 121 | end
|
102 | 122 | end
|
103 | 123 | end
|
| 124 | + |
| 125 | + # New specs for region-aware inference profile handling |
| 126 | + describe '#model_id_with_region with region awareness' do |
| 127 | + let(:provider_instance) do |
| 128 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('eu-west-3') |
| 129 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 130 | + provider.extend(described_class) |
| 131 | + provider |
| 132 | + end |
| 133 | + |
| 134 | + context 'with EU region configured' do |
| 135 | + let(:inference_profile_model) do |
| 136 | + { |
| 137 | + 'modelId' => 'anthropic.claude-3-7-sonnet-20250219-v1:0', |
| 138 | + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] |
| 139 | + } |
| 140 | + end |
| 141 | + |
| 142 | + let(:us_prefixed_model) do |
| 143 | + { |
| 144 | + 'modelId' => 'us.anthropic.claude-opus-4-1-20250805-v1:0', |
| 145 | + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] |
| 146 | + } |
| 147 | + end |
| 148 | + |
| 149 | + it 'adds eu. prefix for inference profile models' do |
| 150 | + result = provider_instance.send(:model_id_with_region, |
| 151 | + inference_profile_model['modelId'], |
| 152 | + inference_profile_model) |
| 153 | + expect(result).to eq('eu.anthropic.claude-3-7-sonnet-20250219-v1:0') |
| 154 | + end |
| 155 | + |
| 156 | + it 'adds eu. prefix to us. prefixed model' do |
| 157 | + result = provider_instance.send(:model_id_with_region, |
| 158 | + us_prefixed_model['modelId'], |
| 159 | + us_prefixed_model) |
| 160 | + expect(result).to eq('eu.anthropic.claude-opus-4-1-20250805-v1:0') |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + context 'with AP region configured' do |
| 165 | + let(:provider_instance) do |
| 166 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('ap-south-1') |
| 167 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 168 | + provider.extend(described_class) |
| 169 | + provider |
| 170 | + end |
| 171 | + |
| 172 | + it 'adds ap. prefix to existing us. prefixed model' do |
| 173 | + model_data = { |
| 174 | + 'modelId' => 'us.anthropic.claude-opus-4-1-20250805-v1:0', |
| 175 | + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] |
| 176 | + } |
| 177 | + |
| 178 | + result = provider_instance.send(:model_id_with_region, |
| 179 | + model_data['modelId'], |
| 180 | + model_data) |
| 181 | + expect(result).to eq('ap.anthropic.claude-opus-4-1-20250805-v1:0') |
| 182 | + end |
| 183 | + end |
| 184 | + |
| 185 | + context 'with region prefix edge cases' do |
| 186 | + it 'handles empty region gracefully' do |
| 187 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return('') |
| 188 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 189 | + provider.extend(described_class) |
| 190 | + |
| 191 | + model_data = { |
| 192 | + 'modelId' => 'anthropic.claude-opus-4-1-20250805-v1:0', |
| 193 | + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] |
| 194 | + } |
| 195 | + |
| 196 | + result = provider.send(:model_id_with_region, |
| 197 | + model_data['modelId'], |
| 198 | + model_data) |
| 199 | + expect(result).to eq('us.anthropic.claude-opus-4-1-20250805-v1:0') |
| 200 | + end |
| 201 | + |
| 202 | + it 'extracts region prefix from various AWS regions' do |
| 203 | + regions_and_expected_prefixes = { |
| 204 | + 'eu-west-3' => 'eu', |
| 205 | + 'ap-south-1' => 'ap', |
| 206 | + 'ca-central-1' => 'ca', |
| 207 | + 'sa-east-1' => 'sa' |
| 208 | + } |
| 209 | + |
| 210 | + regions_and_expected_prefixes.each do |region, expected_prefix| |
| 211 | + allow(RubyLLM.config).to receive(:bedrock_region).and_return(region) |
| 212 | + provider = RubyLLM::Providers::Bedrock.new(RubyLLM.config) |
| 213 | + provider.extend(described_class) |
| 214 | + |
| 215 | + model_data = { |
| 216 | + 'modelId' => 'anthropic.claude-opus-4-1-20250805-v1:0', |
| 217 | + 'inferenceTypesSupported' => ['INFERENCE_PROFILE'] |
| 218 | + } |
| 219 | + |
| 220 | + result = provider.send(:model_id_with_region, |
| 221 | + model_data['modelId'], |
| 222 | + model_data) |
| 223 | + expect(result).to eq("#{expected_prefix}.anthropic.claude-opus-4-1-20250805-v1:0") |
| 224 | + end |
| 225 | + end |
| 226 | + end |
| 227 | + end |
104 | 228 | end
|
0 commit comments