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 - migrate Anthropic chat models to use messaging API #545

Merged
merged 15 commits into from
Mar 11, 2024

Conversation

vblagoje
Copy link
Member

@vblagoje vblagoje commented Mar 6, 2024

Fixes deepset-ai/haystack#7324

  • Supports new Anthropic messaging API
  • Supports old Claude 2.1 chat models and new Claude 3 chat models
  • Add support for system messages

@github-actions github-actions bot added integration:amazon-bedrock type:documentation Improvements or additions to documentation labels Mar 6, 2024
@vblagoje vblagoje changed the title feat: Adjust AmazonBedrockChatGenerator for Anthropic Claude chat models to use messaging API feat: AmazonBedrockChatGenerator - migrate Anthropic chat models to use messaging API Mar 6, 2024
@vblagoje vblagoje marked this pull request as ready for review March 6, 2024 12:05
@vblagoje vblagoje requested a review from a team as a code owner March 6, 2024 12:05
@vblagoje vblagoje requested review from anakin87 and removed request for a team March 6, 2024 12:05
@vblagoje
Copy link
Member Author

vblagoje commented Mar 6, 2024

@anakin87 not a priority yet, let's sync internally first

Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I feel that our Bedrock Generators can be simplified somewhat...
It is not always easy to understand what is going on.

About this PR, I have an idea:
can we start adding integration tests, as we do for other integrations?
That way, we can be sure that our integration is stable and working...

@vblagoje vblagoje requested a review from anakin87 March 8, 2024 16:27
@vblagoje
Copy link
Member Author

@anakin87 in 8683af0 I've added model parameter tracking. I thought it lead to a better UX. If user uses unknown parameter rather than getting exception from AWS she'll get a warning.

Instead of:

>>> client.run(messages, generation_kwargs={"max_tokens": 512, "semi": ["Sprache"]})
Traceback (most recent call last):
  File "/Users/vblagoje/workspace/haystack-core-integrations/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py", line 161, in invoke
    response = self.client.invoke_model_with_response_stream(
  File "/Users/vblagoje/miniconda3/envs/haystack/lib/python3.10/site-packages/botocore/client.py", line 553, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/Users/vblagoje/miniconda3/envs/haystack/lib/python3.10/site-packages/botocore/client.py", line 1009, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: Malformed input request: #: subject must not be valid against schema {"required":["messages"]}#: extraneous key [semi] is not permitted, please reformat your input and try again.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/vblagoje/workspace/haystack-core-integrations/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py", line 190, in run
    return {"replies": self.invoke(messages=messages, **(generation_kwargs or {}))}
  File "/Users/vblagoje/workspace/haystack-core-integrations/integrations/amazon_bedrock/src/haystack_integrations/components/generators/amazon_bedrock/chat/chat_generator.py", line 176, in invoke
    raise AmazonBedrockInferenceError(msg) from exception
haystack_integrations.common.amazon_bedrock.errors.AmazonBedrockInferenceError: Could not inference Amazon Bedrock model anthropic.claude-3-sonnet-20240229-v1:0 due: An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: Malformed input request: #: subject must not be valid against schema {"required":["messages"]}#: extraneous key [semi] is not permitted, please reformat your input and try again.

user will see:

>>> client.run(messages, generation_kwargs={"max_tokens": 512, "semi": ["Sprache"]})
Parameter 'semi' is not allowed and will be ignored.
Natürliche Sprachverarbeitung (NLP) ist ein Bereich der künstlichen Intelligenz, der sich mit der Entwicklung von Computersystemen befasst, die menschliche Sprache in all ihren Formen verstehen und verarbeiten können. Das Ziel ist es, Computern beizubringen, natürliche Sprache zu analysieren, zu interpretieren und zu generieren, so dass eine effektive Kommunikation zwischen Menschen und Maschinen möglich wird.

This comes with cost of tracking these parameters. LMK if you think it is worth it. We can rollback the last commit if you disagree.

Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I would like to simplify this integration a bit in the future.
I still see some legacy of the Prompt Node 😃

Anyway, your PR looks good and I appreciated the extra effort of adding integration tests.
I think they will help us in the future...

@vblagoje vblagoje merged commit f95e4d0 into main Mar 11, 2024
10 checks passed
@vblagoje vblagoje deleted the new_claude_bedrock branch March 11, 2024 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration:amazon-bedrock topic:CI type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

claude-3-sonnet-20240229 is not supported
3 participants