Spaces:
Running
Running
Commit ·
f931480
1
Parent(s): 03314f6
error fixed
Browse files- inference.py +24 -13
inference.py
CHANGED
|
@@ -64,29 +64,40 @@ RESPONSE FORMAT — strictly JSON only, no markdown:
|
|
| 64 |
RULES:
|
| 65 |
- Return COMPLETE function with all imports (e.g. from collections import deque)
|
| 66 |
- fixed_code must be valid Python
|
| 67 |
-
- For hard tasks explanation MUST mention the algorithmic concept
|
| 68 |
-
|
| 69 |
-
COMMON
|
| 70 |
-
-
|
| 71 |
-
-
|
| 72 |
-
-
|
|
|
|
|
|
|
| 73 |
- Off-by-one: lst[2] should be lst[1] for second element
|
| 74 |
-
- Wrong operator:
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
- For TimeoutError: you have an infinite loop, add a visited set
|
| 80 |
"""
|
| 81 |
|
| 82 |
def call_llm(buggy_code, instructions, difficulty, feedback=None, attempt=1, prev_code=None):
|
| 83 |
content = f"Difficulty: {difficulty}\nInstructions: {instructions}\n\nBuggy code:\n```python\n{buggy_code}\n```\n"
|
| 84 |
|
| 85 |
if feedback and attempt > 1:
|
| 86 |
-
content += f"\nPREVIOUS FIX FAILED. Feedback:\n{feedback}\n\nYour previous code:\n```python\n{prev_code or ''}\n```\
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
|
| 88 |
if difficulty == "hard":
|
| 89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
try:
|
| 92 |
resp = client.chat.completions.create(
|
|
|
|
| 64 |
RULES:
|
| 65 |
- Return COMPLETE function with all imports (e.g. from collections import deque)
|
| 66 |
- fixed_code must be valid Python
|
| 67 |
+
- For hard tasks explanation MUST mention the algorithmic concept listed in instructions
|
| 68 |
+
|
| 69 |
+
COMMON BUG PATTERNS:
|
| 70 |
+
- List rotation RIGHT by k: correct is lst[-k:] + lst[:-k] NOT lst[k:] + lst[:k]
|
| 71 |
+
- List rotation LEFT by k: correct is lst[k:] + lst[:k]
|
| 72 |
+
- Graph/BFS missing visited set → infinite loop → add visited=set()
|
| 73 |
+
- 0/1 Knapsack: must iterate BACKWARD: range(capacity, weight-1, -1) not forward
|
| 74 |
+
- Binary search wrong boundary: return high not low, or high=n//2
|
| 75 |
- Off-by-one: lst[2] should be lst[1] for second element
|
| 76 |
+
- Wrong operator: complement = target - n NOT target + n
|
| 77 |
|
| 78 |
+
FOR HARD TASKS — explanation MUST include words from the instructions hint.
|
| 79 |
+
Example: if instructions say "mention: iteration order" then write about iteration order.
|
| 80 |
+
Example: if instructions say "mention: visited" then write about visited set.
|
|
|
|
| 81 |
"""
|
| 82 |
|
| 83 |
def call_llm(buggy_code, instructions, difficulty, feedback=None, attempt=1, prev_code=None):
|
| 84 |
content = f"Difficulty: {difficulty}\nInstructions: {instructions}\n\nBuggy code:\n```python\n{buggy_code}\n```\n"
|
| 85 |
|
| 86 |
if feedback and attempt > 1:
|
| 87 |
+
content += f"\nPREVIOUS FIX FAILED. Feedback:\n{feedback}\n\nYour previous code:\n```python\n{prev_code or ''}\n```\n"
|
| 88 |
+
content += "IMPORTANT: Your fix did not work. Look at the Expected vs Got values carefully.\n"
|
| 89 |
+
content += "- If Got is a LEFT rotation but Expected is RIGHT: use lst[-k:] + lst[:-k]\n"
|
| 90 |
+
content += "- If you see TimeoutError: add visited=set() for graph traversal\n"
|
| 91 |
+
content += "- Try a COMPLETELY DIFFERENT approach.\n"
|
| 92 |
|
| 93 |
if difficulty == "hard":
|
| 94 |
+
# Extract keyword hints from instructions (e.g. "mention: visited, queue")
|
| 95 |
+
import re
|
| 96 |
+
hint_match = re.search(r'[Mm]ention[:\s]+([^.]+)', instructions)
|
| 97 |
+
if hint_match:
|
| 98 |
+
hints = hint_match.group(1).strip()
|
| 99 |
+
content += f"\nFor your explanation, you MUST mention these concepts: {hints}\n"
|
| 100 |
+
content += "Include a detailed explanation field — it counts for 30% of your reward.\n"
|
| 101 |
|
| 102 |
try:
|
| 103 |
resp = client.chat.completions.create(
|