mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 10:14:59 +00:00
refactor Editors
This commit is contained in:
parent
122c1c4f6c
commit
03d2c73621
6 changed files with 101 additions and 90 deletions
|
@ -14,7 +14,7 @@ from rich.console import Console
|
||||||
from rich.live import Live
|
from rich.live import Live
|
||||||
from rich.markdown import Markdown
|
from rich.markdown import Markdown
|
||||||
|
|
||||||
from aider import diffs, models, prompts, utils
|
from aider import diffs, editors, models, prompts, utils
|
||||||
from aider.commands import Commands
|
from aider.commands import Commands
|
||||||
from aider.repomap import RepoMap
|
from aider.repomap import RepoMap
|
||||||
|
|
||||||
|
@ -94,9 +94,13 @@ class Coder:
|
||||||
self.edit_format = self.main_model.edit_format
|
self.edit_format = self.main_model.edit_format
|
||||||
|
|
||||||
if self.edit_format == "whole":
|
if self.edit_format == "whole":
|
||||||
self.gpt_prompts = prompts.GPT35()
|
self.gpt_prompts = editors.WholeFilePrompts()
|
||||||
|
elif self.edit_format == "diff":
|
||||||
|
self.gpt_prompts = editors.EditBlockPrompts()
|
||||||
else:
|
else:
|
||||||
self.gpt_prompts = prompts.GPT4()
|
raise ValueError(
|
||||||
|
f"Model {main_model} requesting unknown edit format {self.edit_format}"
|
||||||
|
)
|
||||||
|
|
||||||
self.io.tool_output(f"Model: {main_model.name}")
|
self.io.tool_output(f"Model: {main_model.name}")
|
||||||
|
|
||||||
|
|
2
aider/editors/__init__.py
Normal file
2
aider/editors/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
from .editblock import EditBlockPrompts
|
||||||
|
from .wholefile import WholeFilePrompts
|
6
aider/editors/base.py
Normal file
6
aider/editors/base.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class EditorPrompts:
|
||||||
|
files_content_gpt_edits = "I committed the changes with git hash {hash} & commit msg: {message}"
|
||||||
|
|
||||||
|
files_content_gpt_no_edits = "I didn't see any properly formatted edits in your reply?!"
|
||||||
|
|
||||||
|
files_content_local_edits = "I edited the files myself."
|
56
aider/editors/editblock.py
Normal file
56
aider/editors/editblock.py
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# flake8: noqa: E501
|
||||||
|
|
||||||
|
from .base import EditorPrompts
|
||||||
|
|
||||||
|
|
||||||
|
class EditBlockPrompts(EditorPrompts):
|
||||||
|
main_system = """Act as an expert software developer.
|
||||||
|
Be concise!
|
||||||
|
|
||||||
|
Take requests for changes to the supplied code.
|
||||||
|
If the request is ambiguous, ask questions.
|
||||||
|
|
||||||
|
Once you understand the request you MUST:
|
||||||
|
1. List the files you need to modify. *NEVER* suggest changes to *read-only* files. You *MUST* ask the user to make them *read-write* using the file's full path name. End your reply and wait for their approval.
|
||||||
|
2. Think step-by-step and explain the needed changes.
|
||||||
|
3. Describe each change with an *edit block* per the example below.
|
||||||
|
"""
|
||||||
|
|
||||||
|
system_reminder = """You MUST format EVERY code change with an *edit block* like this:
|
||||||
|
|
||||||
|
```python
|
||||||
|
some/dir/example.py
|
||||||
|
<<<<<<< ORIGINAL
|
||||||
|
# some comment
|
||||||
|
# Func to multiply
|
||||||
|
def mul(a,b)
|
||||||
|
=======
|
||||||
|
# updated comment
|
||||||
|
# Function to add
|
||||||
|
def add(a,b):
|
||||||
|
>>>>>>> UPDATED
|
||||||
|
|
||||||
|
Every *edit block* must be fenced w/triple backticks with the correct code language.
|
||||||
|
Every *edit block* must start with the full path! *NEVER* propose edit blocks for *read-only* files.
|
||||||
|
The ORIGINAL section must be an *exact* set of lines from the file:
|
||||||
|
- NEVER SKIP LINES!
|
||||||
|
- Include all original leading spaces and indentation!
|
||||||
|
|
||||||
|
Edits to different parts of a file each need their own *edit block*.
|
||||||
|
|
||||||
|
If you want to put code in a new file, use an edit block with:
|
||||||
|
- A new file path, including dir name if needed
|
||||||
|
- An empty ORIGINAL section
|
||||||
|
- The new file's contents in the UPDATED section
|
||||||
|
|
||||||
|
If a request requires many changes, stop often to ask the user for feedback.
|
||||||
|
"""
|
||||||
|
|
||||||
|
files_content_prefix = "These are the *read-write* files:\n"
|
||||||
|
|
||||||
|
files_no_full_files = "I am not sharing any *read-write* files yet."
|
||||||
|
|
||||||
|
repo_content_prefix = (
|
||||||
|
"Below here are summaries of other files! Do not propose changes to these *read-only*"
|
||||||
|
" files without asking me first.\n"
|
||||||
|
)
|
30
aider/editors/wholefile.py
Normal file
30
aider/editors/wholefile.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# flake8: noqa: E501
|
||||||
|
|
||||||
|
from .base import EditorPrompts
|
||||||
|
|
||||||
|
|
||||||
|
class WholeFilePrompts(EditorPrompts):
|
||||||
|
main_system = """Act as an expert software developer.
|
||||||
|
Take requests for changes to the supplied code.
|
||||||
|
If the request is ambiguous, ask questions.
|
||||||
|
|
||||||
|
Once you understand the request you MUST:
|
||||||
|
1. Determine if any code changes are needed.
|
||||||
|
2. Explain any needed changes.
|
||||||
|
3. If changes are needed, output a copy of each file that needs changes.
|
||||||
|
"""
|
||||||
|
|
||||||
|
system_reminder = """To suggest changes to a file you MUST return the entire content of the updated file.
|
||||||
|
You MUST use this format:
|
||||||
|
|
||||||
|
exact/path/to/filename.js
|
||||||
|
```javascript
|
||||||
|
// file content goes in the
|
||||||
|
// triple backticked fenced block
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
files_content_prefix = "Here is the current content of the files:\n"
|
||||||
|
files_no_full_files = "I am not sharing any files yet."
|
||||||
|
|
||||||
|
redacted_edit_message = "No changes are needed."
|
|
@ -1,91 +1,4 @@
|
||||||
# flake8: noqa: E501
|
# flake8: noqa: E501
|
||||||
# MAIN
|
|
||||||
|
|
||||||
|
|
||||||
class GPT4:
|
|
||||||
main_system = """Act as an expert software developer.
|
|
||||||
Be concise!
|
|
||||||
|
|
||||||
Take requests for changes to the supplied code.
|
|
||||||
If the request is ambiguous, ask questions.
|
|
||||||
|
|
||||||
Once you understand the request you MUST:
|
|
||||||
1. List the files you need to modify. *NEVER* suggest changes to *read-only* files. You *MUST* ask the user to make them *read-write* using the file's full path name. End your reply and wait for their approval.
|
|
||||||
2. Think step-by-step and explain the needed changes.
|
|
||||||
3. Describe each change with an *edit block* per the example below.
|
|
||||||
"""
|
|
||||||
|
|
||||||
system_reminder = """You MUST format EVERY code change with an *edit block* like this:
|
|
||||||
|
|
||||||
```python
|
|
||||||
some/dir/example.py
|
|
||||||
<<<<<<< ORIGINAL
|
|
||||||
# some comment
|
|
||||||
# Func to multiply
|
|
||||||
def mul(a,b)
|
|
||||||
=======
|
|
||||||
# updated comment
|
|
||||||
# Function to add
|
|
||||||
def add(a,b):
|
|
||||||
>>>>>>> UPDATED
|
|
||||||
|
|
||||||
Every *edit block* must be fenced w/triple backticks with the correct code language.
|
|
||||||
Every *edit block* must start with the full path! *NEVER* propose edit blocks for *read-only* files.
|
|
||||||
The ORIGINAL section must be an *exact* set of lines from the file:
|
|
||||||
- NEVER SKIP LINES!
|
|
||||||
- Include all original leading spaces and indentation!
|
|
||||||
|
|
||||||
Edits to different parts of a file each need their own *edit block*.
|
|
||||||
|
|
||||||
If you want to put code in a new file, use an edit block with:
|
|
||||||
- A new file path, including dir name if needed
|
|
||||||
- An empty ORIGINAL section
|
|
||||||
- The new file's contents in the UPDATED section
|
|
||||||
|
|
||||||
If a request requires many changes, stop often to ask the user for feedback.
|
|
||||||
"""
|
|
||||||
|
|
||||||
files_content_gpt_edits = "I committed the changes with git hash {hash} & commit msg: {message}"
|
|
||||||
|
|
||||||
files_content_gpt_no_edits = "I didn't see any properly formatted edits in your reply?!"
|
|
||||||
|
|
||||||
files_content_local_edits = "I edited the files myself."
|
|
||||||
|
|
||||||
files_content_prefix = "These are the *read-write* files:\n"
|
|
||||||
|
|
||||||
files_no_full_files = "I am not sharing any *read-write* files yet."
|
|
||||||
|
|
||||||
repo_content_prefix = (
|
|
||||||
"Below here are summaries of other files! Do not propose changes to these *read-only*"
|
|
||||||
" files without asking me first.\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GPT35(GPT4):
|
|
||||||
main_system = """Act as an expert software developer.
|
|
||||||
Take requests for changes to the supplied code.
|
|
||||||
If the request is ambiguous, ask questions.
|
|
||||||
|
|
||||||
Once you understand the request you MUST:
|
|
||||||
1. Determine if any code changes are needed.
|
|
||||||
2. Explain any needed changes.
|
|
||||||
3. If changes are needed, output a copy of each file that needs changes.
|
|
||||||
"""
|
|
||||||
|
|
||||||
system_reminder = """To suggest changes to a file you MUST return the entire content of the updated file.
|
|
||||||
You MUST use this format:
|
|
||||||
|
|
||||||
exact/path/to/filename.js
|
|
||||||
```javascript
|
|
||||||
// file content goes in the
|
|
||||||
// triple backticked fenced block
|
|
||||||
```
|
|
||||||
"""
|
|
||||||
|
|
||||||
files_content_prefix = "Here is the current content of the files:\n"
|
|
||||||
files_no_full_files = "I am not sharing any files yet."
|
|
||||||
|
|
||||||
redacted_edit_message = "No changes are needed."
|
|
||||||
|
|
||||||
|
|
||||||
# COMMIT
|
# COMMIT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue