Skip to content

Commit

Permalink
Add Anthropic Claude 3.5 Sonnet v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ihor Lahutin committed Nov 6, 2024
1 parent 610a073 commit cb1675a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
8 changes: 8 additions & 0 deletions aidial_adapter_bedrock/deployments.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ class ChatCompletionDeployment(str, Enum):
ANTHROPIC_CLAUDE_V3_5_SONNET_EU = (
"eu.anthropic.claude-3-5-sonnet-20240620-v1:0"
)
ANTHROPIC_CLAUDE_V3_5_SONNET_V2 = (
"anthropic.claude-3-5-sonnet-20241022-v2:0"
)
ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US = (
"us.anthropic.claude-3-5-sonnet-20241022-v2:0"
)
ANTHROPIC_CLAUDE_V3_HAIKU = "anthropic.claude-3-haiku-20240307-v1:0"
ANTHROPIC_CLAUDE_V3_HAIKU_US = "us.anthropic.claude-3-haiku-20240307-v1:0"
ANTHROPIC_CLAUDE_V3_HAIKU_EU = "eu.anthropic.claude-3-haiku-20240307-v1:0"
Expand Down Expand Up @@ -75,6 +81,8 @@ def from_deployment_id(
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_EU,
Expand Down
2 changes: 2 additions & 0 deletions aidial_adapter_bedrock/llm/model/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ async def get_bedrock_adapter(
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_US
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_EU
Expand Down
5 changes: 5 additions & 0 deletions aidial_adapter_bedrock/llm/model/claude/v3/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ def _tokenize_tool_system_message(
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU
):
return 294 if tool_choice == "auto" else 261
case (
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US,
):
return 346 if tool_choice == "auto" else 313
case (
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_OPUS
| ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_OPUS_US
Expand Down
21 changes: 20 additions & 1 deletion tests/integration_tests/test_chat_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ def get_id(self):
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_SONNET_US: _WEST,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET: _WEST,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US: _WEST,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2: _WEST,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US: _WEST,
ChatCompletionDeployment.META_LLAMA2_13B_CHAT_V1: _WEST,
ChatCompletionDeployment.META_LLAMA2_70B_CHAT_V1: _WEST,
ChatCompletionDeployment.META_LLAMA3_8B_INSTRUCT_V1: _WEST,
Expand All @@ -118,6 +120,8 @@ def supports_tools(deployment: ChatCompletionDeployment) -> bool:
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_EU,
Expand All @@ -126,6 +130,13 @@ def supports_tools(deployment: ChatCompletionDeployment) -> bool:
]


def supports_parallel_tool_calls(deployment: ChatCompletionDeployment) -> bool:
return deployment not in [
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US,
] and supports_tools(deployment)


def is_llama3(deployment: ChatCompletionDeployment) -> bool:
return deployment in [
ChatCompletionDeployment.META_LLAMA3_8B_INSTRUCT_V1,
Expand All @@ -148,6 +159,8 @@ def is_claude3(deployment: ChatCompletionDeployment) -> bool:
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_US,
ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_EU,
Expand Down Expand Up @@ -379,9 +392,15 @@ def dial_recall_expected(r: ChatCompletionResult):
expected=lambda s: "7" in s.content.lower(),
)

city_config = (
[[("Glasgow", 15)], [("Glasgow", 15), ("London", 20)]]
if supports_parallel_tool_calls(deployment)
else [[("Glasgow", 15)]]
)

if supports_tools(deployment):

for cities in [[("Glasgow", 15)], [("Glasgow", 15), ("London", 20)]]:
for cities in city_config:
function = GET_WEATHER_FUNCTION
tool = function_to_tool(function)
fun_name = function["name"]
Expand Down
2 changes: 2 additions & 0 deletions tests/unit_tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_US, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_EU, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_5_SONNET_V2_US, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_US, True, True),
(ChatCompletionDeployment.ANTHROPIC_CLAUDE_V3_HAIKU_EU, True, True),
Expand Down

0 comments on commit cb1675a

Please sign in to comment.