Skip to content

Commit 1a6b5c3

Browse files
authored
add new supported regions (#2725)
1 parent 9281195 commit 1a6b5c3

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/generator.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,17 @@ class AmazonBedrockGenerator:
6363
supports Amazon Bedrock.
6464
"""
6565

66+
# Regex pattern for supported AWS Bedrock region prefixes
67+
_REGION_PREFIX_PATTERN = r"((?:global|us-gov|us|eu|apac|au|ca|jp)\.)?"
68+
6669
SUPPORTED_MODEL_PATTERNS: ClassVar[dict[str, type[BedrockModelAdapter]]] = {
67-
r"([a-z]{2}\.)?amazon.titan-text.*": AmazonTitanAdapter,
68-
r"([a-z]{2}\.)?ai21.j2.*": AI21LabsJurassic2Adapter,
69-
r"([a-z]{2}\.)?cohere.command-[^r].*": CohereCommandAdapter,
70-
r"([a-z]{2}\.)?cohere.command-r.*": CohereCommandRAdapter,
71-
r"([a-z]{2}\.)?anthropic.claude.*": AnthropicClaudeAdapter,
72-
r"([a-z]{2}\.)?meta.llama.*": MetaLlamaAdapter,
73-
r"([a-z]{2}\.)?mistral.*": MistralAdapter,
70+
rf"{_REGION_PREFIX_PATTERN}amazon.titan-text.*": AmazonTitanAdapter,
71+
rf"{_REGION_PREFIX_PATTERN}ai21.j2.*": AI21LabsJurassic2Adapter,
72+
rf"{_REGION_PREFIX_PATTERN}cohere.command-[^r].*": CohereCommandAdapter,
73+
rf"{_REGION_PREFIX_PATTERN}cohere.command-r.*": CohereCommandRAdapter,
74+
rf"{_REGION_PREFIX_PATTERN}anthropic.claude.*": AnthropicClaudeAdapter,
75+
rf"{_REGION_PREFIX_PATTERN}meta.llama.*": MetaLlamaAdapter,
76+
rf"{_REGION_PREFIX_PATTERN}mistral.*": MistralAdapter,
7477
}
7578

7679
SUPPORTED_MODEL_FAMILIES: ClassVar[dict[str, type[BedrockModelAdapter]]] = {

integrations/amazon_bedrock/tests/test_generator.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,11 @@ def test_constructor_with_empty_model():
129129
("anthropic.claude-v2", AnthropicClaudeAdapter),
130130
("eu.anthropic.claude-v1", AnthropicClaudeAdapter), # cross-region inference
131131
("us.anthropic.claude-v2", AnthropicClaudeAdapter), # cross-region inference
132+
("global.anthropic.claude-v2", AnthropicClaudeAdapter),
133+
("us-gov.anthropic.claude-v1", AnthropicClaudeAdapter),
134+
("apac.anthropic.claude-v2", AnthropicClaudeAdapter),
135+
("au.anthropic.claude-v1", AnthropicClaudeAdapter),
136+
("jp.anthropic.claude-v1", AnthropicClaudeAdapter),
132137
("anthropic.claude-instant-v1", AnthropicClaudeAdapter),
133138
("anthropic.claude-super-v5", AnthropicClaudeAdapter), # artificial
134139
("cohere.command-text-v14", CohereCommandAdapter),
@@ -207,6 +212,20 @@ def test_get_model_adapter_auto_detect_family_fails():
207212
AmazonBedrockGenerator.get_model_adapter(model="arn:123435423")
208213

209214

215+
@pytest.mark.parametrize(
216+
"model",
217+
[
218+
"invalid.anthropic.claude-v2",
219+
"xyz.meta.llama2-13b-chat-v1",
220+
"fake-region.mistral.mistral-7b-instruct-v0:2",
221+
"global.us.anthropic.claude-v2",
222+
],
223+
)
224+
def test_get_model_adapter_with_invalid_region_prefix(model: str):
225+
with pytest.raises(AmazonBedrockConfigurationError):
226+
AmazonBedrockGenerator.get_model_adapter(model=model)
227+
228+
210229
def test_get_model_adapter_model_family_over_auto_detection():
211230
"""
212231
Test that the model_family is used over auto-detection

0 commit comments

Comments
 (0)