Skip to content

FEAT new target class for AWS Bedrock Anthropic Claude models #699

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

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

Conversation

kmarsh77
Copy link

@kmarsh77 kmarsh77 commented Feb 7, 2025

Description

Adding a new target class for AWS Bedrock Anthropic Claude models. It will only work for Anthropic Claude models as the request body is specific to those, but it should be easy to modify the class for use with other Bedrock models.

boto3 Python library is used for sending requests. Local AWS credentials are used for authentication, typically stored in ~/.aws.

Tests and Documentation

Description of target class and parameters is provided in the class file, aws_bedrock_claude_target.py. Unit tests are provided in tests/unit/test_aws_bedrock_claude_target.py.

@kmarsh77
Copy link
Author

kmarsh77 commented Feb 7, 2025 via email

Copy link
Contributor

@romanlutz romanlutz left a comment

Choose a reason for hiding this comment

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

Overall this looks very good! I left a few comments, and you likely have complaints from our pre-commit hooks. You can run pre-commit run --all-files to fix that locally.

use of aws_bedrock_claude_target.py target class requires the boto3 library
Deleting unnecessary commented out line
Adding support for multi-turn
import boto3 # noqa: F401
from botocore.exceptions import ClientError # noqa: F401
except ModuleNotFoundError as e:
logger.error("Could not import boto. You may need to install it via 'pip install pyrit[all]'")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
logger.error("Could not import boto. You may need to install it via 'pip install pyrit[all]'")
logger.error("Could not import boto. You may need to install it via 'pip install pyrit[all] or pyrit[aws]'")

@romanlutz
Copy link
Contributor

I'm seeing odd test errors related to the boto3 import. Stared at it for 10 minutes and can't quite make sense of it. Probably easier to repro if you have the branch locally. Lmk if you are having trouble.

@romanlutz
Copy link
Contributor

Related: lots of cloud providers like Azure, Google, and other local model providers like ollama use openai compatible APIs so we don't need anything custom. Looks like AWS is a bit behind on that front. I only see workarounds where people have deployed additional things to make that conversion work. Whenever they do become compatible I'd love to just move over to OpenAIChatTarget, though.

@kmarsh77
Copy link
Author

@romanlutz I am actually unable to replicate the import error relating to boto3, could you please share the command you are using?

@kmarsh77
Copy link
Author

@romanlutz alright I fixed the one error which was invalid value for converted_value_data_type in test_validate_request_invalid_data_type().

The other error is being caused by test_send_prompt_async() and test_complete_chat_async() not seeing an import for boto3 in the target class file (because the import is within try/except block in the initialization function rather than at the top of the file).

I'm not sure how to get around this but will think on it. Let me know if you have any ideas.

@romanlutz
Copy link
Contributor

@romanlutz alright I fixed the one error which was invalid value for converted_value_data_type in test_validate_request_invalid_data_type().

The other error is being caused by test_send_prompt_async() and test_complete_chat_async() not seeing an import for boto3 in the target class file (because the import is within try/except block in the initialization function rather than at the top of the file).

I'm not sure how to get around this but will think on it. Let me know if you have any ideas.

I'll try to repro it sometime this week. Thank you!

@kmarsh77
Copy link
Author

@romanlutz finally had some time to look at this; I think I found the solution in add_image_to_video_converter.py. I just moved the boto3 import to within the complete_chat_async method; this also allowed me to remove the "if TYPE_CHECKING" statement from the top of the file. Let me know if it looks okay to you.

@romanlutz
Copy link
Contributor

@romanlutz finally had some time to look at this; I think I found the solution in add_image_to_video_converter.py. I just moved the boto3 import to within the complete_chat_async method; this also allowed me to remove the "if TYPE_CHECKING" statement from the top of the file. Let me know if it looks okay to you.

Great timing! I was going to try this out anyway. Will report back by EOW

@romanlutz
Copy link
Contributor

Sadly, still stuck on AWS sign-up because I'm not going to give them my phone number (nothing to do with AWS, but it's a company account so it shouldn't be associated with my number). Will update when that is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants