Skip to content

Commit

Permalink
fix: better scrolling as LLMs responses are written to the page
Browse files Browse the repository at this point in the history
  • Loading branch information
klown committed Jul 26, 2024
1 parent ffa9424 commit 4814b14
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions apps/ollama/ollama.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function setSelectedModel () {
}

/**
* Handle clicke on the "use all models" checkbox. This will eneable or disbale
* Handle click on the "use all models" checkbox. This will eneable or disbale
* the models <select> element and reset `nameOfModelToUse` as appropriate.
*/
function useAllModelsClicked () {
Expand Down Expand Up @@ -196,11 +196,11 @@ async function outputResult(response, outputEl, defaultMsg) {
for await (const aPart of response) {
console.debug(aPart.message.content);
outputEl.innerText += aPart.message.content;
outputEl.scrollIntoView(false);
document.body.scrollIntoView({behavior: "smooth", block: "end"});
}
if (outputEl.innerText === "") {
outputEl.innerText = ( defaultMsg === undefined ? "LLM gave no results" : defaultMsg);
outputEl.scrollIntoView(false);
document.body.scrollIntoView({behavior: "smooth", block: "end"});
}
}

Expand Down Expand Up @@ -244,9 +244,10 @@ async function queryEachModel (promptText) {
count++;

// Clear the general "Working..." message after all models have been
// queried
// queried, and scroll to the bottom
if (count === names.length) {
document.getElementById("ollamaOutput").innerText = "";
outputResult([], document.getElementById("ollamaOutput"), "");
document.body.scrollTop = document.body.scrollHeight;
}
});
});
Expand Down Expand Up @@ -274,7 +275,6 @@ function createOutputSection(modelName) {
paragraph.setAttribute("id", `${modelName}_output`);
paragraph.append("Working ...");
sectionEl.appendChild(paragraph);
paragraph.scrollIntoView(false);
}
else {
// Rationale: if <section id=section_modelName ...> exists, it was created
Expand Down

0 comments on commit 4814b14

Please sign in to comment.