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(parser): add BedrockEventModel parser and envelope #3286

Merged
merged 6 commits into from
Nov 2, 2023

Conversation

rubenfonseca
Copy link
Contributor

@rubenfonseca rubenfonseca commented Nov 2, 2023

Issue number: #3261

Summary

Changes

Please provide a summary of what's being changed

This PR adds parser and envelope support for the Bedrock Agent event

User experience

Please share what the user experience looks like before and after this change

from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.parser.models import BedrockAgentEventModel


@event_parser(model=BedrockAgentEventModel)
def lambda_handler(event: BedrockAgentEventModel, context):
    print(event.api_path)
    print(event.input_text)

Envelopes:

from pydantic import BaseModel

from aws_lambda_powertools.utilities.parser import event_parser
from aws_lambda_powertools.utilities.parser.envelopes import BedrockAgentEnvelope


class MyBusinessModel(BaseModel):
    name: str
    age: int


@event_parser(model=MyBusinessModel, envelope=BedrockAgentEnvelope)
def lambda_handler(event: MyBusinessModel, context):
    print(event.name)
    print(event.age)

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Nov 2, 2023
@leandrodamascena
Copy link
Contributor

@ran-isenberg 🚀

@boring-cyborg boring-cyborg bot added the tests label Nov 2, 2023
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 2, 2023
@rubenfonseca rubenfonseca linked an issue Nov 2, 2023 that may be closed by this pull request
2 tasks
@rubenfonseca rubenfonseca added the parser Parser (Pydantic) utility label Nov 2, 2023
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Nov 2, 2023
@rubenfonseca rubenfonseca marked this pull request as ready for review November 2, 2023 15:48
@rubenfonseca rubenfonseca requested a review from a team as a code owner November 2, 2023 15:48
Copy link

sonarcloud bot commented Nov 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@codecov-commenter
Copy link

codecov-commenter commented Nov 2, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (0964e75) 95.12% compared to head (a30ea43) 95.14%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3286      +/-   ##
===========================================
+ Coverage    95.12%   95.14%   +0.02%     
===========================================
  Files          203      205       +2     
  Lines         9476     9517      +41     
  Branches      1742     1742              
===========================================
+ Hits          9014     9055      +41     
  Misses         342      342              
  Partials       120      120              
Files Coverage Δ
..._powertools/utilities/parser/envelopes/__init__.py 100.00% <100.00%> (ø)
...rtools/utilities/parser/envelopes/bedrock_agent.py 100.00% <100.00%> (ø)
...bda_powertools/utilities/parser/models/__init__.py 100.00% <100.00%> (ø)
...owertools/utilities/parser/models/bedrock_agent.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@leandrodamascena leandrodamascena left a comment

Choose a reason for hiding this comment

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

APPROVED!

@leandrodamascena leandrodamascena merged commit 07a31aa into develop Nov 2, 2023
16 checks passed
@leandrodamascena leandrodamascena deleted the rf/bedrock-event-parser branch November 2, 2023 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation parser Parser (Pydantic) utility size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add support for the Bedrock Agent event and response formats
4 participants