Ask GPT to retry if original block is not found

This commit is contained in:
Paul Gauthier 2023-07-19 17:24:53 -03:00
parent 691c013272
commit 4bc35a7376
3 changed files with 14 additions and 3 deletions

View file

@ -532,6 +532,7 @@ class Coder:
edited, edit_error = self.apply_updates()
if edit_error:
self.update_cur_messages(content, set())
return edit_error
# TODO: this shouldn't use content, should use self.partial_....
@ -1006,7 +1007,7 @@ class Coder:
apply_update_errors = 0
def apply_updates(self):
max_apply_update_errors = 2
max_apply_update_errors = 3
try:
edited = self.update_files()

View file

@ -32,7 +32,17 @@ class EditBlockCoder(Coder):
self.io.write_text(full_path, content)
edited.add(path)
continue
self.io.tool_error(f"Failed to apply edit to {path}")
raise ValueError(f"""InvalidEditBlock: edit failed!
{path} does not contain the *exact sequence* of ORIGINAL lines you specified.
Try again.
DO NOT skip blank lines, comments, docstrings, etc!
The ORIGINAL block needs to be EXACTLY the same as the lines in {path} with nothing missing!
{path} does not contain these {len(original.splitlines())} exact lines in a row:
```
{original}```
""")
return edited

View file

@ -33,7 +33,7 @@ some/dir/example.py
Every *edit block* must be fenced with {fence[0]}...{fence[1]} with the correct code language.
Every *edit block* must start with the full path! *NEVER* propose edit blocks for *read-only* files.
The ORIGINAL section must be an *exact* set of lines from the file:
The ORIGINAL section must be an *exact set of sequential lines* from the file:
- NEVER SKIP LINES!
- Include all original leading spaces and indentation!