nsarrazin HF staff commited on
Commit
6ba40e9
1 Parent(s): f23c3c9

Make chat title summarization non blocking (#575)

Browse files
src/routes/conversation/[id]/+server.ts CHANGED
@@ -208,14 +208,16 @@ export async function POST({ request, locals, params, getClientAddress }) {
208
 
209
  update({ type: "status", status: "started" });
210
 
211
- if (conv.title === "New Chat" && messages.length === 1) {
212
- try {
213
- conv.title = (await summarize(newPrompt)) ?? conv.title;
214
- update({ type: "status", status: "title", message: conv.title });
215
- } catch (e) {
216
- console.error(e);
 
 
217
  }
218
- }
219
 
220
  await collections.conversations.updateOne(
221
  {
@@ -321,6 +323,7 @@ export async function POST({ request, locals, params, getClientAddress }) {
321
  text: messages[messages.length - 1].content,
322
  });
323
 
 
324
  return;
325
  },
326
  async cancel() {
 
208
 
209
  update({ type: "status", status: "started" });
210
 
211
+ const summarizeIfNeeded = (async () => {
212
+ if (conv.title === "New Chat" && messages.length === 1) {
213
+ try {
214
+ conv.title = (await summarize(newPrompt)) ?? conv.title;
215
+ update({ type: "status", status: "title", message: conv.title });
216
+ } catch (e) {
217
+ console.error(e);
218
+ }
219
  }
220
+ })();
221
 
222
  await collections.conversations.updateOne(
223
  {
 
323
  text: messages[messages.length - 1].content,
324
  });
325
 
326
+ await summarizeIfNeeded;
327
  return;
328
  },
329
  async cancel() {