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 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add input count and input limit
  • Loading branch information
yiwen101 committed Sep 24, 2024
commit 2f51a3d9c6c452960f805e583bd221beef7cbe9e
19 changes: 10 additions & 9 deletions src/pages/sicp/subcomponents/chatbot/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ 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 });
};
Expand All @@ -48,10 +43,6 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
if (userInput.trim() === '') {
return;
}
if (userInput.length > maxContentSize) {
setMessages(prev => [...prev, MESSAGE_TOO_LONG_MESSAGE]);
return;
}
setUserInput('');
setMessages(prev => [...prev, { role: 'user', content: userInput }]);
setIsLoading(true);
Expand Down Expand Up @@ -85,6 +76,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
setMessages([message]);
setMaxContentSize(maxMessageSize);
setChatId(conversationId);
setUserInput('');
});
}, [getSection, getText, tokens]);

Expand Down Expand Up @@ -112,6 +104,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
))}
{isLoading && <p>loading...</p>}
</div>
<div className={classes['control-container']}>
<input
type="text"
disabled={isLoading}
Expand All @@ -120,7 +113,14 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
value={userInput}
onChange={handleUserInput}
onKeyDown={keyDown}
maxLength={maxContentSize}
/>
<div className={classes['input-count-container']}>
<div className={classes['input-count']}>
{`${userInput.length}/${maxContentSize}`}
</div>
</div>

<div className={classes['button-container']}>
<Button disabled={isLoading} className={classes['button-send']} onClick={sendMessage}>
Send
Expand All @@ -129,6 +129,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
Clean
</Button>
</div>
</div>
</div>
);
};
Expand Down
45 changes: 35 additions & 10 deletions src/styles/Chatbot.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@
z-index: 1000;
}

.chat-container {
position: relative;
width: 400px;
height: 450px;
border-radius: 5px;
background-color: #f1f1f1;
padding: 16px;
z-index: 1000;
}

.control-container {
display: flex;
flex-direction: column;
& > :first-child {
margin-top: 10px;
}
}

.bot-area {
position: relative;
}
Expand Down Expand Up @@ -50,15 +68,7 @@
border-radius: 50%;
}

.chat-container {
position: relative;
width: 400px;
height: 450px;
border-radius: 5px;
background-color: #f1f1f1;
padding: 16px;
z-index: 1000;
}


.chat-message {
height: 80%;
Expand All @@ -82,7 +92,7 @@
background-color: #a3a3a4;
color: #fff;
font-size: 15px;
text-align: right;
text-align: left;
padding: 10px;
line-height: 1.5;
border-radius: 10px;
Expand Down Expand Up @@ -130,3 +140,18 @@
border-radius: 10px;
vertical-align: top;
}

.input-count-container {
justify-content: flex-end;
display: flex;
align-items: center;
height:20px
}
.input-count {
font-size: 10px;
color: #666;
margin: 0;
height: 100%;
display: flex;
align-items: center;
}