-
Notifications
You must be signed in to change notification settings - Fork 167
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
base: master
Are you sure you want to change the base?
Add payload size limit #3017
Changes from 1 commit
baa8e92
39a6bb6
c9ea47b
2f51a3d
1857e24
3db9d0e
275264b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,11 @@ const BOT_ERROR_MESSAGE: Readonly<ChatMessage> = { | |
role: 'assistant' | ||
}; | ||
|
||
const MESSAGE_TOO_LONG_MESSAGE: Readonly<ChatMessage> = { | ||
content: 'Your message is too long. Please try again with a shorter message.', | ||
role: 'assistant' | ||
}; | ||
|
||
const scrollToBottom = (ref: React.RefObject<HTMLDivElement>) => { | ||
ref.current?.scrollTo({ top: ref.current?.scrollHeight }); | ||
}; | ||
|
@@ -32,6 +37,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => { | |
const [chatId, setChatId] = useState<string>(); | ||
const [messages, setMessages] = useState<ChatMessage[]>([INITIAL_MESSAGE]); | ||
const [userInput, setUserInput] = useState(''); | ||
const [maxContentSize, setMaxContentSize] = useState(1000); | ||
const tokens = useTokens(); | ||
|
||
const handleUserInput = (event: React.ChangeEvent<HTMLInputElement>) => { | ||
|
@@ -42,6 +48,10 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => { | |
if (userInput.trim() === '') { | ||
return; | ||
} | ||
if (userInput.length > maxContentSize) { | ||
setMessages(prev => [...prev, MESSAGE_TOO_LONG_MESSAGE]); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be a simple indicator of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the comment. Feature added. |
||
setUserInput(''); | ||
setMessages(prev => [...prev, { role: 'user', content: userInput }]); | ||
setIsLoading(true); | ||
|
@@ -56,7 +66,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => { | |
.finally(() => { | ||
setIsLoading(false); | ||
}); | ||
}, [chatId, tokens, userInput]); | ||
}, [chatId, tokens, userInput, maxContentSize]); | ||
|
||
const keyDown: React.KeyboardEventHandler<HTMLInputElement> = useCallback( | ||
e => { | ||
|
@@ -71,7 +81,9 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => { | |
initChat(tokens, getSection(), getText()).then(resp => { | ||
const message = resp.response; | ||
const conversationId = resp.conversationId; | ||
const maxMessageSize = resp.maxContentSize; | ||
setMessages([message]); | ||
setMaxContentSize(maxMessageSize); | ||
setChatId(conversationId); | ||
}); | ||
}, [getSection, getText, tokens]); | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.