mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-06 12:45:00 +00:00
Tell Sonnet to make concise SEARCH/REPLACE blocks #705
This commit is contained in:
parent
b44c24678c
commit
7be08c782c
2 changed files with 38 additions and 19 deletions
|
@ -1,8 +1,12 @@
|
||||||
|
import difflib
|
||||||
import math
|
import math
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
from difflib import SequenceMatcher
|
from difflib import SequenceMatcher
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from aider import utils
|
||||||
|
|
||||||
from ..dump import dump # noqa: F401
|
from ..dump import dump # noqa: F401
|
||||||
from .base_coder import Coder
|
from .base_coder import Coder
|
||||||
from .editblock_prompts import EditBlockPrompts
|
from .editblock_prompts import EditBlockPrompts
|
||||||
|
@ -481,24 +485,6 @@ def find_filename(lines, fence):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
edit = """
|
|
||||||
Here's the change:
|
|
||||||
|
|
||||||
```text
|
|
||||||
foo.txt
|
|
||||||
<<<<<<< HEAD
|
|
||||||
Two
|
|
||||||
=======
|
|
||||||
Tooooo
|
|
||||||
>>>>>>> updated
|
|
||||||
```
|
|
||||||
|
|
||||||
Hope you like it!
|
|
||||||
"""
|
|
||||||
print(list(find_original_update_blocks(edit)))
|
|
||||||
|
|
||||||
|
|
||||||
def find_similar_lines(search_lines, content_lines, threshold=0.6):
|
def find_similar_lines(search_lines, content_lines, threshold=0.6):
|
||||||
search_lines = search_lines.splitlines()
|
search_lines = search_lines.splitlines()
|
||||||
content_lines = content_lines.splitlines()
|
content_lines = content_lines.splitlines()
|
||||||
|
@ -526,3 +512,32 @@ def find_similar_lines(search_lines, content_lines, threshold=0.6):
|
||||||
|
|
||||||
best = content_lines[best_match_i:best_match_end]
|
best = content_lines[best_match_i:best_match_end]
|
||||||
return "\n".join(best)
|
return "\n".join(best)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
history_md = Path(sys.argv[1]).read_text()
|
||||||
|
if not history_md:
|
||||||
|
return
|
||||||
|
|
||||||
|
messages = utils.split_chat_history_markdown(history_md)
|
||||||
|
|
||||||
|
for msg in messages:
|
||||||
|
msg = msg["content"]
|
||||||
|
edits = list(find_original_update_blocks(msg))
|
||||||
|
|
||||||
|
for fname, before, after in edits:
|
||||||
|
# Compute diff
|
||||||
|
diff = difflib.unified_diff(
|
||||||
|
before.splitlines(keepends=True),
|
||||||
|
after.splitlines(keepends=True),
|
||||||
|
fromfile="before",
|
||||||
|
tofile="after",
|
||||||
|
)
|
||||||
|
diff = "".join(diff)
|
||||||
|
dump(before)
|
||||||
|
dump(after)
|
||||||
|
dump(diff)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
@ -124,8 +124,12 @@ Every *SEARCH/REPLACE block* must use this format:
|
||||||
|
|
||||||
Every *SEARCH* section must *EXACTLY MATCH* the existing source code, character for character, including all comments, docstrings, etc.
|
Every *SEARCH* section must *EXACTLY MATCH* the existing source code, character for character, including all comments, docstrings, etc.
|
||||||
|
|
||||||
|
|
||||||
*SEARCH/REPLACE* blocks will replace *all* matching occurrences.
|
*SEARCH/REPLACE* blocks will replace *all* matching occurrences.
|
||||||
Include enough lines to make the SEARCH blocks unique.
|
Include enough lines to make the SEARCH blocks uniquely match the lines to change.
|
||||||
|
|
||||||
|
Keep *SEARCH/REPLACE* blocks concise.
|
||||||
|
Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
||||||
|
|
||||||
Include *ALL* the code being searched and replaced!
|
Include *ALL* the code being searched and replaced!
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue