Spaces:
Sleeping
Sleeping
databoysu commited on
Commit ·
807adf9
1
Parent(s): 3313317
improve tooling and whitespace error handling
Browse filesFiles changed (4)
2 unmodified lines345678397 unmodified lines4064074084094104114129 unmodified lines4224234244254264272 unmodified linesfrom __future__ import annotationsimport randomimport uuidfrom typing import Any, Dict, List, Optional, Tuple397 unmodified linesself._edit_history.append(list(self._code_lines))new_lines = new_code_block.split("\n")self._code_lines[start_idx:end_idx] = new_linesnew_end = start_line + len(new_lines) - 19 unmodified lines)return 0.0def _act_submit(self) -> float:output, results, syntax_err = run_code_with_tests(source=self._source(),2 unmodified lines3456789397 unmodified lines4074084094104114124134144154164174189 unmodified lines4284294304314324334344354364374384394404414424434444454464474484494504514524534544554562 unmodified linesfrom __future__ import annotationsimport randomimport reimport uuidfrom typing import Any, Dict, List, Optional, Tuple397 unmodified linesself._edit_history.append(list(self._code_lines))original_line = self._code_lines[start_line - 1]original_indent = re.match(r"[ \t]*", original_line).group(0)new_lines = self._auto_indent_replacement_block(new_code_block=new_code_block,original_indent=original_indent,)self._code_lines[start_idx:end_idx] = new_linesnew_end = start_line + len(new_lines) - 19 unmodified lines)return 0.0def _auto_indent_replacement_block(self, new_code_block: str, original_indent: str) -> List[str]:lines = new_code_block.split("\n")if not lines:return []first_indent_match = re.match(r"[ \t]*", lines[0])first_indent_len = len(first_indent_match.group(0)) if first_indent_match else 0adjusted_lines: List[str] = []for line in lines:leading_match = re.match(r"[ \t]*", line)leading_whitespace = leading_match.group(0) if leading_match else ""content = line[len(leading_whitespace):]if first_indent_len > 0:relative_whitespace = leading_whitespace[first_indent_len:]else:relative_whitespace = leading_whitespaceadjusted_lines.append(f"{original_indent}{relative_whitespace}{content}")return adjusted_linesdef _act_submit(self) -> float:output, results, syntax_err = run_code_with_tests(source=self._source(),
58 unmodified lines596061626364656658 unmodified linesnew_code_block: Optional[str] = Field(default=None,description=("The exact replacement Python code. Must be properly indented to match the ""surrounding code. Do not include markdown formatting or backticks."),)58 unmodified lines5960616263646558 unmodified linesnew_code_block: Optional[str] = Field(default=None,description=("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."),)
__pycache__/environment.cpython-312.pyc
__pycache__/models.cpython-312.pyc
environment.py+30-1
models.py+1-2