Update static/script.js
Browse files- static/script.js +39 -33
static/script.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
| 1 |
-
// ===
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
{
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
function createDropdown(dropdownId) {
|
| 18 |
const dropdown = document.getElementById(dropdownId);
|
| 19 |
const selected = dropdown.querySelector(".selected");
|
|
@@ -42,9 +44,23 @@ function createDropdown(dropdownId) {
|
|
| 42 |
options.classList.toggle("hidden");
|
| 43 |
});
|
| 44 |
|
| 45 |
-
|
| 46 |
options.classList.add("hidden");
|
| 47 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
}
|
| 49 |
|
| 50 |
// === Theme, Config and Docs Buttons ===
|
|
@@ -121,11 +137,6 @@ const chatForm = document.getElementById("chatForm");
|
|
| 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"}`;
|
|
@@ -152,9 +163,7 @@ chatForm.addEventListener("submit", async (e) => {
|
|
| 152 |
"LLM-D": document.getElementById("aggregator").dataset.value
|
| 153 |
};
|
| 154 |
|
| 155 |
-
|
| 156 |
-
if (selections[key]) showLoader(key.slice(-1)); // showLoader("A", "B", ...)
|
| 157 |
-
}
|
| 158 |
|
| 159 |
const settings = {
|
| 160 |
models: {
|
|
@@ -174,15 +183,12 @@ chatForm.addEventListener("submit", async (e) => {
|
|
| 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 |
-
|
| 184 |
-
hideLoader(key.slice(-1));
|
| 185 |
-
}
|
| 186 |
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 187 |
}
|
| 188 |
});
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// === Dynamic Model Fetching ===
|
| 2 |
+
let MODEL_LIST = [];
|
| 3 |
+
|
| 4 |
+
async function fetchModelList() {
|
| 5 |
+
try {
|
| 6 |
+
const response = await fetch("/models");
|
| 7 |
+
if (response.ok) {
|
| 8 |
+
MODEL_LIST = await response.json();
|
| 9 |
+
initializeDropdowns();
|
| 10 |
+
} else {
|
| 11 |
+
console.error("Failed to fetch model list");
|
| 12 |
+
}
|
| 13 |
+
} catch (error) {
|
| 14 |
+
console.error("Error fetching models:", error);
|
| 15 |
+
}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
// === Create Custom Dropdowns Dynamically ===
|
| 19 |
function createDropdown(dropdownId) {
|
| 20 |
const dropdown = document.getElementById(dropdownId);
|
| 21 |
const selected = dropdown.querySelector(".selected");
|
|
|
|
| 44 |
options.classList.toggle("hidden");
|
| 45 |
});
|
| 46 |
|
| 47 |
+
options.addEventListener("mouseleave", () => {
|
| 48 |
options.classList.add("hidden");
|
| 49 |
});
|
| 50 |
+
|
| 51 |
+
document.addEventListener("click", (e) => {
|
| 52 |
+
if (!dropdown.contains(e.target)) {
|
| 53 |
+
options.classList.add("hidden");
|
| 54 |
+
}
|
| 55 |
+
});
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
// === Initialize All Dropdowns After Fetch ===
|
| 59 |
+
function initializeDropdowns() {
|
| 60 |
+
createDropdown("modelA");
|
| 61 |
+
createDropdown("modelB");
|
| 62 |
+
createDropdown("modelC");
|
| 63 |
+
createDropdown("aggregator");
|
| 64 |
}
|
| 65 |
|
| 66 |
// === Theme, Config and Docs Buttons ===
|
|
|
|
| 137 |
const userInput = document.getElementById("userInput");
|
| 138 |
const chatContainer = document.getElementById("chatContainer");
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
function appendMessage(role, text) {
|
| 141 |
const div = document.createElement("div");
|
| 142 |
div.className = `p-3 rounded shadow max-w-2xl ${role === "user" ? "bg-blue text-fg0 self-end" : "bg-green text-fg0 self-start"}`;
|
|
|
|
| 163 |
"LLM-D": document.getElementById("aggregator").dataset.value
|
| 164 |
};
|
| 165 |
|
| 166 |
+
["A", "B", "C"].forEach(id => showLoader(id));
|
|
|
|
|
|
|
| 167 |
|
| 168 |
const settings = {
|
| 169 |
models: {
|
|
|
|
| 183 |
if (response.ok) {
|
| 184 |
const data = await response.json();
|
| 185 |
appendMessage("bot", data.response);
|
| 186 |
+
["A", "B", "C", "D"].forEach(id => hideLoader(id));
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
} else {
|
| 188 |
+
["A", "B", "C", "D"].forEach(id => hideLoader(id));
|
|
|
|
|
|
|
| 189 |
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 190 |
}
|
| 191 |
});
|
| 192 |
+
|
| 193 |
+
// === Kickstart ===
|
| 194 |
+
fetchModelList();
|