diff --git a/integrations/anthropic/example/documentation_rag_with_claude.py b/integrations/anthropic/example/documentation_rag_with_claude.py index 98cc9d40e..22df45ac3 100644 --- a/integrations/anthropic/example/documentation_rag_with_claude.py +++ b/integrations/anthropic/example/documentation_rag_with_claude.py @@ -23,7 +23,6 @@ "llm", AnthropicChatGenerator( api_key=Secret.from_env_var("ANTHROPIC_API_KEY"), - model="claude-3-sonnet-20240229", streaming_callback=print_streaming_chunk, ), ) diff --git a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py index b5dda870a..d150788d2 100644 --- a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py +++ b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/chat/chat_generator.py @@ -27,21 +27,21 @@ class AnthropicChatGenerator: Enables text generation using Anthropic state-of-the-art Claude 3 family of large language models (LLMs) through the Anthropic messaging API. - It supports models like `claude-3-opus`, `claude-3-sonnet`, and `claude-3-haiku`, accessed through the - `/v1/messages` API endpoint using the Claude v2.1 messaging version. + It supports models like `claude-3-5-sonnet`, `claude-3-opus`, `claude-3-sonnet`, and `claude-3-haiku`, + accessed through the [`/v1/messages`](https://docs.anthropic.com/en/api/messages) API endpoint. Users can pass any text generation parameters valid for the Anthropic messaging API directly to this component via the `generation_kwargs` parameter in `__init__` or the `generation_kwargs` parameter in the `run` method. For more details on the parameters supported by the Anthropic API, refer to the - Anthropic Message API [documentation](https://docs.anthropic.com/claude/reference/messages_post). + Anthropic Message API [documentation](https://docs.anthropic.com/en/api/messages). ```python from haystack_integrations.components.generators.anthropic import AnthropicChatGenerator from haystack.dataclasses import ChatMessage messages = [ChatMessage.from_user("What's Natural Language Processing?")] - client = AnthropicChatGenerator(model="claude-3-sonnet-20240229") + client = AnthropicChatGenerator(model="claude-3-5-sonnet-20240620") response = client.run(messages) print(response) @@ -49,15 +49,16 @@ class AnthropicChatGenerator: >> focuses on enabling computers to understand, interpret, and generate human language. It involves developing >> techniques and algorithms to analyze and process text or speech data, allowing machines to comprehend and >> communicate in natural languages like English, Spanish, or Chinese.', role=, - >> name=None, meta={'model': 'claude-3-sonnet-20240229', 'index': 0, 'finish_reason': 'end_turn', + >> name=None, meta={'model': 'claude-3-5-sonnet-20240620', 'index': 0, 'finish_reason': 'end_turn', >> 'usage': {'input_tokens': 15, 'output_tokens': 64}})]} ``` For more details on supported models and their capabilities, refer to the Anthropic [documentation](https://docs.anthropic.com/claude/docs/intro-to-claude). - Note: We don't yet support vision [capabilities](https://docs.anthropic.com/claude/docs/vision) in the current - implementation. + Note: We only support text input/output modalities, and + image [modality](https://docs.anthropic.com/en/docs/build-with-claude/vision) is not supported in + this version of AnthropicChatGenerator. """ # The parameters that can be passed to the Anthropic API https://docs.anthropic.com/claude/reference/messages_post @@ -76,7 +77,7 @@ class AnthropicChatGenerator: def __init__( self, api_key: Secret = Secret.from_env_var("ANTHROPIC_API_KEY"), # noqa: B008 - model: str = "claude-3-sonnet-20240229", + model: str = "claude-3-5-sonnet-20240620", streaming_callback: Optional[Callable[[StreamingChunk], None]] = None, generation_kwargs: Optional[Dict[str, Any]] = None, ignore_tools_thinking_messages: bool = True, diff --git a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/generator.py b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/generator.py index aa78dfed1..4cb8fd3e6 100644 --- a/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/generator.py +++ b/integrations/anthropic/src/haystack_integrations/components/generators/anthropic/generator.py @@ -29,7 +29,7 @@ class AnthropicGenerator: ```python from haystack_integrations.components.generators.anthropic import AnthropicGenerator - client = AnthropicGenerator(model="claude-2.1") + client = AnthropicGenerator(model="claude-3-sonnet-20240229") response = client.run("What's Natural Language Processing? Be brief.") print(response) >>{'replies': ['Natural language processing (NLP) is a branch of artificial intelligence focused on enabling diff --git a/integrations/anthropic/tests/test_chat_generator.py b/integrations/anthropic/tests/test_chat_generator.py index 4f1a5bef6..3ffa24c94 100644 --- a/integrations/anthropic/tests/test_chat_generator.py +++ b/integrations/anthropic/tests/test_chat_generator.py @@ -23,7 +23,7 @@ def test_init_default(self, monkeypatch): monkeypatch.setenv("ANTHROPIC_API_KEY", "test-api-key") component = AnthropicChatGenerator() assert component.client.api_key == "test-api-key" - assert component.model == "claude-3-sonnet-20240229" + assert component.model == "claude-3-5-sonnet-20240620" assert component.streaming_callback is None assert not component.generation_kwargs assert component.ignore_tools_thinking_messages @@ -36,13 +36,13 @@ def test_init_fail_wo_api_key(self, monkeypatch): def test_init_with_parameters(self): component = AnthropicChatGenerator( api_key=Secret.from_token("test-api-key"), - model="claude-3-sonnet-20240229", + model="claude-3-5-sonnet-20240620", streaming_callback=print_streaming_chunk, generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"}, ignore_tools_thinking_messages=False, ) assert component.client.api_key == "test-api-key" - assert component.model == "claude-3-sonnet-20240229" + assert component.model == "claude-3-5-sonnet-20240620" assert component.streaming_callback is print_streaming_chunk assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"} assert component.ignore_tools_thinking_messages is False @@ -55,7 +55,7 @@ def test_to_dict_default(self, monkeypatch): "type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator", "init_parameters": { "api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "strict": True, "type": "env_var"}, - "model": "claude-3-sonnet-20240229", + "model": "claude-3-5-sonnet-20240620", "streaming_callback": None, "generation_kwargs": {}, "ignore_tools_thinking_messages": True, @@ -74,7 +74,7 @@ def test_to_dict_with_parameters(self, monkeypatch): "type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator", "init_parameters": { "api_key": {"env_vars": ["ENV_VAR"], "strict": True, "type": "env_var"}, - "model": "claude-3-sonnet-20240229", + "model": "claude-3-5-sonnet-20240620", "streaming_callback": "haystack.components.generators.utils.print_streaming_chunk", "generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"}, "ignore_tools_thinking_messages": True, @@ -84,7 +84,7 @@ def test_to_dict_with_parameters(self, monkeypatch): def test_to_dict_with_lambda_streaming_callback(self, monkeypatch): monkeypatch.setenv("ANTHROPIC_API_KEY", "test-api-key") component = AnthropicChatGenerator( - model="claude-3-sonnet-20240229", + model="claude-3-5-sonnet-20240620", streaming_callback=lambda x: x, generation_kwargs={"max_tokens": 10, "some_test_param": "test-params"}, ) @@ -93,7 +93,7 @@ def test_to_dict_with_lambda_streaming_callback(self, monkeypatch): "type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator", "init_parameters": { "api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "strict": True, "type": "env_var"}, - "model": "claude-3-sonnet-20240229", + "model": "claude-3-5-sonnet-20240620", "streaming_callback": "tests.test_chat_generator.", "generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"}, "ignore_tools_thinking_messages": True, @@ -106,14 +106,14 @@ def test_from_dict(self, monkeypatch): "type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator", "init_parameters": { "api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "strict": True, "type": "env_var"}, - "model": "claude-3-sonnet-20240229", + "model": "claude-3-5-sonnet-20240620", "streaming_callback": "haystack.components.generators.utils.print_streaming_chunk", "generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"}, "ignore_tools_thinking_messages": True, }, } component = AnthropicChatGenerator.from_dict(data) - assert component.model == "claude-3-sonnet-20240229" + assert component.model == "claude-3-5-sonnet-20240620" assert component.streaming_callback is print_streaming_chunk assert component.generation_kwargs == {"max_tokens": 10, "some_test_param": "test-params"} assert component.api_key == Secret.from_env_var("ANTHROPIC_API_KEY") @@ -124,7 +124,7 @@ def test_from_dict_fail_wo_env_var(self, monkeypatch): "type": "haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator", "init_parameters": { "api_key": {"env_vars": ["ANTHROPIC_API_KEY"], "strict": True, "type": "env_var"}, - "model": "claude-3-sonnet-20240229", + "model": "claude-3-5-sonnet-20240620", "streaming_callback": "haystack.components.generators.utils.print_streaming_chunk", "generation_kwargs": {"max_tokens": 10, "some_test_param": "test-params"}, "ignore_tools_thinking_messages": True,