Skip to content

Commit d18ddf1

Browse files
committed
Add redo button to new web ui
1 parent bc82424 commit d18ddf1

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

llamafile/server/www/chatbot.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,20 @@ ul li:first-child {
263263
display: block;
264264
}
265265

266+
.redo-button {
267+
padding: 8px;
268+
background: transparent;
269+
border: none;
270+
cursor: pointer;
271+
font-size: 20px;
272+
color: #666;
273+
transition: color 0.2s;
274+
}
275+
276+
.redo-button:hover {
277+
color: #000;
278+
}
279+
266280
.settings-button {
267281
padding: 0.75rem 1rem;
268282
background: #6c757d;

llamafile/server/www/chatbot.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const stopButton = document.getElementById("stop-button");
3838
const settingsButton = document.getElementById("settings-button");
3939
const settingsModal = document.getElementById("settings-modal");
4040
const closeSettings = document.getElementById("close-settings");
41+
const redoButton = document.getElementById('redo-button');
4142

4243
let abortController = null;
4344
let disableAutoScroll = false;
@@ -71,13 +72,16 @@ function onChatInput() {
7172
}
7273

7374
function cleanupAfterMessage() {
74-
disableAutoScroll = false;
7575
chatMessages.scrollTop = chatMessages.scrollHeight;
7676
chatInput.disabled = false;
7777
sendButton.style.display = "inline-block";
7878
stopButton.style.display = "none";
7979
abortController = null;
80-
chatInput.focus();
80+
if (!disableAutoScroll) {
81+
scrollToBottom();
82+
chatInput.focus();
83+
}
84+
disableAutoScroll = false;
8185
}
8286

8387
function onWheel(e) {
@@ -146,7 +150,6 @@ function fixUploads(str) {
146150
str = uploadedFiles.reduce(
147151
(text, [from, to]) => text.replaceAll(from, to),
148152
str);
149-
uploadedFiles.length = 0;
150153
return str;
151154
}
152155

@@ -452,13 +455,34 @@ function setupSettings() {
452455
});
453456
}
454457

458+
function removeLastDirectChild(element) {
459+
if (element.lastElementChild) {
460+
element.removeChild(element.lastElementChild);
461+
}
462+
}
463+
464+
function onRedo() {
465+
if (!chatHistory.length)
466+
return;
467+
removeLastDirectChild(chatMessages);
468+
let msg = chatHistory.pop();
469+
if (msg.role === "assistant") {
470+
removeLastDirectChild(chatMessages);
471+
msg = chatHistory.pop();
472+
}
473+
chatInput.value = msg.content;
474+
chatInput.focus();
475+
chatInput.dispatchEvent(new Event("input")); // adjust textarea height
476+
}
477+
455478
async function chatbot() {
456479
flagz = await fetchFlagz();
457480
updateModelInfo();
458481
setupSettings();
459482
startChat([{ role: "system", content: getSystemPrompt() }]);
460483
sendButton.addEventListener("click", sendMessage);
461484
stopButton.addEventListener("click", stopMessage);
485+
redoButton.addEventListener("click", onRedo);
462486
chatInput.addEventListener("input", onChatInput);
463487
chatInput.addEventListener("keydown", onKeyDown);
464488
document.addEventListener("wheel", onWheel);

llamafile/server/www/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ <h1>
2323
<button class="send-button" id="send-button">Send</button>
2424
<button class="stop-button" id="stop-button" style="display:none">Stop</button>
2525
<button class="settings-button" id="settings-button" title="Settings">⚙️</button>
26+
<button class="redo-button" id="redo-button" title="Redo last message"></button>
2627
</div>
2728
</div>
2829

0 commit comments

Comments
 (0)