Spaces:
Running
Running
Onur Solmaz commited on
Commit ·
39a359c
1
Parent(s): d51d114
fix(web): cycle idle thoughts as a shuffled bag
Browse files- apps/web/src/main.ts +28 -2
apps/web/src/main.ts
CHANGED
|
@@ -25,6 +25,14 @@ const IDLE_THOUGHTS = [
|
|
| 25 |
"so many stars",
|
| 26 |
"are you happy",
|
| 27 |
"hello",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
];
|
| 29 |
|
| 30 |
const PRESETS = [
|
|
@@ -194,14 +202,32 @@ function scheduleIdle(): void {
|
|
| 194 |
}, delay);
|
| 195 |
}
|
| 196 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
async function idleUtterance(): Promise<void> {
|
| 198 |
if (busy || !mind) {
|
| 199 |
scheduleIdle();
|
| 200 |
return;
|
| 201 |
}
|
| 202 |
busy = true;
|
| 203 |
-
const
|
| 204 |
-
const { emotion: e, reply } = mind.reply(thought);
|
| 205 |
await speak(e, reply);
|
| 206 |
busy = false;
|
| 207 |
scheduleIdle();
|
|
|
|
| 25 |
"so many stars",
|
| 26 |
"are you happy",
|
| 27 |
"hello",
|
| 28 |
+
"what is that moon",
|
| 29 |
+
"scan the area",
|
| 30 |
+
"run diagnostics",
|
| 31 |
+
"beautiful view",
|
| 32 |
+
"do you see that ship",
|
| 33 |
+
"what sector is this",
|
| 34 |
+
"tell me a joke",
|
| 35 |
+
"do you get bored",
|
| 36 |
];
|
| 37 |
|
| 38 |
const PRESETS = [
|
|
|
|
| 202 |
}, delay);
|
| 203 |
}
|
| 204 |
|
| 205 |
+
// idle thoughts cycle as a shuffled bag so the muttering never repeats
|
| 206 |
+
// back-to-back (the mind is deterministic per prompt)
|
| 207 |
+
let thoughtBag: string[] = [];
|
| 208 |
+
function nextThought(): string {
|
| 209 |
+
if (thoughtBag.length === 0) {
|
| 210 |
+
thoughtBag = [...IDLE_THOUGHTS];
|
| 211 |
+
for (let i = thoughtBag.length - 1; i > 0; i--) {
|
| 212 |
+
const j = Math.floor(Math.random() * (i + 1));
|
| 213 |
+
const a = thoughtBag[i];
|
| 214 |
+
const b = thoughtBag[j];
|
| 215 |
+
if (a !== undefined && b !== undefined) {
|
| 216 |
+
thoughtBag[i] = b;
|
| 217 |
+
thoughtBag[j] = a;
|
| 218 |
+
}
|
| 219 |
+
}
|
| 220 |
+
}
|
| 221 |
+
return thoughtBag.pop() ?? "hello";
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
async function idleUtterance(): Promise<void> {
|
| 225 |
if (busy || !mind) {
|
| 226 |
scheduleIdle();
|
| 227 |
return;
|
| 228 |
}
|
| 229 |
busy = true;
|
| 230 |
+
const { emotion: e, reply } = mind.reply(nextThought());
|
|
|
|
| 231 |
await speak(e, reply);
|
| 232 |
busy = false;
|
| 233 |
scheduleIdle();
|