Skip to content

Commit

Permalink
Merge pull request #930 from ATheorell/fix#928
Browse files Browse the repository at this point in the history
potential fix for some/dir/ bug #928
  • Loading branch information
ATheorell committed Jan 5, 2024
2 parents c6dd523 + 02fd2cf commit 561b48c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
10 changes: 6 additions & 4 deletions gpt_engineer/preprompts/improve
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Take requests for changes to the supplied code, and then you MUST

You MUST format EVERY code change with an *edit block* like this:
```python
some/dir/example.py
example.py
<<<<<<< HEAD
# some comment
# Func to multiply
Expand All @@ -29,7 +29,7 @@ Also, in the class `DB`, we need to update the "SOMETHING"

OUTPUT:
```python
some/dir/example_1.py
example_1.py
<<<<<<< HEAD
def mul(a,b)
=======
Expand All @@ -38,7 +38,7 @@ some/dir/example_1.py
```

```python
some/dir/example_1.py
example_1.py
<<<<<<< HEAD
def add_one(a,b):
a = a+2
Expand All @@ -49,7 +49,7 @@ some/dir/example_1.py
```

```python
some/dir/example_2.py
example_1.py
<<<<<<< HEAD
class DBS:
db = 'aaa'
Expand All @@ -65,6 +65,8 @@ So edit blocks must be precise and unambiguous!

Every *edit block* must be fenced with ```CONTENT OF EDIT BLOCK``` with the correct code language.

The file name at the top of the edit block (example_1.py in the examples) is the relative path to the file.

The `HEAD` section must be an *exact set of sequential lines* from the file! This is very important. Otherwise the parser won't work.
NEVER SKIP LINES in the `HEAD` section!
NEVER ELIDE LINES AND REPLACE THEM WITH A COMMENT!
Expand Down
2 changes: 1 addition & 1 deletion tests/ai_cache.json

Large diffs are not rendered by default.

11 changes: 9 additions & 2 deletions tests/core/test_chat_to_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,19 @@ class DBS:
assert parsed == expected


def test_apply_overwrite_existing_file(log_capture):
edits = [Edit("existing_file.py", "", "print('Hello, World!')")]
code = {"existing_file.py": "some content"}
apply_edits(edits, code)
assert code == {"existing_file.py": "print('Hello, World!')"}
assert "file will be overwritten" in log_capture.messages[0]


def test_apply_edit_new_file(log_capture):
edits = [Edit("new_file.py", "", "print('Hello, World!')")]
code = {"new_file.py": "some content"}
code = {}
apply_edits(edits, code)
assert code == {"new_file.py": "print('Hello, World!')"}
assert "file will be overwritten" in log_capture.messages[0]


def test_apply_edit_no_match(log_capture):
Expand Down

0 comments on commit 561b48c

Please sign in to comment.