Update static/script.js
Browse files- static/script.js +39 -29
static/script.js
CHANGED
|
@@ -18,6 +18,8 @@ function createDropdown(dropdownId) {
|
|
| 18 |
const dropdown = document.getElementById(dropdownId);
|
| 19 |
const selected = dropdown.querySelector(".selected");
|
| 20 |
const options = dropdown.querySelector(".options");
|
|
|
|
|
|
|
| 21 |
|
| 22 |
MODEL_LIST.forEach(model => {
|
| 23 |
const option = document.createElement("div");
|
|
@@ -30,6 +32,7 @@ function createDropdown(dropdownId) {
|
|
| 30 |
e.stopPropagation();
|
| 31 |
selected.textContent = model.name;
|
| 32 |
dropdown.dataset.value = model.id;
|
|
|
|
| 33 |
options.classList.add("hidden");
|
| 34 |
});
|
| 35 |
});
|
|
@@ -79,7 +82,6 @@ themeToggle.addEventListener("click", () => {
|
|
| 79 |
themeToggle.textContent = isDark ? "🌙" : "☀️";
|
| 80 |
});
|
| 81 |
|
| 82 |
-
// === Config Panel Toggle Behavior ===
|
| 83 |
toggleConfig.addEventListener("click", () => {
|
| 84 |
if (configPanel.classList.contains("minimal")) {
|
| 85 |
configPanel.classList.remove("minimal");
|
|
@@ -93,30 +95,25 @@ toggleConfig.addEventListener("click", () => {
|
|
| 93 |
}
|
| 94 |
});
|
| 95 |
|
| 96 |
-
// === Docs Button Redirect ===
|
| 97 |
docsButton.addEventListener("click", () => {
|
| 98 |
window.location.href = "/docs";
|
| 99 |
});
|
| 100 |
|
| 101 |
-
// ===
|
| 102 |
-
function
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
`;
|
| 111 |
-
});
|
| 112 |
}
|
| 113 |
|
| 114 |
-
function
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
loader.innerHTML = "";
|
| 119 |
-
});
|
| 120 |
}
|
| 121 |
|
| 122 |
// === Chat Handling ===
|
|
@@ -124,13 +121,11 @@ const chatForm = document.getElementById("chatForm");
|
|
| 124 |
const userInput = document.getElementById("userInput");
|
| 125 |
const chatContainer = document.getElementById("chatContainer");
|
| 126 |
|
| 127 |
-
// Create all dropdowns
|
| 128 |
createDropdown("modelA");
|
| 129 |
createDropdown("modelB");
|
| 130 |
createDropdown("modelC");
|
| 131 |
createDropdown("aggregator");
|
| 132 |
|
| 133 |
-
// Append Message Function
|
| 134 |
function appendMessage(role, text) {
|
| 135 |
const div = document.createElement("div");
|
| 136 |
div.className = `p-3 rounded shadow max-w-2xl ${role === "user" ? "bg-blue text-fg0 self-end" : "bg-green text-fg0 self-start"}`;
|
|
@@ -139,7 +134,6 @@ function appendMessage(role, text) {
|
|
| 139 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 140 |
}
|
| 141 |
|
| 142 |
-
// Form Submit Event
|
| 143 |
chatForm.addEventListener("submit", async (e) => {
|
| 144 |
e.preventDefault();
|
| 145 |
const prompt = userInput.value.trim();
|
|
@@ -150,15 +144,25 @@ chatForm.addEventListener("submit", async (e) => {
|
|
| 150 |
|
| 151 |
configPanel.classList.remove("expanded");
|
| 152 |
configPanel.classList.add("minimal");
|
| 153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
|
| 155 |
const settings = {
|
| 156 |
models: {
|
| 157 |
-
"LLM-A":
|
| 158 |
-
"LLM-B":
|
| 159 |
-
"LLM-C":
|
| 160 |
},
|
| 161 |
-
aggregator:
|
| 162 |
};
|
| 163 |
|
| 164 |
const response = await fetch("/chat", {
|
|
@@ -167,12 +171,18 @@ chatForm.addEventListener("submit", async (e) => {
|
|
| 167 |
body: JSON.stringify({ prompt, settings })
|
| 168 |
});
|
| 169 |
|
| 170 |
-
hideLoaders();
|
| 171 |
-
|
| 172 |
if (response.ok) {
|
| 173 |
const data = await response.json();
|
| 174 |
appendMessage("bot", data.response);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
} else {
|
|
|
|
|
|
|
|
|
|
| 176 |
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 177 |
}
|
| 178 |
});
|
|
|
|
| 18 |
const dropdown = document.getElementById(dropdownId);
|
| 19 |
const selected = dropdown.querySelector(".selected");
|
| 20 |
const options = dropdown.querySelector(".options");
|
| 21 |
+
const label = dropdown.parentElement.querySelector(".model-label");
|
| 22 |
+
const nameDisplay = dropdown.parentElement.querySelector(".model-name");
|
| 23 |
|
| 24 |
MODEL_LIST.forEach(model => {
|
| 25 |
const option = document.createElement("div");
|
|
|
|
| 32 |
e.stopPropagation();
|
| 33 |
selected.textContent = model.name;
|
| 34 |
dropdown.dataset.value = model.id;
|
| 35 |
+
nameDisplay.textContent = model.name;
|
| 36 |
options.classList.add("hidden");
|
| 37 |
});
|
| 38 |
});
|
|
|
|
| 82 |
themeToggle.textContent = isDark ? "🌙" : "☀️";
|
| 83 |
});
|
| 84 |
|
|
|
|
| 85 |
toggleConfig.addEventListener("click", () => {
|
| 86 |
if (configPanel.classList.contains("minimal")) {
|
| 87 |
configPanel.classList.remove("minimal");
|
|
|
|
| 95 |
}
|
| 96 |
});
|
| 97 |
|
|
|
|
| 98 |
docsButton.addEventListener("click", () => {
|
| 99 |
window.location.href = "/docs";
|
| 100 |
});
|
| 101 |
|
| 102 |
+
// === Per-model Loader Control ===
|
| 103 |
+
function showLoader(id) {
|
| 104 |
+
const loader = document.getElementById(`loader${id}`);
|
| 105 |
+
loader.classList.remove("hidden");
|
| 106 |
+
loader.innerHTML = `
|
| 107 |
+
<div class="dot bg-aqua"></div>
|
| 108 |
+
<div class="dot bg-aqua animation-delay-150"></div>
|
| 109 |
+
<div class="dot bg-aqua animation-delay-300"></div>
|
| 110 |
+
`;
|
|
|
|
|
|
|
| 111 |
}
|
| 112 |
|
| 113 |
+
function hideLoader(id) {
|
| 114 |
+
const loader = document.getElementById(`loader${id}`);
|
| 115 |
+
loader.classList.add("hidden");
|
| 116 |
+
loader.innerHTML = "";
|
|
|
|
|
|
|
| 117 |
}
|
| 118 |
|
| 119 |
// === Chat Handling ===
|
|
|
|
| 121 |
const userInput = document.getElementById("userInput");
|
| 122 |
const chatContainer = document.getElementById("chatContainer");
|
| 123 |
|
|
|
|
| 124 |
createDropdown("modelA");
|
| 125 |
createDropdown("modelB");
|
| 126 |
createDropdown("modelC");
|
| 127 |
createDropdown("aggregator");
|
| 128 |
|
|
|
|
| 129 |
function appendMessage(role, text) {
|
| 130 |
const div = document.createElement("div");
|
| 131 |
div.className = `p-3 rounded shadow max-w-2xl ${role === "user" ? "bg-blue text-fg0 self-end" : "bg-green text-fg0 self-start"}`;
|
|
|
|
| 134 |
chatContainer.scrollTop = chatContainer.scrollHeight;
|
| 135 |
}
|
| 136 |
|
|
|
|
| 137 |
chatForm.addEventListener("submit", async (e) => {
|
| 138 |
e.preventDefault();
|
| 139 |
const prompt = userInput.value.trim();
|
|
|
|
| 144 |
|
| 145 |
configPanel.classList.remove("expanded");
|
| 146 |
configPanel.classList.add("minimal");
|
| 147 |
+
|
| 148 |
+
const selections = {
|
| 149 |
+
"LLM-A": document.getElementById("modelA").dataset.value,
|
| 150 |
+
"LLM-B": document.getElementById("modelB").dataset.value,
|
| 151 |
+
"LLM-C": document.getElementById("modelC").dataset.value,
|
| 152 |
+
"LLM-D": document.getElementById("aggregator").dataset.value
|
| 153 |
+
};
|
| 154 |
+
|
| 155 |
+
for (const key of Object.keys(selections)) {
|
| 156 |
+
if (selections[key]) showLoader(key.slice(-1)); // showLoader("A", "B", ...)
|
| 157 |
+
}
|
| 158 |
|
| 159 |
const settings = {
|
| 160 |
models: {
|
| 161 |
+
"LLM-A": selections["LLM-A"],
|
| 162 |
+
"LLM-B": selections["LLM-B"],
|
| 163 |
+
"LLM-C": selections["LLM-C"]
|
| 164 |
},
|
| 165 |
+
aggregator: selections["LLM-D"]
|
| 166 |
};
|
| 167 |
|
| 168 |
const response = await fetch("/chat", {
|
|
|
|
| 171 |
body: JSON.stringify({ prompt, settings })
|
| 172 |
});
|
| 173 |
|
|
|
|
|
|
|
| 174 |
if (response.ok) {
|
| 175 |
const data = await response.json();
|
| 176 |
appendMessage("bot", data.response);
|
| 177 |
+
|
| 178 |
+
// Simulated per-model delay (optional)
|
| 179 |
+
for (const key of Object.keys(selections)) {
|
| 180 |
+
hideLoader(key.slice(-1));
|
| 181 |
+
}
|
| 182 |
} else {
|
| 183 |
+
for (const key of Object.keys(selections)) {
|
| 184 |
+
hideLoader(key.slice(-1));
|
| 185 |
+
}
|
| 186 |
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 187 |
}
|
| 188 |
});
|