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

Add payload size limit #3017

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Add payload size limit #3017

wants to merge 7 commits into from

Conversation

yiwen101
Copy link
Contributor

Description

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

Checklist

  • I have tested this code
  • I have updated the documentation

@yiwen101
Copy link
Contributor Author

yiwen101 commented Aug 12, 2024

Corresponding BE PR: source-academy/backend#1151

@yiwen101 yiwen101 changed the title Add payload_size_limit Add payload size limit Aug 12, 2024
@coveralls
Copy link

coveralls commented Aug 12, 2024

Pull Request Test Coverage Report for Build 11011737335

Details

  • 0 of 4 (0.0%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.006%) to 31.443%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/pages/sicp/subcomponents/chatbot/ChatBox.tsx 0 4 0.0%
Files with Coverage Reduction New Missed Lines %
src/pages/sicp/subcomponents/chatbot/ChatBox.tsx 2 7.04%
Totals Coverage Status
Change from base Build 11008401716: -0.006%
Covered Lines: 4852
Relevant Lines: 14551

💛 - Coveralls

Comment on lines 51 to 54
if (userInput.length > maxContentSize) {
setMessages(prev => [...prev, MESSAGE_TOO_LONG_MESSAGE]);
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should error when the user submits. Instead, the input field should not allow more than maxContentSize characters.

Copy link
Member

Choose a reason for hiding this comment

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

This can be a simple indicator of maxContentSize - userInput.length and set the onChange to ignore extra characters beyond maxContentSize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the comment. Feature added.

Comment on lines 25 to 28
const MESSAGE_TOO_LONG_MESSAGE: Readonly<ChatMessage> = {
content: 'Your message is too long. Please try again with a shorter message.',
role: 'assistant'
};
Copy link
Member

Choose a reason for hiding this comment

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

That way, this will never be necessary. From UX perspective, it's easier for the user to edit their message before sending in order to fit the character limit, as opposed to having to copy and paste their previous message and send it again. Not to mention, if you do it like this, there will be a mismatch between the conversation history stored in the FE state with the one stored in the DB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right;
it is more intuitive to do let the user trigger this in the first place;
this also pollute the chat history, making it less readable.

@yiwen101 yiwen101 requested a review from sayomaki September 25, 2024 16:50
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