victor HF Staff commited on
Commit
cd8869a
·
1 Parent(s): 9432484

chore: Add console logs for debugging AI request flow

Browse files
Files changed (1) hide show
  1. server.js +9 -1
server.js CHANGED
@@ -372,6 +372,7 @@ app.post("/api/ask-ai", async (req, res) => {
372
  }
373
 
374
  const isFollowUp = !!html && !!previousPrompt; // Check if it's a follow-up request
 
375
 
376
  const { hf_token } = req.cookies;
377
  let token = hf_token;
@@ -444,10 +445,14 @@ ${REPLACE_END}
444
  ONLY output the changes in this format. Do NOT output the full HTML file again.`;
445
 
446
  // --- Prepare Messages for AI ---
 
 
 
 
447
  const messages = [
448
  {
449
  role: "system",
450
- content: isFollowUp ? followUpSystemPrompt : initialSystemPrompt,
451
  },
452
  // Include previous context if available
453
  ...(previousPrompt ? [{ role: "user", content: previousPrompt }] : []),
@@ -500,11 +505,14 @@ ONLY output the changes in this format. Do NOT output the full HTML file again.`
500
 
501
 
502
  // Apply the diffs
 
503
  const modifiedHtml = applyDiffs(html, completeResponse);
 
504
  res.status(200).type('text/html').send(modifiedHtml); // Send the fully modified HTML
505
 
506
  } else {
507
  // **Stream response directly (Initial Request)**
 
508
  res.setHeader("Content-Type", "text/html"); // Send as HTML
509
  res.setHeader("Cache-Control", "no-cache");
510
  res.setHeader("Connection", "keep-alive");
 
372
  }
373
 
374
  const isFollowUp = !!html && !!previousPrompt; // Check if it's a follow-up request
375
+ console.log(`[AI Request] Type: ${isFollowUp ? 'Follow-up' : 'Initial'}`);
376
 
377
  const { hf_token } = req.cookies;
378
  let token = hf_token;
 
445
  ONLY output the changes in this format. Do NOT output the full HTML file again.`;
446
 
447
  // --- Prepare Messages for AI ---
448
+ const systemPromptContent = isFollowUp ? followUpSystemPrompt : initialSystemPrompt;
449
+ console.log(`[AI Request] Using system prompt: ${isFollowUp ? 'Follow-up (Diff)' : 'Initial (Full HTML)'}`);
450
+ // console.log("[AI Request] System Prompt Content:\n", systemPromptContent); // Uncomment for full prompt text
451
+
452
  const messages = [
453
  {
454
  role: "system",
455
+ content: systemPromptContent,
456
  },
457
  // Include previous context if available
458
  ...(previousPrompt ? [{ role: "user", content: previousPrompt }] : []),
 
505
 
506
 
507
  // Apply the diffs
508
+ console.log("[Diff Apply] Attempting to apply diffs...");
509
  const modifiedHtml = applyDiffs(html, completeResponse);
510
+ console.log("[Diff Apply] Diffs applied successfully.");
511
  res.status(200).type('text/html').send(modifiedHtml); // Send the fully modified HTML
512
 
513
  } else {
514
  // **Stream response directly (Initial Request)**
515
+ console.log("[AI Request] Starting direct stream for initial request.");
516
  res.setHeader("Content-Type", "text/html"); // Send as HTML
517
  res.setHeader("Cache-Control", "no-cache");
518
  res.setHeader("Connection", "keep-alive");