More flexible filename search for deepseek coder v2

This commit is contained in:
Paul Gauthier 2024-06-21 08:29:02 -07:00
parent 93e104f79f
commit 4fd61f1112
3 changed files with 67 additions and 12 deletions

View file

@ -414,16 +414,8 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE):
processed.append(cur) # original_marker
filename = strip_filename(processed[-2].splitlines()[-1], fence)
try:
if not filename:
filename = strip_filename(processed[-2].splitlines()[-2], fence)
if not filename:
if current_filename:
filename = current_filename
else:
raise ValueError(missing_filename_err.format(fence=fence))
except IndexError:
filename = find_filename(processed[-2].splitlines(), fence)
if not filename:
if current_filename:
filename = current_filename
else:
@ -460,6 +452,35 @@ def find_original_update_blocks(content, fence=DEFAULT_FENCE):
raise ValueError(f"{processed}\n^^^ Error parsing SEARCH/REPLACE block.")
def find_filename(lines, fence):
"""
Deepseek Coder v2 has been doing this:
```python
word_count.py
```
```python
<<<<<<< SEARCH
...
This is a more flexible search back for filenames.
"""
# Go back through the 3 preceding lines
lines.reverse()
lines = lines[:3]
for line in lines:
# If we find a filename, done
filename = strip_filename(line, fence)
if filename:
return filename
# Only continue as long as we keep seeing fences
if not line.startswith(fence[0]):
return
if __name__ == "__main__":
edit = """
Here's the change:

View file

@ -236,7 +236,7 @@ MODEL_SETTINGS = [
send_undo_reply=True,
),
ModelSettings(
"openai/deepseek-chat",
"deepseek/deepseek-chat",
"diff",
use_repo_map=True,
send_undo_reply=True,
@ -244,7 +244,15 @@ MODEL_SETTINGS = [
reminder_as_sys_msg=True,
),
ModelSettings(
"deepseek/deepseek-chat",
"deepseek/deepseek-coder",
"diff",
use_repo_map=True,
send_undo_reply=True,
examples_as_sys_msg=True,
reminder_as_sys_msg=True,
),
ModelSettings(
"openrouter/deepseek/deepseek-coder",
"diff",
use_repo_map=True,
send_undo_reply=True,

View file

@ -398,6 +398,32 @@ Hope you like it!
],
)
def test_deepseek_coder_v2_filename_mangling(self):
edit = """
Here's the change:
```python
foo.txt
```
```python
<<<<<<< SEARCH
one
=======
two
>>>>>>> REPLACE
```
Hope you like it!
"""
edits = list(eb.find_original_update_blocks(edit))
self.assertEqual(
edits,
[
("foo.txt", "one\n", "two\n"),
],
)
if __name__ == "__main__":
unittest.main()