Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: AmazonBedrockChatGenerator - add tools support #1304

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Jan 20, 2025

Why:

Adds Haystack tool support to AmazonBedrockChatGenerator

What:

  • Added method to convert Haystack tools to Amazon Bedrock toolConfig format, facilitating tool integration.
  • Modified AmazonBedrockChatGenerator to accept, serialize, and handle tool specifications as part of the chat messages.
  • Updated testing suite to cover tool-related functionalities, ensuring robustness and reliability.

How can it be used:

The changes enable users to pass tools to AmazonBedrockChatGenerator, enhancing the model's capabilities by allowing it to use external tools within chat interactions. Here is a simplified example:

from haystack.dataclasses import ChatMessage
from haystack_integrations.components.generators.amazon_bedrock import AmazonBedrockChatGenerator
from haystack.tools import Tool

def weather(city: str):
        """Get weather for a given city."""
        return f"The weather in {city} is sunny and 32°C"

tool_parameters = {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}
tool = Tool(
    name="weather",
    description="useful to determine the weather in a given location",
    parameters=tool_parameters,
    function=weather,
)

messages = [ChatMessage.from_user("What's the weather like in Paris?")]
generator = AmazonBedrockChatGenerator(model="model_name", tools=[tool])
response = generator.run(messages=messages)

How did you test it:

Implemented thorough unit and integration tests to validate the addition of tool-related functionalities. Tests included:

  • Serialization and deserialization of tool configurations.
  • Ensuring tool calls within conversations behave as expected.
  • Integration tests with mock and live scenarios for tool usage within chat interactions.

Notes for the reviewer:

Please pay special attention to the serialization and deserialization processes for tool objects and the handling of tool calls within the chat messages. Consider reviewing the edge cases in the test suite that handle different orderings of tool messages in replies.

@github-actions github-actions bot added integration:amazon-bedrock type:documentation Improvements or additions to documentation labels Jan 20, 2025
@vblagoje vblagoje marked this pull request as ready for review January 22, 2025 11:01
@vblagoje vblagoje requested a review from a team as a code owner January 22, 2025 11:01
@vblagoje vblagoje requested review from julian-risch and anakin87 and removed request for a team January 22, 2025 11:01
@vblagoje vblagoje marked this pull request as draft January 22, 2025 14:30
@vblagoje vblagoje marked this pull request as ready for review January 22, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bedrock ChatGenerator - support for Tool
1 participant