Spaces:
Sleeping
Sleeping
databoysu commited on
Commit ·
807adf9
1
Parent(s): 3313317
improve tooling and whitespace error handling
Browse files- __pycache__/environment.cpython-312.pyc +0 -0
- __pycache__/models.cpython-312.pyc +0 -0
- environment.py +30 -1
- models.py +1 -2
__pycache__/environment.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/environment.cpython-312.pyc and b/__pycache__/environment.cpython-312.pyc differ
|
|
|
__pycache__/models.cpython-312.pyc
CHANGED
|
Binary files a/__pycache__/models.cpython-312.pyc and b/__pycache__/models.cpython-312.pyc differ
|
|
|
environment.py
CHANGED
|
@@ -3,6 +3,7 @@
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import random
|
|
|
|
| 6 |
import uuid
|
| 7 |
from typing import Any, Dict, List, Optional, Tuple
|
| 8 |
|
|
@@ -406,7 +407,12 @@ class TraceFixRLGym:
|
|
| 406 |
|
| 407 |
self._edit_history.append(list(self._code_lines))
|
| 408 |
|
| 409 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
self._code_lines[start_idx:end_idx] = new_lines
|
| 411 |
|
| 412 |
new_end = start_line + len(new_lines) - 1
|
|
@@ -422,6 +428,29 @@ class TraceFixRLGym:
|
|
| 422 |
)
|
| 423 |
return 0.0
|
| 424 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
def _act_submit(self) -> float:
|
| 426 |
output, results, syntax_err = run_code_with_tests(
|
| 427 |
source=self._source(),
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import random
|
| 6 |
+
import re
|
| 7 |
import uuid
|
| 8 |
from typing import Any, Dict, List, Optional, Tuple
|
| 9 |
|
|
|
|
| 407 |
|
| 408 |
self._edit_history.append(list(self._code_lines))
|
| 409 |
|
| 410 |
+
original_line = self._code_lines[start_line - 1]
|
| 411 |
+
original_indent = re.match(r"[ \t]*", original_line).group(0)
|
| 412 |
+
new_lines = self._auto_indent_replacement_block(
|
| 413 |
+
new_code_block=new_code_block,
|
| 414 |
+
original_indent=original_indent,
|
| 415 |
+
)
|
| 416 |
self._code_lines[start_idx:end_idx] = new_lines
|
| 417 |
|
| 418 |
new_end = start_line + len(new_lines) - 1
|
|
|
|
| 428 |
)
|
| 429 |
return 0.0
|
| 430 |
|
| 431 |
+
def _auto_indent_replacement_block(
|
| 432 |
+
self, new_code_block: str, original_indent: str
|
| 433 |
+
) -> List[str]:
|
| 434 |
+
lines = new_code_block.split("\n")
|
| 435 |
+
if not lines:
|
| 436 |
+
return []
|
| 437 |
+
|
| 438 |
+
first_indent_match = re.match(r"[ \t]*", lines[0])
|
| 439 |
+
first_indent_len = len(first_indent_match.group(0)) if first_indent_match else 0
|
| 440 |
+
|
| 441 |
+
adjusted_lines: List[str] = []
|
| 442 |
+
for line in lines:
|
| 443 |
+
leading_match = re.match(r"[ \t]*", line)
|
| 444 |
+
leading_whitespace = leading_match.group(0) if leading_match else ""
|
| 445 |
+
content = line[len(leading_whitespace):]
|
| 446 |
+
if first_indent_len > 0:
|
| 447 |
+
relative_whitespace = leading_whitespace[first_indent_len:]
|
| 448 |
+
else:
|
| 449 |
+
relative_whitespace = leading_whitespace
|
| 450 |
+
adjusted_lines.append(f"{original_indent}{relative_whitespace}{content}")
|
| 451 |
+
|
| 452 |
+
return adjusted_lines
|
| 453 |
+
|
| 454 |
def _act_submit(self) -> float:
|
| 455 |
output, results, syntax_err = run_code_with_tests(
|
| 456 |
source=self._source(),
|
models.py
CHANGED
|
@@ -59,8 +59,7 @@ class CodeAction(Action):
|
|
| 59 |
new_code_block: Optional[str] = Field(
|
| 60 |
default=None,
|
| 61 |
description=(
|
| 62 |
-
"The exact replacement Python code.
|
| 63 |
-
"surrounding code. Do not include markdown formatting or backticks."
|
| 64 |
),
|
| 65 |
)
|
| 66 |
|
|
|
|
| 59 |
new_code_block: Optional[str] = Field(
|
| 60 |
default=None,
|
| 61 |
description=(
|
| 62 |
+
"The exact replacement Python code. CRITICAL: DO NOT add leading spaces or indentation. Write the code completely flush to the left margin. The environment will automatically calculate and apply the correct indentation based on the start_line."
|
|
|
|
| 63 |
),
|
| 64 |
)
|
| 65 |
|