Fafnirk commited on
Commit
a29613f
·
1 Parent(s): 933dfec

fixed prompt build

Browse files
Files changed (1) hide show
  1. backend/app.py +13 -4
backend/app.py CHANGED
@@ -294,13 +294,18 @@ def parse_user_mode(text: str) -> str:
294
  # 4. Default to casual chat if no coding intent is detected
295
  return "discuss"
296
 
297
- def build_full_prompt(project: str, user_text: str) -> Tuple[str, str]:
298
  hist = load_recent(project, limit=8)
299
  hist_lines = [f"{m['role'].upper()}: {m['content']}" for m in hist]
300
  files_context = load_project_files_context(project)
301
  mode = parse_user_mode(user_text)
302
 
303
- # Logic: Only enforce strict "Multi-file" rules for coding modes
 
 
 
 
 
304
  if mode in ["write", "review"]:
305
  planning_instructions = f"""
306
  IMPORTANT:
@@ -310,7 +315,6 @@ IMPORTANT:
310
  - End with a 'Self-Check'.
311
  """
312
  else:
313
- # For 'explain' or 'discuss', we want a natural conversation
314
  planning_instructions = f"""
315
  IMPORTANT:
316
  - Start with '#mode: {mode}'.
@@ -318,10 +322,12 @@ IMPORTANT:
318
  - Do NOT use the Multi-file format unless specifically asked for code.
319
  """
320
 
 
321
  sections = [
322
  SYSTEM_PROMPT.strip(),
323
  "\n--- Session Settings ---\n",
324
  f"Model: {MODEL}\nTemperature: {TEMPERATURE}\n",
 
325
  "\n--- Project Context ---\n",
326
  files_context,
327
  "\n--- Conversation ---\n",
@@ -329,9 +335,12 @@ IMPORTANT:
329
  "\n--- New Request ---\n",
330
  f"USER: {user_text}\n{planning_instructions}\nASSISTANT:"
331
  ]
332
- prompt = "\n".join(s for s in sections if s is not None)
 
 
333
  if len(prompt) > MAX_PROMPT_CHARS:
334
  prompt = prompt[-MAX_PROMPT_CHARS:]
 
335
  return prompt, mode
336
 
337
  # -------------- Routes --------------
 
294
  # 4. Default to casual chat if no coding intent is detected
295
  return "discuss"
296
 
297
+ def build_full_prompt(project: str, user_text: str, search_results: List[str] = None) -> Tuple[str, str]:
298
  hist = load_recent(project, limit=8)
299
  hist_lines = [f"{m['role'].upper()}: {m['content']}" for m in hist]
300
  files_context = load_project_files_context(project)
301
  mode = parse_user_mode(user_text)
302
 
303
+ # 1. Define the search context block
304
+ search_context = ""
305
+ if search_results:
306
+ search_context = "\n--- Web Search Results ---\n" + "\n".join(search_results)
307
+
308
+ # 2. Logic for mode-specific instructions
309
  if mode in ["write", "review"]:
310
  planning_instructions = f"""
311
  IMPORTANT:
 
315
  - End with a 'Self-Check'.
316
  """
317
  else:
 
318
  planning_instructions = f"""
319
  IMPORTANT:
320
  - Start with '#mode: {mode}'.
 
322
  - Do NOT use the Multi-file format unless specifically asked for code.
323
  """
324
 
325
+ # 3. Assemble the prompt (added search_context to the list)
326
  sections = [
327
  SYSTEM_PROMPT.strip(),
328
  "\n--- Session Settings ---\n",
329
  f"Model: {MODEL}\nTemperature: {TEMPERATURE}\n",
330
+ search_context, # <--- CRITICAL FIX: This was missing from your sections list
331
  "\n--- Project Context ---\n",
332
  files_context,
333
  "\n--- Conversation ---\n",
 
335
  "\n--- New Request ---\n",
336
  f"USER: {user_text}\n{planning_instructions}\nASSISTANT:"
337
  ]
338
+
339
+ # 4. Join and enforce character budget
340
+ prompt = "\n".join(s for s in sections if s and s.strip())
341
  if len(prompt) > MAX_PROMPT_CHARS:
342
  prompt = prompt[-MAX_PROMPT_CHARS:]
343
+
344
  return prompt, mode
345
 
346
  # -------------- Routes --------------