File size: 2,448 Bytes
718aa48 a84172d 718aa48 a84172d 718aa48 a84172d 718aa48 a84172d 718aa48 a84172d 718aa48 a84172d 718aa48 a84172d 718aa48 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
// === Theme Toggle ===
const themeToggle = document.getElementById("themeToggle");
const toggleConfig = document.getElementById("toggleConfig");
const configPanel = document.getElementById("configPanel");
const html = document.documentElement;
function setInitialTheme() {
const savedTheme = localStorage.getItem("theme");
if (savedTheme === "dark") {
html.classList.add("dark");
} else if (savedTheme === "light") {
html.classList.remove("dark");
} else {
const prefersDark = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;
if (prefersDark) html.classList.add("dark");
else html.classList.remove("dark");
}
}
setInitialTheme();
themeToggle.addEventListener("click", () => {
const isDark = html.classList.toggle("dark");
localStorage.setItem("theme", isDark ? "dark" : "light");
});
toggleConfig.addEventListener("click", () => {
configPanel.classList.toggle("hidden");
});
// === Chat Handling ===
const chatForm = document.getElementById("chatForm");
const userInput = document.getElementById("userInput");
const chatContainer = document.getElementById("chatContainer");
const modelA = document.getElementById("modelA");
const modelB = document.getElementById("modelB");
const modelC = document.getElementById("modelC");
function appendMessage(role, text) {
const div = document.createElement("div");
div.className = `p-3 rounded shadow max-w-2xl ${role === "user" ? "bg-blue text-fg0 self-end" : "bg-green text-fg0 self-start"}`;
div.innerText = text;
chatContainer.appendChild(div);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
chatForm.addEventListener("submit", async (e) => {
e.preventDefault();
const prompt = userInput.value.trim();
if (!prompt) return;
appendMessage("user", prompt);
userInput.value = "";
appendMessage("bot", "Thinking...");
const settings = {
models: {
"LLM-A": modelA.value,
"LLM-B": modelB.value,
"LLM-C": modelC.value,
},
};
const response = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ prompt, settings }),
});
chatContainer.lastChild.remove(); // remove 'Thinking...'
if (response.ok) {
const data = await response.json();
appendMessage("bot", data.response);
} else {
appendMessage(
"bot",
"An error occurred. Please check your model selections.",
);
}
});
|