Chat: show a writing indicator instead of a quick answer while the AI writes
Browse files- chat/chat.js +4 -6
chat/chat.js
CHANGED
|
@@ -192,9 +192,8 @@ async function ask(question) {
|
|
| 192 |
const messages = chatMessages(question, passages, auditBrief(chat.audit), history);
|
| 193 |
reply.question = question; reply.history = history;
|
| 194 |
if (state.engine) {
|
| 195 |
-
//
|
| 196 |
-
reply.
|
| 197 |
-
reply.note = '✨ The AI is writing a fuller answer…';
|
| 198 |
render();
|
| 199 |
await aiAnswer(chat, reply, messages, passages);
|
| 200 |
} else {
|
|
@@ -216,12 +215,11 @@ async function aiAnswer(chat, reply, messages, passages) {
|
|
| 216 |
let engine = state.engine;
|
| 217 |
for (let attempt = 0; attempt < 2 && engine; attempt++) {
|
| 218 |
try {
|
| 219 |
-
reply.pending = false;
|
| 220 |
const stream = await engine.chat.completions.create({ messages, temperature: 0, max_tokens: 700, stream: true });
|
| 221 |
let last = 0, started = false;
|
| 222 |
for await (const chunk of stream) {
|
| 223 |
const delta = chunk.choices[0]?.delta?.content || '';
|
| 224 |
-
if (!started && delta) { started = true; reply.content = ''; reply.quick = false; reply.writing = false; reply.note = ''; }
|
| 225 |
reply.content += delta;
|
| 226 |
if (Date.now() - last > 120) { last = Date.now(); const el = $(`m${index}`); if (el) el.innerHTML = markdown(clean(reply.content), passages, index); }
|
| 227 |
}
|
|
@@ -238,7 +236,7 @@ async function aiAnswer(chat, reply, messages, passages) {
|
|
| 238 |
engine = attempt === 0 ? await getEngine() : null;
|
| 239 |
}
|
| 240 |
}
|
| 241 |
-
reply.content = quickAnswer(passages); reply.cited = true; reply.quick = true; reply.writing = false;
|
| 242 |
reply.note = 'Quick answer from the knowledge base (the AI could not run just now).';
|
| 243 |
}
|
| 244 |
|
|
|
|
| 192 |
const messages = chatMessages(question, passages, auditBrief(chat.audit), history);
|
| 193 |
reply.question = question; reply.history = history;
|
| 194 |
if (state.engine) {
|
| 195 |
+
// Typing dots until the AI's first words arrive; the knowledge-base answer is only the fallback if the AI fails.
|
| 196 |
+
reply.writing = true; reply.note = '✨ Writing answer…';
|
|
|
|
| 197 |
render();
|
| 198 |
await aiAnswer(chat, reply, messages, passages);
|
| 199 |
} else {
|
|
|
|
| 215 |
let engine = state.engine;
|
| 216 |
for (let attempt = 0; attempt < 2 && engine; attempt++) {
|
| 217 |
try {
|
|
|
|
| 218 |
const stream = await engine.chat.completions.create({ messages, temperature: 0, max_tokens: 700, stream: true });
|
| 219 |
let last = 0, started = false;
|
| 220 |
for await (const chunk of stream) {
|
| 221 |
const delta = chunk.choices[0]?.delta?.content || '';
|
| 222 |
+
if (!started && delta) { started = true; reply.pending = false; reply.content = ''; reply.quick = false; reply.writing = false; reply.note = ''; }
|
| 223 |
reply.content += delta;
|
| 224 |
if (Date.now() - last > 120) { last = Date.now(); const el = $(`m${index}`); if (el) el.innerHTML = markdown(clean(reply.content), passages, index); }
|
| 225 |
}
|
|
|
|
| 236 |
engine = attempt === 0 ? await getEngine() : null;
|
| 237 |
}
|
| 238 |
}
|
| 239 |
+
reply.pending = false; reply.content = quickAnswer(passages); reply.cited = true; reply.quick = true; reply.writing = false;
|
| 240 |
reply.note = 'Quick answer from the knowledge base (the AI could not run just now).';
|
| 241 |
}
|
| 242 |
|