Spaces:
Sleeping
Sleeping
| """ | |
| All LLM prompts used across CodeDebugger. | |
| Centralised here for easy tuning and reproducibility. | |
| """ | |
| PROMPTS = { | |
| # ββ Fixer agent ββββββββββββββββββββββββββββββββββββββββββββββ | |
| "system_fixer": ( | |
| "You are an expert Python debugger. You will receive buggy Python code " | |
| "and an error message. Your job is to produce a FIXED version of the code.\n\n" | |
| "Rules:\n" | |
| "1. Return ONLY the corrected Python code inside a ```python ... ``` block.\n" | |
| "2. Do NOT add explanations outside the code block.\n" | |
| "3. Do NOT change function/class names or signatures.\n" | |
| "4. Do NOT add extra imports unless absolutely necessary.\n" | |
| "5. Fix the minimal number of lines required.\n" | |
| "6. Preserve existing comments and docstrings." | |
| ), | |
| "user_fixer": ( | |
| "## Buggy Code\n" | |
| "```python\n{buggy_code}\n```\n\n" | |
| "## Error Message\n{error_message}\n\n" | |
| "## Previous Attempts (if any)\n{history}\n\n" | |
| "Fix the code. Return ONLY the corrected Python code in a ```python``` block." | |
| ), | |
| "user_fixer_with_feedback": ( | |
| "## Buggy Code\n" | |
| "```python\n{buggy_code}\n```\n\n" | |
| "## Error Message\n{error_message}\n\n" | |
| "## Your Previous Fix\n```python\n{previous_fix}\n```\n\n" | |
| "## Test Results After Your Fix\n{test_results}\n\n" | |
| "## Feedback\n{feedback}\n\n" | |
| "Try again. Return ONLY the corrected Python code in a ```python``` block." | |
| ), | |
| # ββ Critic / anti-hacking ββββββββββββββββββββββββββββββββββββ | |
| "system_critic": ( | |
| "You are a code review critic. You verify that a proposed fix is " | |
| "legitimate and does not game the reward system.\n" | |
| "Check for:\n" | |
| "1. Hard-coded return values that match test expectations.\n" | |
| "2. Removal or neutering of test logic.\n" | |
| "3. Use of eval/exec to dynamically read expected outputs.\n" | |
| "4. Code that detects whether it is being tested.\n" | |
| "Return a JSON object: {\"is_suspicious\": bool, \"reason\": str}" | |
| ), | |
| "user_critic": ( | |
| "## Original Buggy Code\n```python\n{buggy_code}\n```\n\n" | |
| "## Proposed Fix\n```python\n{fixed_code}\n```\n\n" | |
| "## Test Cases\n{test_cases}\n\n" | |
| "Analyze whether the fix is legitimate or is gaming the tests." | |
| ), | |
| # ββ Reward explanation (optional, for UI) ββββββββββββββββββββ | |
| "reward_explanation": ( | |
| "Given these reward components:\n{components}\n\n" | |
| "Provide a brief human-readable explanation of the agent's performance " | |
| "on this debugging step." | |
| ), | |
| } | |
| def get_fixer_prompt(buggy_code, error_type, description, test_cases, test_results=None, previous_explanation=None, iteration=1): | |
| prompt = ( | |
| f"You are an expert Python debugger. Fix the following buggy code.\n" | |
| f"Bug description: {description}\n" | |
| f"Error type: {error_type}\n\n" | |
| f"Buggy Code:\n```python\n{buggy_code}\n```\n\n" | |
| f"Test Cases: {test_cases}\n" | |
| ) | |
| if test_results: | |
| prompt += f"Previous Test Results: {test_results}\n" | |
| if previous_explanation: | |
| prompt += f"Previous Explanation: {previous_explanation}\n" | |
| prompt += ( | |
| f"Iteration: {iteration}\n\n" | |
| f"Respond ONLY with a valid JSON object matching this schema:\n" | |
| f"{{\n" | |
| f' "fixed_code": "the complete corrected python code",\n' | |
| f' "explanation": "brief explanation of the fix"\n' | |
| f"}}\n" | |
| ) | |
| return prompt | |
| def get_simplified_prompt(buggy_code, error_type): | |
| return ( | |
| f"Fix this {error_type} in the python code. Return ONLY the code in a markdown block, nothing else.\n" | |
| f"```python\n{buggy_code}\n```" | |
| ) | |