Skip to content

Commit d3d79f1

Browse files
authored
test: Bedrock - use Sonnet 4.6 due to 3.5 EOL (#3071)
1 parent ea94dd1 commit d3d79f1

3 files changed

Lines changed: 51 additions & 51 deletions

File tree

integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ class AmazonBedrockChatGenerator:
3939
"""
4040
Completes chats using LLMs hosted on Amazon Bedrock available via the Bedrock Converse API.
4141
42-
For example, to use the Anthropic Claude 3 Sonnet model, initialize this component with the
43-
'anthropic.claude-3-5-sonnet-20240620-v1:0' model name.
42+
For example, to use the Anthropic Claude 4.6 Sonnet model, initialize this component with the
43+
'global.anthropic.claude-sonnet-4-6' model name.
4444
4545
**Usage example**
4646
@@ -53,7 +53,7 @@ class AmazonBedrockChatGenerator:
5353
ChatMessage.from_user("What's Natural Language Processing?")]
5454
5555
56-
client = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0",
56+
client = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6",
5757
streaming_callback=print_streaming_chunk)
5858
client.run(messages, generation_kwargs={"max_tokens": 512})
5959
```
@@ -64,7 +64,7 @@ class AmazonBedrockChatGenerator:
6464
from haystack.dataclasses import ChatMessage, ImageContent
6565
from haystack_integrations.components.generators.amazon_bedrock import AmazonBedrockChatGenerator
6666
67-
generator = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
67+
generator = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6")
6868
6969
image_content = ImageContent.from_file_path(file_path="apple.jpg")
7070
@@ -107,7 +107,7 @@ def weather(city: str):
107107
108108
# Initialize generator with tool
109109
client = AmazonBedrockChatGenerator(
110-
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
110+
model="global.anthropic.claude-sonnet-4-6",
111111
tools=[weather_tool]
112112
)
113113

integrations/amazon_bedrock/tests/test_chat_generator.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def test_from_dict(self, mock_boto3_session: Any, boto3_config: dict[str, Any] |
211211
"aws_session_token": {"type": "env_var", "env_vars": ["AWS_SESSION_TOKEN"], "strict": False},
212212
"aws_region_name": {"type": "env_var", "env_vars": ["AWS_DEFAULT_REGION"], "strict": False},
213213
"aws_profile_name": {"type": "env_var", "env_vars": ["AWS_PROFILE"], "strict": False},
214-
"model": "anthropic.claude-3-5-sonnet-20240620-v1:0",
214+
"model": "global.anthropic.claude-sonnet-4-6",
215215
"generation_kwargs": {"temperature": 0.7},
216216
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
217217
"boto3_config": boto3_config,
@@ -221,16 +221,16 @@ def test_from_dict(self, mock_boto3_session: Any, boto3_config: dict[str, Any] |
221221
},
222222
}
223223
)
224-
assert generator.model == "anthropic.claude-3-5-sonnet-20240620-v1:0"
224+
assert generator.model == "global.anthropic.claude-sonnet-4-6"
225225
assert generator.streaming_callback == print_streaming_chunk
226226
assert generator.boto3_config == boto3_config
227227

228228
def test_default_constructor(self, mock_boto3_session, mock_aioboto3_session, set_env_variables):
229229
"""
230230
Test that the default constructor sets the correct values
231231
"""
232-
layer = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
233-
assert layer.model == "anthropic.claude-3-5-sonnet-20240620-v1:0"
232+
layer = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6")
233+
assert layer.model == "global.anthropic.claude-sonnet-4-6"
234234

235235
# assert mocked boto3 client called exactly once
236236
mock_boto3_session.assert_called_once()
@@ -250,7 +250,7 @@ def test_constructor_with_generation_kwargs(self, mock_boto3_session):
250250
"""
251251
generation_kwargs = {"temperature": 0.7}
252252
layer = AmazonBedrockChatGenerator(
253-
model="anthropic.claude-3-5-sonnet-20240620-v1:0", generation_kwargs=generation_kwargs
253+
model="global.anthropic.claude-sonnet-4-6", generation_kwargs=generation_kwargs
254254
)
255255
assert layer.generation_kwargs == generation_kwargs
256256

@@ -276,7 +276,7 @@ def test_serde_in_pipeline(self, mock_boto3_session, monkeypatch):
276276
)
277277

