Update static/script.js
Browse files- static/script.js +21 -14
static/script.js
CHANGED
|
@@ -20,8 +20,8 @@ function createDropdown(dropdownId) {
|
|
| 20 |
const dropdown = document.getElementById(dropdownId);
|
| 21 |
const selected = dropdown.querySelector(".selected");
|
| 22 |
const options = dropdown.querySelector(".options");
|
| 23 |
-
const
|
| 24 |
-
const nameDisplay =
|
| 25 |
|
| 26 |
MODEL_LIST.forEach(model => {
|
| 27 |
const option = document.createElement("div");
|
|
@@ -34,7 +34,10 @@ function createDropdown(dropdownId) {
|
|
| 34 |
e.stopPropagation();
|
| 35 |
selected.textContent = model.name;
|
| 36 |
dropdown.dataset.value = model.id;
|
| 37 |
-
nameDisplay
|
|
|
|
|
|
|
|
|
|
| 38 |
options.classList.add("hidden");
|
| 39 |
});
|
| 40 |
});
|
|
@@ -178,19 +181,23 @@ chatForm.addEventListener("submit", async (e) => {
|
|
| 178 |
aggregator: selections["LLM-D"]
|
| 179 |
};
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
|
|
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
["A", "B", "C", "D"].forEach(id => hideLoader(id));
|
| 193 |
-
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 194 |
}
|
| 195 |
});
|
| 196 |
|
|
|
|
| 20 |
const dropdown = document.getElementById(dropdownId);
|
| 21 |
const selected = dropdown.querySelector(".selected");
|
| 22 |
const options = dropdown.querySelector(".options");
|
| 23 |
+
const modelZone = dropdown.closest(".model-zone");
|
| 24 |
+
const nameDisplay = modelZone.querySelector(".model-name");
|
| 25 |
|
| 26 |
MODEL_LIST.forEach(model => {
|
| 27 |
const option = document.createElement("div");
|
|
|
|
| 34 |
e.stopPropagation();
|
| 35 |
selected.textContent = model.name;
|
| 36 |
dropdown.dataset.value = model.id;
|
| 37 |
+
if (nameDisplay) {
|
| 38 |
+
nameDisplay.textContent = model.name;
|
| 39 |
+
nameDisplay.classList.remove("hidden");
|
| 40 |
+
}
|
| 41 |
options.classList.add("hidden");
|
| 42 |
});
|
| 43 |
});
|
|
|
|
| 181 |
aggregator: selections["LLM-D"]
|
| 182 |
};
|
| 183 |
|
| 184 |
+
try {
|
| 185 |
+
const response = await fetch("/chat", {
|
| 186 |
+
method: "POST",
|
| 187 |
+
headers: { "Content-Type": "application/json" },
|
| 188 |
+
body: JSON.stringify({ prompt, settings })
|
| 189 |
+
});
|
| 190 |
|
| 191 |
+
if (response.ok) {
|
| 192 |
+
const data = await response.json();
|
| 193 |
+
appendMessage("bot", data.response);
|
| 194 |
+
} else {
|
| 195 |
+
appendMessage("bot", "An error occurred. Please check your model selections.");
|
| 196 |
+
}
|
| 197 |
+
} catch (error) {
|
| 198 |
+
appendMessage("bot", "An unexpected error occurred.");
|
| 199 |
+
} finally {
|
| 200 |
["A", "B", "C", "D"].forEach(id => hideLoader(id));
|
|
|
|
| 201 |
}
|
| 202 |
});
|
| 203 |
|