fixed prompt build
Browse files293 unmodified lines2942952962972982993003013023033043053063 unmodified lines3103113123133143153161 unmodified line3183193203213223233243253263271 unmodified line329330331332333334335336337293 unmodified lines# 4. Default to casual chat if no coding intent is detectedreturn "discuss"def build_full_prompt(project: str, user_text: str) -> Tuple[str, str]:hist = load_recent(project, limit=8)hist_lines = [f"{m['role'].upper()}: {m['content']}" for m in hist]files_context = load_project_files_context(project)mode = parse_user_mode(user_text)# Logic: Only enforce strict "Multi-file" rules for coding modesif mode in ["write", "review"]:planning_instructions = f"""IMPORTANT:3 unmodified lines- End with a 'Self-Check'."""else:# For 'explain' or 'discuss', we want a natural conversationplanning_instructions = f"""IMPORTANT:- Start with '#mode: {mode}'.1 unmodified line- Do NOT use the Multi-file format unless specifically asked for code."""sections = [SYSTEM_PROMPT.strip(),"\n--- Session Settings ---\n",f"Model: {MODEL}\nTemperature: {TEMPERATURE}\n","\n--- Project Context ---\n",files_context,"\n--- Conversation ---\n",1 unmodified line"\n--- New Request ---\n",f"USER: {user_text}\n{planning_instructions}\nASSISTANT:"]prompt = "\n".join(s for s in sections if s is not None)if len(prompt) > MAX_PROMPT_CHARS:prompt = prompt[-MAX_PROMPT_CHARS:]return prompt, mode# -------------- Routes --------------293 unmodified lines2942952962972982993003013023033043053063073083093103113 unmodified lines3153163173183193201 unmodified line3223233243253263273283293303313323331 unmodified line335336337338339340341342343344345346293 unmodified lines# 4. Default to casual chat if no coding intent is detectedreturn "discuss"def build_full_prompt(project: str, user_text: str, search_results: List[str] = None) -> Tuple[str, str]:hist = load_recent(project, limit=8)hist_lines = [f"{m['role'].upper()}: {m['content']}" for m in hist]files_context = load_project_files_context(project)mode = parse_user_mode(user_text)# 1. Define the search context blocksearch_context = ""if search_results:search_context = "\n--- Web Search Results ---\n" + "\n".join(search_results)# 2. Logic for mode-specific instructionsif mode in ["write", "review"]:planning_instructions = f"""IMPORTANT:3 unmodified lines- End with a 'Self-Check'."""else:planning_instructions = f"""IMPORTANT:- Start with '#mode: {mode}'.1 unmodified line- Do NOT use the Multi-file format unless specifically asked for code."""# 3. Assemble the prompt (added search_context to the list)sections = [SYSTEM_PROMPT.strip(),"\n--- Session Settings ---\n",f"Model: {MODEL}\nTemperature: {TEMPERATURE}\n",search_context, # <--- CRITICAL FIX: This was missing from your sections list"\n--- Project Context ---\n",files_context,"\n--- Conversation ---\n",1 unmodified line"\n--- New Request ---\n",f"USER: {user_text}\n{planning_instructions}\nASSISTANT:"]# 4. Join and enforce character budgetprompt = "\n".join(s for s in sections if s and s.strip())if len(prompt) > MAX_PROMPT_CHARS:prompt = prompt[-MAX_PROMPT_CHARS:]return prompt, mode# -------------- Routes --------------
backend/app.py+13-4