Spaces:
Sleeping
Sleeping
Clicking an example now fills the form fields instead of sending to chat.
Browse files- assets/app.js +35 -26
assets/app.js
CHANGED
|
@@ -137,6 +137,40 @@ function selectedValues(select) {
|
|
| 137 |
return value || null;
|
| 138 |
}
|
| 139 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
function fieldValue(id) {
|
| 141 |
const element = document.getElementById(id);
|
| 142 |
if (element.tagName === "TEXTAREA") {
|
|
@@ -233,7 +267,7 @@ async function loadChoices() {
|
|
| 233 |
const button = document.createElement("button");
|
| 234 |
button.type = "button";
|
| 235 |
button.textContent = persona.label;
|
| 236 |
-
button.addEventListener("click", () =>
|
| 237 |
els.personaList.appendChild(button);
|
| 238 |
}
|
| 239 |
}
|
|
@@ -266,31 +300,6 @@ async function sendChatMessage(message) {
|
|
| 266 |
}
|
| 267 |
}
|
| 268 |
|
| 269 |
-
async function loadPersonaPrompt(personaId) {
|
| 270 |
-
if (state.busy) {
|
| 271 |
-
return;
|
| 272 |
-
}
|
| 273 |
-
|
| 274 |
-
showChatView();
|
| 275 |
-
setBusy(true);
|
| 276 |
-
setStatus("Building demo persona prompt...");
|
| 277 |
-
try {
|
| 278 |
-
const result = await client.predict("/build_persona_prompt", {
|
| 279 |
-
persona_id: personaId,
|
| 280 |
-
});
|
| 281 |
-
const message = unwrapResult(result) || "";
|
| 282 |
-
if (!message) {
|
| 283 |
-
setStatus("Could not load persona prompt.");
|
| 284 |
-
return;
|
| 285 |
-
}
|
| 286 |
-
await sendChatMessage(message);
|
| 287 |
-
} catch (error) {
|
| 288 |
-
setStatus(`Could not load persona prompt: ${error.message || error}`);
|
| 289 |
-
} finally {
|
| 290 |
-
setBusy(false);
|
| 291 |
-
}
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
async function submitForm(event) {
|
| 295 |
event.preventDefault();
|
| 296 |
if (state.busy || !validateForm()) {
|
|
|
|
| 137 |
return value || null;
|
| 138 |
}
|
| 139 |
|
| 140 |
+
function setSelectValue(id, value) {
|
| 141 |
+
const select = document.getElementById(id);
|
| 142 |
+
const text = String(value || "").trim();
|
| 143 |
+
if (!text) {
|
| 144 |
+
select.value = "";
|
| 145 |
+
return;
|
| 146 |
+
}
|
| 147 |
+
|
| 148 |
+
let option = Array.from(select.options).find((entry) => entry.value === text);
|
| 149 |
+
if (!option) {
|
| 150 |
+
option = document.createElement("option");
|
| 151 |
+
option.value = text;
|
| 152 |
+
option.textContent = text;
|
| 153 |
+
select.appendChild(option);
|
| 154 |
+
}
|
| 155 |
+
select.value = text;
|
| 156 |
+
setFieldInvalid(id, false);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
function fillPersonaForm(persona) {
|
| 160 |
+
const profile = persona.profile || {};
|
| 161 |
+
setSelectValue("current-country", profile.current_country);
|
| 162 |
+
setSelectValue("residence-status", profile.residence_status);
|
| 163 |
+
setSelectValue("education", profile.education);
|
| 164 |
+
setSelectValue("occupation", profile.occupation);
|
| 165 |
+
setSelectValue("experience", profile.experience);
|
| 166 |
+
setSelectValue("budget", profile.budget);
|
| 167 |
+
setSelectValue("family", profile.family);
|
| 168 |
+
setSelectValue("timeline", profile.timeline);
|
| 169 |
+
document.getElementById("goals").value = String(profile.goals || "").trim();
|
| 170 |
+
setFieldInvalid("goals", false);
|
| 171 |
+
setStatus("");
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
function fieldValue(id) {
|
| 175 |
const element = document.getElementById(id);
|
| 176 |
if (element.tagName === "TEXTAREA") {
|
|
|
|
| 267 |
const button = document.createElement("button");
|
| 268 |
button.type = "button";
|
| 269 |
button.textContent = persona.label;
|
| 270 |
+
button.addEventListener("click", () => fillPersonaForm(persona));
|
| 271 |
els.personaList.appendChild(button);
|
| 272 |
}
|
| 273 |
}
|
|
|
|
| 300 |
}
|
| 301 |
}
|
| 302 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
async function submitForm(event) {
|
| 304 |
event.preventDefault();
|
| 305 |
if (state.busy || !validateForm()) {
|