feat: localchat, a Go + Templ + HTMX chat app for local Gemma models

Streams replies over SSE from any OpenAI-compatible server (oMLX,
llama.cpp, Ollama, ...). Single binary that can install itself as an
OS service; docker compose bundles llama.cpp + Gemma 4 E2B.
This commit is contained in:
bdeb1337 committed 2026-10-05 07:24:09 +02:00
commit d1b512ff77
28 files changed
+2457

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// Small UX touches on top of HTMX: Enter to send, auto-growing textarea,
// clearing the input after sending, and keeping the newest message in view.
(() => {
const form = document.getElementById("composer");
const input = form.querySelector("textarea");
const messages = document.getElementById("messages");
const grow = () => {
input.style.height = "auto";
input.style.height = input.scrollHeight + "px";
};
const nearBottom = () =>
messages.scrollHeight - messages.scrollTop - messages.clientHeight < 120;
const scrollDown = () => (messages.scrollTop = messages.scrollHeight);
input.addEventListener("input", grow);
input.addEventListener("keydown", (e) => {
if (e.key === "Enter" && !e.shiftKey && !e.isComposing) {
e.preventDefault();
if (input.value.trim()) form.requestSubmit();
}
});
form.addEventListener("htmx:afterRequest", (e) => {
if (e.detail.successful) {
form.reset();
grow();
scrollDown();
}
});
// Follow streaming tokens, unless the user scrolled up to read.
let follow = true;
messages.addEventListener("scroll", () => (follow = nearBottom()));
document.body.addEventListener("htmx:sseMessage", () => follow && scrollDown());
document.body.addEventListener("htmx:afterSwap", () => follow && scrollDown());
scrollDown();
})();