Skip to content

Commit

Permalink
feat: support for tools in AnthropicChatGenerator (#118)
Browse files Browse the repository at this point in the history
* Initial implementation

* Tool use for streaming

* Add system message support, proper generation_kwargs handling

* system message format

* Minor

* Minor fixes

* Improve pydocs

* Check duplicate tools

* Update haystack_experimental/components/generators/anthropic/__init__.py

Co-authored-by: Stefano Fiorucci <[email protected]>

* Update haystack_experimental/components/generators/anthropic/chat/chat_generator.py

Co-authored-by: Stefano Fiorucci <[email protected]>

* Update haystack_experimental/components/generators/anthropic/chat/chat_generator.py

Co-authored-by: Stefano Fiorucci <[email protected]>

* Update haystack_experimental/components/generators/anthropic/chat/chat_generator.py

Co-authored-by: Stefano Fiorucci <[email protected]>

* PR feedback

* Fix class pydoc

* PR feedback

* Handle tools round trip

* PR feedback

* Small lint

* Parallel tool support

* Special handing for ToolCallResult messages

* Simplify _convert_messages_to_anthropic_format

* More tests, improve coverage

* Increase coverage

* Update haystack_experimental/components/generators/anthropic/chat/chat_generator.py

Co-authored-by: Stefano Fiorucci <[email protected]>

* PR feedback

* PR feedback - rename method

* try simplification

* PR feedback - pydoc updates

* pylint

* Simplify main message conversion algorithm

* further simplifaction + test

* update readme

---------

Co-authored-by: Stefano Fiorucci <[email protected]>
  • Loading branch information
vblagoje and anakin87 authored Oct 30, 2024
1 parent fbeeac7 commit bad887b
Show file tree
Hide file tree
Showing 7 changed files with 1,371 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The latest version of the package contains the following experiments:
| [`EvaluationHarness`][1] | Evaluation orchestrator | October 2024 | None | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/rag_eval_harness.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/74) |
| [`OpenAIFunctionCaller`][2] | Function Calling Component | October 2024 | None | 🔜 | |
| [`OpenAPITool`][3] | OpenAPITool component | October 2024 | jsonref | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/openapitool.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/79)|
| Support for Tools: [refactored `ChatMessage` dataclass][10], [`Tool` dataclass][4], [refactored `OpenAIChatGenerator`][11], [refactored `OllamaChatGenerator`][14], [`ToolInvoker` component][12] | Tool Calling support | November 2024 | jsonschema | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/tools_support.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/98)|
| Support for Tools: [refactored `ChatMessage` dataclass][10], [`Tool` dataclass][4], [refactored `OpenAIChatGenerator`][11], [refactored `OllamaChatGenerator`][14], [refactored `HuggingFaceAPIChatGenerator`][15], [refactored `AnthropicChatGenerator`][16], [`ToolInvoker` component][12] | Tool Calling support | November 2024 | jsonschema | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/tools_support.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/98)|
| [`ChatMessageWriter`][5] | Memory Component | December 2024 | None | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/conversational_rag_using_memory.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/75) |
| [`ChatMessageRetriever`][6] | Memory Component | December 2024 | None | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/conversational_rag_using_memory.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/75) |
| [`InMemoryChatMessageStore`][7] | Memory Store | December 2024 | None | <a href="https://colab.research.google.com/github/deepset-ai/haystack-cookbook/blob/main/notebooks/conversational_rag_using_memory.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> | [Discuss](https://github.com/deepset-ai/haystack-experimental/discussions/75) |
Expand All @@ -62,6 +62,8 @@ The latest version of the package contains the following experiments:
[12]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/tools/tool_invoker.py
[13]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/extractors/llm_metadata_extractor.py
[14]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/generators/ollama/chat/chat_generator.py
[15]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/generators/chat/hugging_face_api.py
[16]: https://github.com/deepset-ai/haystack-experimental/blob/main/haystack_experimental/components/generators/anthropic/chat/chat_generator.py

## Usage

Expand Down
1 change: 1 addition & 0 deletions docs/pydoc/config/generators_api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ loaders:
search_path: [../../../]
modules: ["haystack_experimental.components.generators.chat.openai",
"haystack_experimental.components.generators.chat.hugging_face_api",
"haystack_experimental.components.generators.anthropic.chat.chat_generator",
"haystack_experimental.components.generators.ollama.chat.chat_generator"]
ignore_when_discovered: ["__init__"]
processors:
Expand Down
2 changes: 2 additions & 0 deletions haystack_experimental/components/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@


from .extractors import LLMMetadataExtractor
from .generators.anthropic.chat.chat_generator import AnthropicChatGenerator
from .generators.chat import HuggingFaceAPIChatGenerator, OpenAIChatGenerator
from .generators.ollama.chat.chat_generator import OllamaChatGenerator
from .retrievers.auto_merging_retriever import AutoMergingRetriever
Expand All @@ -19,6 +20,7 @@
"HuggingFaceAPIChatGenerator",
"OllamaChatGenerator",
"OpenAIChatGenerator",
"AnthropicChatGenerator",
"LLMMetadataExtractor",
"HierarchicalDocumentSplitter",
"OpenAIFunctionCaller",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

from .chat.chat_generator import AnthropicChatGenerator

__all__ = ["AnthropicChatGenerator"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

from haystack_experimental.components.generators.anthropic.chat.chat_generator import AnthropicChatGenerator

__all__ = ["AnthropicChatGenerator"]
Loading

0 comments on commit bad887b

Please sign in to comment.