umer-wasim commited on
Commit
b42d57c
·
verified ·
1 Parent(s): 4a44611

Chat: show why the AI could not answer

Browse files
Files changed (1) hide show
  1. chat/chat.js +3 -2
chat/chat.js CHANGED
@@ -249,7 +249,7 @@ async function ask(question) {
249
  // Write (or rewrite) an answer with the model; the GPU can be lost (memory pressure, sleep): restart once, else keep the quick answer.
250
  async function aiAnswer(chat, reply, messages, passages) {
251
  const index = chat.messages.indexOf(reply);
252
- let engine = state.engine;
253
  for (let attempt = 0; attempt < 2 && engine; attempt++) {
254
  try {
255
  const stream = await engine.chat.completions.create({ messages, temperature: 0, max_tokens: 700, stream: true });
@@ -285,13 +285,14 @@ async function aiAnswer(chat, reply, messages, passages) {
285
  if (chatProblems(messages[messages.length - 1].content, reply.content).length) reply.note = 'Some details in this answer could not be matched to the sources. Check them in the sources below before acting.';
286
  return;
287
  } catch (error) {
 
288
  if (!/lost|Instance reference|GPUDevice|disposed/i.test(error.message)) { console.warn('AI answer failed', error); break; } // keep the quick answer
289
  status('The graphics processor was reset; restarting the AI…', 0.5);
290
  state.engine = null; state.enginePromise = null;
291
  engine = attempt === 0 ? await getEngine() : null;
292
  }
293
  }
294
- fallback(reply, passages, 'Quick answer from the knowledge base (the AI could not run just now).');
295
  }
296
 
297
  function fallback(reply, passages, note) {
 
249
  // Write (or rewrite) an answer with the model; the GPU can be lost (memory pressure, sleep): restart once, else keep the quick answer.
250
  async function aiAnswer(chat, reply, messages, passages) {
251
  const index = chat.messages.indexOf(reply);
252
+ let engine = state.engine, lastError = '';
253
  for (let attempt = 0; attempt < 2 && engine; attempt++) {
254
  try {
255
  const stream = await engine.chat.completions.create({ messages, temperature: 0, max_tokens: 700, stream: true });
 
285
  if (chatProblems(messages[messages.length - 1].content, reply.content).length) reply.note = 'Some details in this answer could not be matched to the sources. Check them in the sources below before acting.';
286
  return;
287
  } catch (error) {
288
+ lastError = error.message;
289
  if (!/lost|Instance reference|GPUDevice|disposed/i.test(error.message)) { console.warn('AI answer failed', error); break; } // keep the quick answer
290
  status('The graphics processor was reset; restarting the AI…', 0.5);
291
  state.engine = null; state.enginePromise = null;
292
  engine = attempt === 0 ? await getEngine() : null;
293
  }
294
  }
295
+ fallback(reply, passages, `Quick answer from the knowledge base (the AI could not run just now${lastError ? `: ${lastError.slice(0, 140)}` : ''}).`);
296
  }
297
 
298
  function fallback(reply, passages, note) {