Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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]]] = {
Expand Down
19 changes: 19 additions & 0 deletions integrations/amazon_bedrock/tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down