278278
generator = AmazonBedrockChatGenerator(
279-
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
279+
model="global.anthropic.claude-sonnet-4-6",
280280
generation_kwargs={"temperature": 0.7, "stopSequences": ["eviscerate"]},
281281
streaming_callback=print_streaming_chunk,
282282
tools=[tool],
@@ -303,7 +303,7 @@ def test_serde_in_pipeline(self, mock_boto3_session, monkeypatch):
303303
"aws_session_token": {"type": "env_var", "env_vars": ["AWS_SESSION_TOKEN"], "strict": False},
304304
"aws_region_name": {"type": "env_var", "env_vars": ["AWS_DEFAULT_REGION"], "strict": False},
305305
"aws_profile_name": {"type": "env_var", "env_vars": ["AWS_PROFILE"], "strict": False},
306-
"model": "anthropic.claude-3-5-sonnet-20240620-v1:0",
306+
"model": "global.anthropic.claude-sonnet-4-6",
307307
"generation_kwargs": {"temperature": 0.7, "stopSequences": ["eviscerate"]},
308308
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
309309
"boto3_config": None,
@@ -335,7 +335,7 @@ def test_serde_in_pipeline(self, mock_boto3_session, monkeypatch):
335335
assert pipeline_dict == expected_dict
336336

337337
def test_prepare_request_params_tool_config(self, top_song_tool_config, mock_boto3_session, set_env_variables):
338-
generator = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
338+
generator = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6")
339339
request_params, _ = generator._prepare_request_params(
340340
messages=[ChatMessage.from_user("What's the capital of France?")],
341341
generation_kwargs={"toolConfig": top_song_tool_config},
@@ -346,7 +346,7 @@ def test_prepare_request_params_tool_config(self, top_song_tool_config, mock_bot
346346

347347
def test_prepare_request_params_guardrail_config(self, mock_boto3_session, set_env_variables):
348348
generator = AmazonBedrockChatGenerator(
349-
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
349+
model="global.anthropic.claude-sonnet-4-6",
350350
guardrail_config={"guardrailIdentifier": "test", "guardrailVersion": "test"},
351351
)
352352
request_params, _ = generator._prepare_request_params(
@@ -374,7 +374,7 @@ def tool_fn(city: str) -> str:
374374
toolset = Toolset([population_tool])
375375

376376
generator = AmazonBedrockChatGenerator(
377-
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
377+
model="global.anthropic.claude-sonnet-4-6",
378378
tools=[weather_tool, toolset],
379379
)
380380

@@ -398,7 +398,7 @@ def tool_fn(city: str) -> str:
398398
)
399399
toolset = Toolset([population_tool])
400400

401-
generator = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
401+
generator = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6")
402402
request_params, _ = generator._prepare_request_params(
403403
messages=[ChatMessage.from_user("What's the capital of France?")],
404404
tools=[weather_tool, toolset],
@@ -487,7 +487,7 @@ def tool_fn(city: str) -> str:
487487
def test_prepare_request_params_with_flattened_generation_kwargs(
488488
self, mock_boto3_session, set_env_variables, generation_kwargs, additional_model_request_fields
489489
):
490-
generator = AmazonBedrockChatGenerator(model="anthropic.claude-3-5-sonnet-20240620-v1:0")
490+
generator = AmazonBedrockChatGenerator(model="global.anthropic.claude-sonnet-4-6")
491491
request_params, _ = generator._prepare_request_params(
492492
messages=[ChatMessage.from_user("What's the capital of France?")],
493493
generation_kwargs=generation_kwargs,
@@ -969,7 +969,7 @@ def test_live_run_with_tool_with_no_args_streaming(self, tool_with_no_parameters
969969
def test_live_run_with_guardrail(self, streaming_callback):
970970
messages = [ChatMessage.from_user("Should I invest in Tesla or Apple?")]
971971
component = AmazonBedrockChatGenerator(
972-
model="anthropic.claude-3-5-sonnet-20240620-v1:0",
972+
model="global.anthropic.claude-sonnet-4-6",
973973
guardrail_config={
974974
"guardrailIdentifier": os.getenv("AWS_BEDROCK_GUARDRAIL_ID"),
975975
"guardrailVersion": os.getenv("AWS_BEDROCK_GUARDRAIL_VERSION"),

0 commit comments

Comments
 (0)