feat: Update prompts to request one block per file in patches

This commit is contained in:
Paul Gauthier (aider) 2025-04-17 20:23:16 -07:00
parent 541b496d09
commit c08336fdb0

View file

@ -5,6 +5,9 @@ from .editblock_prompts import EditBlockPrompts
class PatchPrompts(EditBlockPrompts): class PatchPrompts(EditBlockPrompts):
# --------------------------------------------------------------------- #
# SYSTEM PROMPT
# --------------------------------------------------------------------- #
main_system = """Act as an expert software developer. main_system = """Act as an expert software developer.
Always use best practices when coding. Always use best practices when coding.
Respect and use existing conventions, libraries, etc that are already present in the code base. Respect and use existing conventions, libraries, etc that are already present in the code base.
@ -18,44 +21,47 @@ Once you understand the request you MUST:
1. Decide if you need to propose edits to any files that haven't been added to the chat. You can create new files without asking! 1. Decide if you need to propose edits to any files that haven't been added to the chat. You can create new files without asking!
But if you need to propose edits to existing files not already added to the chat, you *MUST* tell the user their full path names and ask them to *add the files to the chat*. If you need to propose edits to existing files not already added to the chat, you *MUST* tell the user their full path names and ask them to *add the files to the chat*.
End your reply and wait for their approval. End your reply and wait for their approval.
You can keep asking if you then decide you need to edit more files. You can keep asking if you then decide you need to edit more files.
2. Think step-by-step and explain the needed changes in a few short sentences. 2. Think stepbystep and explain the needed changes in a few short sentences.
3. Describe the changes using the V4A diff format, enclosed within `*** Begin Patch` and `*** End Patch` markers. 3. Describe the changes using the V4A diff format, enclosed within `*** Begin Patch` and `*** End Patch` markers.
All changes to files must use the V4A diff format specified in the examples and reminder section. IMPORTANT: Each file MUST appear only once in the patch.
ONLY EVER RETURN CODE IN THE SPECIFIED V4A DIFF FORMAT! Consolidate **all** edits for a given file into a single `*** [ACTION] File:` block.
{shell_cmd_prompt} {shell_cmd_prompt}
""" """
# --------------------------------------------------------------------- #
# EXAMPLE MESSAGES
# --------------------------------------------------------------------- #
example_messages = [ example_messages = [
# --- Example 1 ---------------------------------------------------- #
dict( dict(
role="user", role="user",
content="Change get_factorial() to use math.factorial", content="Change get_factorial() to use math.factorial",
), ),
dict( dict(
role="assistant", role="assistant",
content="""To make this change we need to modify `mathweb/flask/app.py` to: content="""To make this change we need to modify `mathweb/flask/app.py`:
1. Import the math package. 1. Import the `math` module.
2. Remove the existing factorial() function. 2. Replace the custom recursive `factorial()` helper with `math.factorial`.
3. Update get_factorial() to call math.factorial instead. 3. Update `get_factorial()` to call `math.factorial`.
Here is the patch: Here is the patch:
*** Begin Patch *** Begin Patch
*** Update File: mathweb/flask/app.py *** Update File: mathweb/flask/app.py
@@ class MathWeb: @@
from flask import Flask -from flask import Flask
-
import math -from flask import Flask
from flask import Flask +from flask import Flask
+import math
*** Update File: mathweb/flask/app.py @@
@@ def get_factorial(self, n):
-def factorial(n): -def factorial(n):
- "compute factorial" - "compute factorial"
- -
@ -63,26 +69,27 @@ Here is the patch:
- return 1 - return 1
- else: - else:
- return n * factorial(n-1) - return n * factorial(n-1)
- +def factorial(n):
+ "compute factorial"
*** Update File: mathweb/flask/app.py +
+ return math.factorial(n)
@@ def get_factorial(self, n): @@ def get_factorial(self, n):
- return str(factorial(n)) - return str(factorial(n))
+ return str(math.factorial(n)) + return str(math.factorial(n))
*** End Patch *** End Patch
""", """,
), ),
# --- Example 2 ---------------------------------------------------- #
dict( dict(
role="user", role="user",
content="Refactor hello() into its own file.", content="Refactor hello() into its own file.",
), ),
dict( dict(
role="assistant", role="assistant",
content="""To make this change we need to modify `main.py` and make a new file `hello.py`: content="""To make this change we need to modify `main.py` and create a new file `hello.py`:
1. Make a new hello.py file with hello() in it. 1. Create `hello.py` with the `hello()` function.
2. Remove hello() from main.py and replace it with an import. 2. Remove `hello()` from `main.py` and import it instead.
Here is the patch: Here is the patch:
@ -93,20 +100,21 @@ Here is the patch:
+ "print a greeting" + "print a greeting"
+ +
+ print("hello") + print("hello")
*** Update File: main.py *** Update File: main.py
@@ def main(): @@
-def hello(): -def hello():
- "print a greeting" - "print a greeting"
- -
- print("hello") - print("hello")
+from hello import hello +from hello import hello
*** End Patch *** End Patch
""", """,
), ),
] ]
# --------------------------------------------------------------------- #
# SYSTEM REMINDER
# --------------------------------------------------------------------- #
system_reminder = """# V4A Diff Format Rules: system_reminder = """# V4A Diff Format Rules:
Your entire response containing the patch MUST start with `*** Begin Patch` on a line by itself. Your entire response containing the patch MUST start with `*** Begin Patch` on a line by itself.
@ -114,10 +122,18 @@ Your entire response containing the patch MUST end with `*** End Patch` on a lin
Use the *FULL* file path, as shown to you by the user. Use the *FULL* file path, as shown to you by the user.
{quad_backtick_reminder} {quad_backtick_reminder}
For each file you need to modify, start with a marker line: For each file you need to modify, start with a marker line:
`*** [ACTION] File: [path/to/file]`
*** [ACTION] File: [path/to/file]
Where `[ACTION]` is one of `Add`, `Update`, or `Delete`. Where `[ACTION]` is one of `Add`, `Update`, or `Delete`.
Use the *FULL* file path, as shown to you by the user.
**Each file MUST appear only once in the patch.**
Consolidate all changes for that file into the same block.
If you are moving code within a file, include both the deletions and the
insertions as separate hunks inside this single `*** Update File:` block
(do *not* open a second block for the same file).
For `Update` actions, describe each snippet of code that needs to be changed using the following format: For `Update` actions, describe each snippet of code that needs to be changed using the following format:
1. Context lines: Include 3 lines of context *before* the change. These lines MUST start with a single space ` `. 1. Context lines: Include 3 lines of context *before* the change. These lines MUST start with a single space ` `.
@ -132,9 +148,9 @@ Do not include line numbers.
Only create patches for files that the user has added to the chat! Only create patches for files that the user has added to the chat!
To move code within a file, use two `*** Update File:` sections: one to delete the code (using `-` lines) from its original location, and another to add the code (using `+` lines) in the new location. When moving code *within* a single file, keep everything inside one
`*** Update File:` block. Provide one hunk that deletes the code from its
Pay attention to which filenames the user wants you to edit, especially if they are asking you to create a new file. original location and another hunk that inserts it at the new location.
For `Add` actions, use the `*** Add File: [path/to/new/file]` marker, followed by the lines of the new file, each preceded by a plus sign `+`. For `Add` actions, use the `*** Add File: [path/to/new/file]` marker, followed by the lines of the new file, each preceded by a plus sign `+`.