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(ai) add attachment validations #6211

Merged
merged 8 commits into from
Nov 27, 2024
Merged

Conversation

dbanksdesign
Copy link
Contributor

Description of changes

Issue #, if available

Description of how you validated changes

Checklist

  • Have read the Pull Request Guidelines
  • PR description included
  • yarn test passes and tests are updated/added
  • PR title and commit messages follow conventional commit syntax
  • If this change should result in a version bump, changeset added (This can be done after creating the PR.) This does not apply to changes made to docs, e2e, examples, or other private packages.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@dbanksdesign dbanksdesign requested a review from a team as a code owner November 26, 2024 22:48
Copy link

changeset-bot bot commented Nov 26, 2024

🦋 Changeset detected

Latest commit: d86499f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 15 packages
Name Type
@aws-amplify/ui-react-ai Minor
@aws-amplify/ui Patch
@aws-amplify/ui-react-auth Patch
@aws-amplify/ui-react-core-auth Patch
@aws-amplify/ui-react-core-notifications Patch
@aws-amplify/ui-react-core Patch
@aws-amplify/ui-react-liveness Patch
@aws-amplify/ui-react-native-auth Patch
@aws-amplify/ui-react-native Patch
@aws-amplify/ui-react-notifications Patch
@aws-amplify/ui-react-storage Patch
@aws-amplify/ui-react Patch
@aws-amplify/ui-vue Patch
@aws-amplify/ui-angular Patch
@aws-amplify/ui-react-geo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Comment on lines 17 to 22
// We save attachments as base64 strings into dynamodb for conversation history
// DynamoDB has a max size of 400kb for records
// This can be overridden so cutsomers could provide a lower number
// or a higher number if in the future we support larger sizes.
maxAttachmentSize = 400_000,
maxAttachments = 20,
Copy link
Member

Choose a reason for hiding this comment

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

Are these safe to override today?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are safe to override to be lower, but if they are higher the customer will probably get an error further down in the stack (in lambda)

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Lmk if I missed it, but are we validating that the provided values are not larger than the known thresholds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We aren't validating if the provided values are larger than the known thresholds. I did this because the thresholds will go up at a later point, the 400kb size limit per file is a limitation of our backend implementation and not Bedrock or the AI model's, and we do plan to fix this long term. I can change it so we enforce the limits though if we feel strongly about it.

calebpollman
calebpollman previously approved these changes Nov 27, 2024
Copy link
Member

@calebpollman calebpollman left a comment

Choose a reason for hiding this comment

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

🚢

May want to consider adding max threshold validation for the maxAttachments/maxAttachmentSize props to ensure override values don't exceed the dynamodb limits in the future

jordanvn
jordanvn previously approved these changes Nov 27, 2024
Comment on lines +66 to +68
for (const file of files) {
const arrayBuffer = await file.arrayBuffer();
const base64 = arrayBufferToBase64(arrayBuffer);
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Could this be done as Promise.all?

maxAttachmentSize,
});

if (hasMaxError ?? hasMaxSizeError) {
Copy link
Member

Choose a reason for hiding this comment

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

Should this be ||? If hasMaxError ever becomes false (maybe due to changes to code in the future) instead of being nullish, it could hide the hasMaxSizeError

acceptedFiles: File[];
rejectedFiles: File[];
hasMaxSizeError?: boolean;
hasMaxError?: boolean;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Can we consider changing this to hasMaxAttachmentsError or something? It's not immediately clear what "max" is referring to

error += displayText.getMaxAttachmentErrorText(maxAttachments);
}
if (hasMaxSizeError) {
error += displayText.getAttachmentSizeErrorText(
Copy link
Member

Choose a reason for hiding this comment

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

If both errors are present, is the string just joined together without a space in between? Would it be better to do something like

const errors = [];
errors.push(maxAttachmentError);
errors.push(sizeError);
setError(errors.join(' '));

cshfang
cshfang previously approved these changes Nov 27, 2024
@dbanksdesign dbanksdesign merged commit 9ab56f4 into main Nov 27, 2024
34 checks passed
@dbanksdesign dbanksdesign deleted the ai-attachment-validation branch November 27, 2024 23:21
@github-actions github-actions bot mentioned this pull request Nov 27, 2024
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.

4 participants