Skip to content

Commit bec19c3

Browse files
committed
Update Anthropic default and test model to claude-3-7-sonnet-latest
1 parent 0f0cbe7 commit bec19c3

7 files changed

Lines changed: 43 additions & 43 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class AnthropicChatGenerator:
161161
from haystack_integrations.components.generators.anthropic import AnthropicChatGenerator
162162
from haystack.dataclasses import ChatMessage
163163
164-
generator = AnthropicChatGenerator(model="claude-3-5-sonnet-20240620",
164+
generator = AnthropicChatGenerator(model="claude-3-7-sonnet-latest",
165165
generation_kwargs={
166166
"max_tokens": 1000,
167167
"temperature": 0.7,
@@ -190,7 +190,7 @@ class AnthropicChatGenerator:
190190
def __init__(
191191
self,
192192
api_key: Secret = Secret.from_env_var("ANTHROPIC_API_KEY"), # noqa: B008
193-
model: str = "claude-3-5-sonnet-20240620",
193+
model: str = "claude-3-7-sonnet-latest",
194194
streaming_callback: Optional[StreamingCallbackT] = None,
195195
generation_kwargs: Optional[Dict[str, Any]] = None,
196196
ignore_tools_thinking_messages: bool = True,

integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/vertex_chat_generator.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class AnthropicVertexChatGenerator(AnthropicChatGenerator):
3939
4040
messages = [ChatMessage.from_user("What's Natural Language Processing?")]
4141
client = AnthropicVertexChatGenerator(
42-
model="claude-3-sonnet@20240229",
42+
model="claude-3-7-sonnet@20250219",
4343
project_id="your-project-id", region="your-region"
4444
)
4545
response = client.run(messages)
@@ -50,7 +50,7 @@ class AnthropicVertexChatGenerator(AnthropicChatGenerator):
5050
>> focuses on enabling computers to understand, interpret, and generate human language. It involves developing
5151
>> techniques and algorithms to analyze and process text or speech data, allowing machines to comprehend and
5252
>> communicate in natural languages like English, Spanish, or Chinese.")],
53-
>> _name=None, _meta={'model': 'claude-3-sonnet@20240229', 'index': 0, 'finish_reason': 'end_turn',
53+
>> _name=None, _meta={'model': 'claude-3-7-sonnet@20250219', 'index': 0, 'finish_reason': 'end_turn',
5454
>> 'usage': {'input_tokens': 15, 'output_tokens': 64}})]}
5555
```
5656
@@ -63,7 +63,7 @@ def __init__(
6363
self,
6464
region: str,
6565
project_id: str,
66-
model: str = "claude-3-5-sonnet@20240620",
66+
model: str = "claude-3-7-sonnet@20250219",
6767
streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
6868
generation_kwargs: Optional[Dict[str, Any]] = None,
6969
ignore_tools_thinking_messages: bool = True,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class AnthropicGenerator:
3535
```python
3636
from haystack_integrations.components.generators.anthropic import AnthropicGenerator
3737
38-
client = AnthropicGenerator(model="claude-3-sonnet-20240229")
38+
client = AnthropicGenerator(model="claude-3-7-sonnet-latest")
3939
response = client.run("What's Natural Language Processing? Be brief.")
4040
print(response)
4141
>>{'replies': ['Natural language processing (NLP) is a branch of artificial intelligence focused on enabling
@@ -60,7 +60,7 @@ class AnthropicGenerator:
6060
def __init__(
6161
self,
6262
api_key: Secret = Secret.from_env_var("ANTHROPIC_API_KEY"), # noqa: B008
63-
model: str = "claude-3-sonnet-20240229",
63+
model: str = "claude-3-7-sonnet-latest",
6464
streaming_callback: Optional[Callable[[StreamingChunk], None]] = None,
6565
system_prompt: Optional[str] = None,
6666
generation_kwargs: Optional[Dict[str, Any]] = None,

integrations/anthropic/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def mock_chat_completion():
1313
completion = Message(
1414
id="foo",
1515
content=[{"type": "text", "text": "Hello, world!"}],
16-
model="claude-3-sonnet-20240229",
16+
model="claude-3-7-sonnet-latest",
1717
role="assistant",
1818
type="message",
1919
usage={"input_tokens": 57, "output_tokens": 40},
@@ -35,7 +35,7 @@ def mock_chat_completion_extended_thinking():
3535
{"type": "thinking", "thinking": "This is a thinking part!", "signature": ""},
3636
{"type": "text", "text": "Hello, world!"},
3737
],
38-
model="claude-3-sonnet-20240229",
38+
model="claude-3-7-sonnet-latest",
3939
role="assistant",
4040
type="message",
4141
usage={"input_tokens": 57, "output_tokens": 40},

integrations/anthropic/tests/test_chat_generator.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def mock_anthropic_completion():
7070
completion = Message(
7171
id="foo",
7272
type="message",
73-
model="claude-3-5-sonnet-20240620",
73+
model="claude-3-7-sonnet-latest",
7474
role="assistant",
7575
content=[TextBlockParam(type="text", text="Hello! I'm Claude.")],
7676
stop_reason="end_turn",
@@ -88,7 +88,7 @@ def test_init_default(self, monkeypatch):
8888
monkeypatch.setenv("ANTHROPIC_API_KEY", "test-api-key")
8989
component = AnthropicChatGenerator()
9090
assert component.client.api_key == "test-api-key"
91-
assert component.model == "claude-3-5-sonnet-20240620"
91+
assert component.model == "claude-3-7-sonnet-latest"
9292
assert component.streaming_callback is None
9393
assert not component.generation_kwargs
9494
assert component.tools is None
@@ -121,13 +121,13 @@ def test_init_with_parameters(self, monkeypatch):
121121
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
122122
component = AnthropicChatGenerator(
123123
api_key=Secret.from_token("test-api-key"),
124-
model="claude-3-5-sonnet-20240620",
124+
model="claude-3-7-sonnet-latest",
125125
streaming_callback=print_streaming_chunk,
126126
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
127127
tools=[tool],
128128
)
129129
assert component.client.api_key == "test-api-key"
130-
assert component.model == "claude-3-5-sonnet-20240620"
130+
assert component.model == "claude-3-7-sonnet-latest"
131131
assert component.streaming_callback is print_streaming_chunk
132132
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
133133
assert component.tools == [tool]
@@ -139,13 +139,13 @@ def test_init_with_parameters_and_env_vars(self, monkeypatch):
139139
monkeypatch.setenv("OPENAI_TIMEOUT", "100")
140140
monkeypatch.setenv("OPENAI_MAX_RETRIES", "10")
141141
component = AnthropicChatGenerator(
142-
model="claude-3-5-sonnet-20240620",
142+
model="claude-3-7-sonnet-latest",
143143
api_key=Secret.from_token("test-api-key"),
144144
streaming_callback=print_streaming_chunk,
145145
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
146146
)
147147
assert component.client.api_key == "test-api-key"
148-
assert component.model == "claude-3-5-sonnet-20240620"
148+
assert component.model == "claude-3-7-sonnet-latest"
149149
assert component.streaming_callback is print_streaming_chunk
150150
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
151151

@@ -160,7 +160,7 @@ def test_to_dict_default(self, monkeypatch):
160160
"type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator",
161161
"init_parameters": {
162162
"api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "type": "env_var", "strict": True},
163-
"model": "claude-3-5-sonnet-20240620",
163+
"model": "claude-3-7-sonnet-latest",
164164
"streaming_callback": None,
165165
"ignore_tools_thinking_messages": True,
166166
"generation_kwargs": {},
@@ -179,7 +179,7 @@ def test_to_dict_with_parameters(self, monkeypatch):
179179
monkeypatch.setenv("ENV_VAR", "test-api-key")
180180
component = AnthropicChatGenerator(
181181
api_key=Secret.from_env_var("ENV_VAR"),
182-
model="claude-3-5-sonnet-20240620",
182+
model="claude-3-7-sonnet-latest",
183183
streaming_callback=print_streaming_chunk,
184184
generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"},
185185
tools=[tool],
@@ -192,7 +192,7 @@ def test_to_dict_with_parameters(self, monkeypatch):
192192
"type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator",
193193
"init_parameters": {
194194
"api_key": {"env_vars": ["ENV_VAR"], "type": "env_var", "strict": True},
195-
"model": "claude-3-5-sonnet-20240620",
195+
"model": "claude-3-7-sonnet-latest",
196196
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
197197
"ignore_tools_thinking_messages": True,
198198
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
@@ -236,7 +236,7 @@ def test_from_dict(self, monkeypatch):
236236
"type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator",
237237
"init_parameters": {
238238
"api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "type": "env_var", "strict": True},
239-
"model": "claude-3-5-sonnet-20240620",
239+
"model": "claude-3-7-sonnet-latest",
240240
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
241241
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
242242
"tools": [
@@ -259,7 +259,7 @@ def test_from_dict(self, monkeypatch):
259259
component = AnthropicChatGenerator.from_dict(data)
260260

261261
assert isinstance(component, AnthropicChatGenerator)
262-
assert component.model == "claude-3-5-sonnet-20240620"
262+
assert component.model == "claude-3-7-sonnet-latest"
263263
assert component.streaming_callback is print_streaming_chunk
264264
assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"}
265265
assert component.api_key == Secret.from_env_var("ANTHROPIC_API_KEY")
@@ -276,7 +276,7 @@ def test_from_dict_fail_wo_env_var(self, monkeypatch):
276276
"type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator",
277277
"init_parameters": {
278278
"api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "type": "env_var", "strict": True},
279-
"model": "claude-3-5-sonnet-20240620",
279+
"model": "claude-3-7-sonnet-latest",
280280
"streaming_callback": "haystack.components.generators.utils.print_streaming_chunk",
281281
"generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"},
282282
},
@@ -316,7 +316,7 @@ def test_run_with_params(self, chat_messages, mock_anthropic_completion):
316316
assert len(response["replies"]) == 1
317317
assert isinstance(response["replies"][0], ChatMessage)
318318
assert "Hello! I'm Claude." in response["replies"][0].text
319-
assert response["replies"][0].meta["model"] == "claude-3-5-sonnet-20240620"
319+
assert response["replies"][0].meta["model"] == "claude-3-7-sonnet-latest"
320320
assert response["replies"][0].meta["finish_reason"] == "end_turn"
321321

322322
def test_check_duplicate_tool_names(self, tools):
@@ -350,7 +350,7 @@ def test_convert_anthropic_chunk_to_streaming_chunk(self):
350350
"type": "message",
351351
"role": "assistant",
352352
"content": [],
353-
"model": "claude-3-5-sonnet-20240620",
353+
"model": "claude-3-7-sonnet-latest",
354354
"stop_reason": None,
355355
"stop_sequence": None,
356356
"usage": {"input_tokens": 25, "output_tokens": 1},
@@ -371,7 +371,7 @@ def test_convert_anthropic_chunk_to_streaming_chunk(self):
371371
"type": "message",
372372
"role": "assistant",
373373
"content": [],
374-
"model": "claude-3-5-sonnet-20240620",
374+
"model": "claude-3-7-sonnet-latest",
375375
"stop_reason": None,
376376
"stop_sequence": None,
377377
"usage": {
@@ -702,7 +702,7 @@ def test_serde_in_pipeline(self):
702702

703703
generator = AnthropicChatGenerator(
704704
api_key=Secret.from_env_var("ANTHROPIC_API_KEY", strict=False),
705-
model="claude-3-5-sonnet-20240620",
705+
model="claude-3-7-sonnet-latest",
706706
generation_kwargs={"temperature": 0.6},
707707
tools=[tool],
708708
)
@@ -722,7 +722,7 @@ def test_serde_in_pipeline(self):
722722
"type": type_,
723723
"init_parameters": {
724724
"api_key": {"type": "env_var", "env_vars": ["ANTHROPIC_API_KEY"], "strict": False},
725-
"model": "claude-3-5-sonnet-20240620",
725+
"model": "claude-3-7-sonnet-latest",
726726
"generation_kwargs": {"temperature": 0.6},
727727
"ignore_tools_thinking_messages": True,
728728
"streaming_callback": None,
@@ -784,7 +784,7 @@ def test_live_run(self):
784784
assert len(results["replies"]) == 1
785785
message: ChatMessage = results["replies"][0]
786786
assert "Paris" in message.text
787-
assert "claude-3-5-sonnet-20240620" in message.meta["model"]
787+
assert "claude-3-7-sonnet-latest" in message.meta["model"]
788788
assert message.meta["finish_reason"] == "end_turn"
789789

790790
@pytest.mark.skipif(
@@ -824,7 +824,7 @@ def __call__(self, chunk: StreamingChunk) -> None:
824824
message: ChatMessage = results["replies"][0]
825825
assert "Paris" in message.text
826826

827-
assert "claude-3-5-sonnet-20240620" in message.meta["model"]
827+
assert "claude-3-7-sonnet-latest" in message.meta["model"]
828828
assert message.meta["finish_reason"] == "end_turn"
829829

830830
assert callback.counter > 1
@@ -1317,7 +1317,7 @@ def test_from_dict_with_prompt_caching(self, monkeypatch):
13171317
"type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator",
13181318
"init_parameters": {
13191319
"api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "strict": True, "type": "env_var"},
1320-
"model": "claude-3-5-sonnet-20240620",
1320+
"model": "claude-3-7-sonnet-latest",
13211321
"generation_kwargs": {"extra_headers": {"anthropic-beta": "prompt-caching-2024-07-31"}},
13221322
},
13231323
}
@@ -1364,7 +1364,7 @@ async def mock_anthropic_completion_async(self):
13641364
completion = Message(
13651365
id="foo",
13661366
type="message",
1367-
model="claude-3-5-sonnet-20240620",
1367+
model="claude-3-7-sonnet-latest",
13681368
role="assistant",
13691369
content=[TextBlockParam(type="text", text="Hello! I'm Claude.")],
13701370
stop_reason="end_turn",
@@ -1380,7 +1380,7 @@ async def mock_anthropic_completion_async_with_tool(self):
13801380
completion = Message(
13811381
id="foo",
13821382
type="message",
1383-
model="claude-3-5-sonnet-20240620",
1383+
model="claude-3-7-sonnet-latest",
13841384
role="assistant",
13851385
content=[
13861386
TextBlockParam(type="text", text="Let me check the weather for you."),
@@ -1431,7 +1431,7 @@ async def test_run_async_with_params(self, chat_messages, mock_anthropic_complet
14311431
assert len(response["replies"]) == 1
14321432
assert isinstance(response["replies"][0], ChatMessage)
14331433
assert "Hello! I'm Claude." in response["replies"][0].text
1434-
assert response["replies"][0].meta["model"] == "claude-3-5-sonnet-20240620"
1434+
assert response["replies"][0].meta["model"] == "claude-3-7-sonnet-latest"
14351435
assert response["replies"][0].meta["finish_reason"] == "end_turn"
14361436

14371437
@pytest.mark.asyncio
@@ -1449,7 +1449,7 @@ async def test_live_run_async(self):
14491449
assert len(results["replies"]) == 1
14501450
message: ChatMessage = results["replies"][0]
14511451
assert "Paris" in message.text
1452-
assert "claude-3-5-sonnet-20240620" in message.meta["model"]
1452+
assert "claude-3-7-sonnet-latest" in message.meta["model"]
14531453
assert message.meta["finish_reason"] == "end_turn"
14541454

14551455
@pytest.mark.asyncio
@@ -1482,7 +1482,7 @@ async def callback(chunk: StreamingChunk) -> None:
14821482
assert len(results["replies"]) == 1
14831483
message = results["replies"][0]
14841484
assert "paris" in message.text.lower()
1485-
assert "claude-3-5-sonnet-20240620" in message.meta["model"]
1485+
assert "claude-3-7-sonnet-latest" in message.meta["model"]
14861486
assert message.meta["finish_reason"] == "end_turn"
14871487

14881488
# Verify streaming behavior

0 commit comments

Comments
 (0)