dvc890 commited on
Commit
cdd3023
·
verified ·
1 Parent(s): 983b6b1

Update ai-routes.js

Browse files
Files changed (1) hide show
  1. ai-routes.js +15 -13
ai-routes.js CHANGED
@@ -456,7 +456,20 @@ router.post('/chat', async (req, res) => {
456
  // Build Current Message Parts
457
  const currentParts = [];
458
 
459
- // Add Images first if any
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  if (images && Array.isArray(images)) {
461
  images.forEach(base64 => {
462
  if (base64) {
@@ -470,7 +483,7 @@ router.post('/chat', async (req, res) => {
470
  });
471
  }
472
 
473
- // Add Audio if any
474
  if (audio) {
475
  currentParts.push({
476
  inlineData: {
@@ -480,17 +493,6 @@ router.post('/chat', async (req, res) => {
480
  });
481
  }
482
 
483
- // Add Text if any (must have text if no media, or can accompany media)
484
- if (text && text.trim()) {
485
- currentParts.push({ text: text });
486
- } else if (audio) {
487
- // Fix: If sending audio without text, add a prompt so the model knows what to do
488
- currentParts.push({ text: "请听这段语音并回答。" });
489
- } else if (currentParts.length === 0) {
490
- // Fallback if empty
491
- currentParts.push({ text: "." });
492
- }
493
-
494
  // Prepare Response Stream
495
  res.setHeader('Content-Type', 'text/event-stream');
496
  res.setHeader('Cache-Control', 'no-cache');
 
456
  // Build Current Message Parts
457
  const currentParts = [];
458
 
459
+ // 1. Text Instruction (Priority)
460
+ // FIX: Put text FIRST to ensure model pays attention to instructions before processing media
461
+ if (text && text.trim()) {
462
+ currentParts.push({ text: text });
463
+ } else if (audio) {
464
+ // Fix: Explicit instruction for audio, placed before audio data if possible
465
+ currentParts.push({ text: "用户发送了语音消息,请听录音并回答。" });
466
+ } else {
467
+ // Fallback
468
+ currentParts.push({ text: "." });
469
+ }
470
+
471
+ // 2. Media (Images/Audio)
472
+ // Add Images
473
  if (images && Array.isArray(images)) {
474
  images.forEach(base64 => {
475
  if (base64) {
 
483
  });
484
  }
485
 
486
+ // Add Audio
487
  if (audio) {
488
  currentParts.push({
489
  inlineData: {
 
493
  });
494
  }
495
 
 
 
 
 
 
 
 
 
 
 
 
496
  // Prepare Response Stream
497
  res.setHeader('Content-Type', 'text/event-stream');
498
  res.setHeader('Cache-Control', 'no-cache');