dvc890 commited on
Commit
586757f
·
verified ·
1 Parent(s): fc13b52

Update ai-routes.js

Browse files
Files changed (1) hide show
  1. ai-routes.js +4 -5
ai-routes.js CHANGED
@@ -338,8 +338,8 @@ async function streamDoubao(baseParams, res, username, mode = 'chat', config, en
338
  }
339
 
340
  // 4. Search Status
341
- // Explicitly catch the searching event
342
- if (eventType === 'response.web_search_call.searching') {
343
  res.write(`data: ${JSON.stringify({ type: 'search', status: 'searching' })}\n\n`);
344
  if (res.flush) res.flush();
345
  }
@@ -352,7 +352,7 @@ async function streamDoubao(baseParams, res, username, mode = 'chat', config, en
352
  }
353
  }
354
 
355
- // Fallback for Legacy/Chat Format (Safety net, in case they revert or mix formats)
356
  if (!eventType && json.response?.output_text?.delta) {
357
  const content = json.response.output_text.delta;
358
  fullText += content;
@@ -434,9 +434,8 @@ async function streamDoubao(baseParams, res, username, mode = 'chat', config, en
434
  if (e.response?.status === 400 && idToSend) {
435
  console.log(`[AI] ⚠️ 400 Error with ID. Retrying with full history...`);
436
  idToSend = null;
437
- // Recursive retry with modified params (careful with infinite loops, handled by loop structure somewhat, but strictly we should just clear DB and fail this request gracefully or implement simpler retry)
438
  await User.findOneAndUpdate({ username }, { doubaoState: { responseId: null } });
439
- // We won't recurse here to keep it simple, just fail and let user retry (which will pick up null ID)
440
  throw new Error("Context invalid. Please retry.");
441
  }
442
  throw e;
 
338
  }
339
 
340
  // 4. Search Status
341
+ // Explicitly catch multiple search-related events
342
+ if (eventType === 'response.web_search_call.searching' || eventType === 'response.web_search_call.in_progress') {
343
  res.write(`data: ${JSON.stringify({ type: 'search', status: 'searching' })}\n\n`);
344
  if (res.flush) res.flush();
345
  }
 
352
  }
353
  }
354
 
355
+ // Fallback for Legacy/Chat Format (Safety net)
356
  if (!eventType && json.response?.output_text?.delta) {
357
  const content = json.response.output_text.delta;
358
  fullText += content;
 
434
  if (e.response?.status === 400 && idToSend) {
435
  console.log(`[AI] ⚠️ 400 Error with ID. Retrying with full history...`);
436
  idToSend = null;
437
+ // Recursive retry with modified params
438
  await User.findOneAndUpdate({ username }, { doubaoState: { responseId: null } });
 
439
  throw new Error("Context invalid. Please retry.");
440
  }
441
  throw e;