Skip to content

Commit 081bec8

Browse files
committed
added updated timeout and char limit
1 parent 765647b commit 081bec8

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

assets/css/demo.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@
245245
white-space: pre-wrap;
246246
}
247247

248+
.char-limit-mesg {
249+
font-size: 14px!important;
250+
margin-top: 4px;
251+
font-style: italic;
252+
}
253+
254+
248255

249256

250257
#notification-popup {

themes/arm-design-system-hugo-theme/layouts/partials/demo-components/demo--kubectl.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h2>Demo</h2>
4545
<p id="reset-demo-txt">Reset chat</p>
4646
</div>
4747
<div class="c-col">
48-
<ads-button id="submit-button" level="primary">Run</ads-button>
48+
<ads-button id="submit-button" level="primary"><i id="submit-icon" class="fa-solid fa-arrow-up"></i></ads-button>
4949
</div>
5050
</div>
5151
</div>

themes/arm-design-system-hugo-theme/layouts/partials/demo-components/llm-chatbot/demo-stats--llm-chatbot.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2>Arm KleidiAI Demo</h2>
2626
<div id="demo-actions">
2727
<div class="c-row">
2828
<div class="c-col" id="input-and-submit">
29-
<textarea id="user-input-for-demo" placeholder="Enter message" tabindex="1" rows="1"></textarea>
29+
<textarea id="user-input-for-demo" placeholder="Enter message" maxlength="10000" tabindex="1" rows="1"></textarea>
3030
<ads-button id="submit-button" level="primary" tabindex="2" disabled>
3131
<i id="submit-icon" class="fa-solid fa-spinner fa-spin"></i>
3232
</ads-button>

themes/arm-design-system-hugo-theme/layouts/partials/demo-components/llm-chatbot/javascript--llm-chatbot.html

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,28 @@
320320
// Add the user's input to the chat history, and spawn a new thinking chatbot response placeholder
321321
function addUserMessage_andChatbotPlaceholder(user_input) {
322322
const all_messages_div = document.getElementById('all-messages-div');
323-
323+
const text_area = document.querySelector('#user-input-for-demo');
324+
324325
const user_div = document.createElement('div');
325326
user_div.classList.add('user-message');
326327

327328
const user_span_for_message = document.createElement('span');
328329
user_div.appendChild(user_span_for_message);
329-
330330
user_span_for_message.textContent = user_input;
331+
332+
if (Array.from(user_input).length >= text_area.maxLength) {
333+
const user_text_limit_update = document.createElement('div');
334+
user_text_limit_update.classList.add('char-limit-mesg');
335+
user_div.appendChild(user_text_limit_update);
336+
user_text_limit_update.textContent = "Char limit reached - truncated to 10,000.";
337+
}
338+
339+
331340
all_messages_div.insertBefore(user_div, all_messages_div.firstChild);
332341

342+
343+
344+
333345
const chatbot_div = document.createElement('div');
334346
chatbot_div.classList.add('chatbot-message');
335347

@@ -397,6 +409,16 @@
397409
}
398410

399411

412+
function tellUserServerIsThinking() {
413+
document.getElementById('all_messages_div')
414+
const current_chatbot_message = document.querySelector("#all-messages-div .chatbot-message");
415+
if (current_chatbot_message) {
416+
const ads_loader_element = current_chatbot_message.querySelector("span ads-loader");
417+
418+
ads_loader_element.setAttribute('label','Still thinking, one moment...')
419+
}
420+
}
421+
400422

401423
// Event listener additions to key demo components
402424
document.addEventListener("DOMContentLoaded", function() {
@@ -442,11 +464,10 @@
442464

443465
// User enters any text in textinput
444466
text_area.addEventListener('input', function() {
445-
//this.style.height = 'auto';
446-
//this.style.height = (this.scrollHeight > this.clientHeight ? this.scrollHeight : this.clientHeight) + 'px';
447467
adjustInputHeight();
448468
toggleButton(); // enable input button
449469
});
470+
450471
// User hits enter in textinput
451472
text_area.addEventListener('keydown', function(event) {
452473
if (event.key === 'Enter') {
@@ -541,10 +562,23 @@
541562

542563
// Set timeout
543564
const controller = new AbortController();
544-
let timeout;
545-
function resetTimeout() {
565+
let timeout; // for server timeout
566+
let tell_user_timeout; // to inform user the UI is thinking
567+
const timeout_duration = 5000; // 5 seconds by default
568+
const tell_user_timeout_duration = 6000; // 6 seconds by default
569+
function resetTimeout(duration = timeout_duration) {
546570
clearTimeout(timeout);
547-
timeout = setTimeout(() => controller.abort(), 5000); // Adjust the timeout duration as needed
571+
clearTimeout(tell_user_timeout);
572+
573+
574+
timeout = setTimeout(() => controller.abort(), duration);
575+
576+
if (duration > 5000) {
577+
tell_user_timeout = setTimeout(() => {
578+
tellUserServerIsThinking();
579+
}, tell_user_timeout_duration); // trigger at 6 seconds
580+
}
581+
548582
}
549583
resetTimeout(); // Start the timeout right before sending
550584

@@ -592,6 +626,7 @@
592626
}
593627
else if (return_json.value == 'STREAM_STARTING') {
594628
hidePopup();
629+
resetTimeout(15000); // Set timeout to 15 seconds
595630
}
596631
}
597632
else if (return_json.message_type === 'chunk') {

0 commit comments

Comments
 (0)