Skip to content

Commit

Permalink
Visually indicate messages truncated by context
Browse files Browse the repository at this point in the history
  • Loading branch information
jart committed Dec 13, 2024
1 parent 08e7a21 commit 956e62c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions llamafile/server/www/chatbot.css
Original file line number Diff line number Diff line change
Expand Up @@ -675,3 +675,8 @@ ul li:first-child {
width: 0;
transition: width 0.2s ease-out;
}

.ooc {
vertical-align: middle;
margin-left: 0.2rem;
}
13 changes: 13 additions & 0 deletions llamafile/server/www/chatbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ async function handleChatStream(response) {
try {
const parsed = JSON.parse(data);
const content = parsed.choices[0]?.delta?.content || "";
const finishReason = parsed.choices[0]?.finish_reason;

// handle prefill progress
if (parsed.x_prefill_progress !== undefined) {
Expand All @@ -154,6 +155,18 @@ async function handleChatStream(response) {
high.feed(content);
scrollToBottom();
}

// we don't supply max_tokens, so "length" can
// only mean that we ran out of context window
if (finishReason === "length" && hdom) {
let img = hdom.push("IMG", "ooc");
img.src = "ooc.svg";
img.alt = "🚫";
img.title = "Message truncated due to running out of context window. Consider tuning --ctx-size and/or --reserve-tokens";
img.width = 16;
img.height = 16;
hdom.pop();
}
} catch (e) {
console.error("Error parsing JSON:", e);
}
Expand Down
15 changes: 15 additions & 0 deletions llamafile/server/www/ooc.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 956e62c

Please sign in to comment.