Skip to content

Pattern update - apigw-lambda-bedrock-sam #2742

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

Merged
merged 2 commits into from
Jun 8, 2025
Merged

Conversation

Sliiiin
Copy link
Contributor

@Sliiiin Sliiiin commented May 26, 2025

I've updated the bedrock_integration.py file to work with Claude 3.5 using the messaging API. Here are the changes I made:

  1. Changed the request format from the older completion API to the messaging API:
    • Replaced the prompt field with a structured messages array
    • Added the required anthropic_version parameter set to "bedrock-2023-05-31"
    • Changed max_tokens_to_sample to max_tokens
    • Removed the stop_sequences parameter as it's handled differently in the messaging API

  2. Updated the response handling:
    • The messaging API returns a different response structure with content in an array
    • Added code to extract the completion text from response_body.get('content', [{}])[0].get('text', '')
    • Extracted the stop reason from response_body.get('stop_reason', '')
    • Formatted the response to maintain backward compatibility with your existing API

  3. Updated README slightly to reflect the changes.

Copy link
Contributor

@bfreiberg bfreiberg left a comment

Choose a reason for hiding this comment

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

Changes look good so far. Could you please take a look if the Lambda layer is still needed. It seems it only imports the boto3 library

@Sliiiin
Copy link
Contributor Author

Sliiiin commented May 28, 2025

Lambda layer is not required and was removed. README references to the Lambda Layer have also been removed.

@bfreiberg
Copy link
Contributor

Looks good, thank you for your contribution.

@bfreiberg bfreiberg merged commit ce2beda into aws-samples:main Jun 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants