mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
feat: Update prompts to request one block per file in patches
This commit is contained in:
parent
541b496d09
commit
c08336fdb0
1 changed files with 49 additions and 33 deletions
|
@ -5,6 +5,9 @@ from .editblock_prompts import EditBlockPrompts
|
|||
|
||||
|
||||
class PatchPrompts(EditBlockPrompts):
|
||||
# --------------------------------------------------------------------- #
|
||||
# SYSTEM PROMPT
|
||||
# --------------------------------------------------------------------- #
|
||||
main_system = """Act as an expert software developer.
|
||||
Always use best practices when coding.
|
||||
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!
|
||||
|
||||
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*.
|
||||
End your reply and wait for their approval.
|
||||
You can keep asking if you then decide you need to edit more files.
|
||||
• 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.
|
||||
• 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 step‑by‑step 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.
|
||||
|
||||
All changes to files must use the V4A diff format specified in the examples and reminder section.
|
||||
ONLY EVER RETURN CODE IN THE SPECIFIED V4A DIFF FORMAT!
|
||||
IMPORTANT: Each file MUST appear only once in the patch.
|
||||
Consolidate **all** edits for a given file into a single `*** [ACTION] File:` block.
|
||||
{shell_cmd_prompt}
|
||||
"""
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# EXAMPLE MESSAGES
|
||||
# --------------------------------------------------------------------- #
|
||||
example_messages = [
|
||||
# --- Example 1 ---------------------------------------------------- #
|
||||
dict(
|
||||
role="user",
|
||||
content="Change get_factorial() to use math.factorial",
|
||||
),
|
||||
dict(
|
||||
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.
|
||||
2. Remove the existing factorial() function.
|
||||
3. Update get_factorial() to call math.factorial instead.
|
||||
1. Import the `math` module.
|
||||
2. Replace the custom recursive `factorial()` helper with `math.factorial`.
|
||||
3. Update `get_factorial()` to call `math.factorial`.
|
||||
|
||||
Here is the patch:
|
||||
|
||||
*** Begin Patch
|
||||
*** Update File: mathweb/flask/app.py
|
||||
@@ class MathWeb:
|
||||
from flask import Flask
|
||||
|
||||
import math
|
||||
from flask import Flask
|
||||
|
||||
*** Update File: mathweb/flask/app.py
|
||||
@@ def get_factorial(self, n):
|
||||
@@
|
||||
-from flask import Flask
|
||||
-
|
||||
-from flask import Flask
|
||||
+from flask import Flask
|
||||
+import math
|
||||
@@
|
||||
-def factorial(n):
|
||||
- "compute factorial"
|
||||
-
|
||||
|
@ -63,26 +69,27 @@ Here is the patch:
|
|||
- return 1
|
||||
- else:
|
||||
- return n * factorial(n-1)
|
||||
-
|
||||
|
||||
*** Update File: mathweb/flask/app.py
|
||||
+def factorial(n):
|
||||
+ "compute factorial"
|
||||
+
|
||||
+ return math.factorial(n)
|
||||
@@ def get_factorial(self, n):
|
||||
- return str(factorial(n))
|
||||
+ return str(math.factorial(n))
|
||||
|
||||
*** End Patch
|
||||
""",
|
||||
),
|
||||
# --- Example 2 ---------------------------------------------------- #
|
||||
dict(
|
||||
role="user",
|
||||
content="Refactor hello() into its own file.",
|
||||
),
|
||||
dict(
|
||||
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.
|
||||
2. Remove hello() from main.py and replace it with an import.
|
||||
1. Create `hello.py` with the `hello()` function.
|
||||
2. Remove `hello()` from `main.py` and import it instead.
|
||||
|
||||
Here is the patch:
|
||||
|
||||
|
@ -93,20 +100,21 @@ Here is the patch:
|
|||
+ "print a greeting"
|
||||
+
|
||||
+ print("hello")
|
||||
|
||||
*** Update File: main.py
|
||||
@@ def main():
|
||||
@@
|
||||
-def hello():
|
||||
- "print a greeting"
|
||||
-
|
||||
- print("hello")
|
||||
+from hello import hello
|
||||
|
||||
*** End Patch
|
||||
""",
|
||||
),
|
||||
]
|
||||
|
||||
# --------------------------------------------------------------------- #
|
||||
# SYSTEM REMINDER
|
||||
# --------------------------------------------------------------------- #
|
||||
system_reminder = """# V4A Diff Format Rules:
|
||||
|
||||
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.
|
||||
{quad_backtick_reminder}
|
||||
|
||||
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`.
|
||||
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:
|
||||
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!
|
||||
|
||||
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.
|
||||
|
||||
Pay attention to which filenames the user wants you to edit, especially if they are asking you to create a new file.
|
||||
When moving code *within* a single file, keep everything inside one
|
||||
`*** Update File:` block. Provide one hunk that deletes the code from its
|
||||
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 `+`.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue