From 9504485913b606fc7c39e60c8d596247f612646d Mon Sep 17 00:00:00 2001 From: SaraCalla Date: Tue, 13 Jan 2026 09:41:27 +0100 Subject: [PATCH] add new supported regions --- .../generators/amazon_bedrock/generator.py | 17 ++++++++++------- .../amazon_bedrock/tests/test_generator.py | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/generator.py b/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/generator.py index 4261142199..384ab07759 100644 --- a/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/generator.py +++ b/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/generator.py @@ -63,14 +63,17 @@ class AmazonBedrockGenerator: supports Amazon Bedrock. """ + # Regex pattern for supported AWS Bedrock region prefixes + _REGION_PREFIX_PATTERN = r"((?:global|us-gov|us|eu|apac|au|ca|jp)\.)?" + SUPPORTED_MODEL_PATTERNS: ClassVar[dict[str, type[BedrockModelAdapter]]] = { - r"([a-z]{2}\.)?amazon.titan-text.*": AmazonTitanAdapter, - r"([a-z]{2}\.)?ai21.j2.*": AI21LabsJurassic2Adapter, - r"([a-z]{2}\.)?cohere.command-[^r].*": CohereCommandAdapter, - r"([a-z]{2}\.)?cohere.command-r.*": CohereCommandRAdapter, - r"([a-z]{2}\.)?anthropic.claude.*": AnthropicClaudeAdapter, - r"([a-z]{2}\.)?meta.llama.*": MetaLlamaAdapter, - r"([a-z]{2}\.)?mistral.*": MistralAdapter, + rf"{_REGION_PREFIX_PATTERN}amazon.titan-text.*": AmazonTitanAdapter, + rf"{_REGION_PREFIX_PATTERN}ai21.j2.*": AI21LabsJurassic2Adapter, + rf"{_REGION_PREFIX_PATTERN}cohere.command-[^r].*": CohereCommandAdapter, + rf"{_REGION_PREFIX_PATTERN}cohere.command-r.*": CohereCommandRAdapter, + rf"{_REGION_PREFIX_PATTERN}anthropic.claude.*": AnthropicClaudeAdapter, + rf"{_REGION_PREFIX_PATTERN}meta.llama.*": MetaLlamaAdapter, + rf"{_REGION_PREFIX_PATTERN}mistral.*": MistralAdapter, } SUPPORTED_MODEL_FAMILIES: ClassVar[dict[str, type[BedrockModelAdapter]]] = { diff --git a/integrations/amazon_bedrock/tests/test_generator.py b/integrations/amazon_bedrock/tests/test_generator.py index b3514db91a..9452b0948f 100644 --- a/integrations/amazon_bedrock/tests/test_generator.py +++ b/integrations/amazon_bedrock/tests/test_generator.py @@ -129,6 +129,11 @@ def test_constructor_with_empty_model(): ("anthropic.claude-v2", AnthropicClaudeAdapter), ("eu.anthropic.claude-v1", AnthropicClaudeAdapter), # cross-region inference ("us.anthropic.claude-v2", AnthropicClaudeAdapter), # cross-region inference + ("global.anthropic.claude-v2", AnthropicClaudeAdapter), + ("us-gov.anthropic.claude-v1", AnthropicClaudeAdapter), + ("apac.anthropic.claude-v2", AnthropicClaudeAdapter), + ("au.anthropic.claude-v1", AnthropicClaudeAdapter), + ("jp.anthropic.claude-v1", AnthropicClaudeAdapter), ("anthropic.claude-instant-v1", AnthropicClaudeAdapter), ("anthropic.claude-super-v5", AnthropicClaudeAdapter), # artificial ("cohere.command-text-v14", CohereCommandAdapter), @@ -207,6 +212,20 @@ def test_get_model_adapter_auto_detect_family_fails(): AmazonBedrockGenerator.get_model_adapter(model="arn:123435423") +@pytest.mark.parametrize( + "model", + [ + "invalid.anthropic.claude-v2", + "xyz.meta.llama2-13b-chat-v1", + "fake-region.mistral.mistral-7b-instruct-v0:2", + "global.us.anthropic.claude-v2", + ], +) +def test_get_model_adapter_with_invalid_region_prefix(model: str): + with pytest.raises(AmazonBedrockConfigurationError): + AmazonBedrockGenerator.get_model_adapter(model=model) + + def test_get_model_adapter_model_family_over_auto_detection(): """ Test that the model_family is used over auto-detection