mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
note all file edits in the chat history, apart from the message with the current file contents
This commit is contained in:
parent
92a94d4b99
commit
257b58ba86
2 changed files with 70 additions and 36 deletions
30
coder.py
30
coder.py
|
@ -110,31 +110,21 @@ class Coder:
|
|||
return True
|
||||
return False
|
||||
|
||||
def set_files_messages(self, did_edits=None):
|
||||
if did_edits:
|
||||
print("Reloading files...")
|
||||
|
||||
if did_edits == "gpt":
|
||||
files_content = prompts.files_content_prefix_gpt_edits
|
||||
elif did_edits == "local":
|
||||
files_content = prompts.files_content_prefix_local_edits
|
||||
else:
|
||||
files_content = prompts.files_content_prefix_initial
|
||||
|
||||
def get_files_messages(self):
|
||||
files_content = prompts.files_content_prefix
|
||||
files_content += self.get_files_content()
|
||||
files_content += prompts.files_content_suffix
|
||||
|
||||
self.files_messages = [
|
||||
files_messages = [
|
||||
dict(role="user", content=files_content),
|
||||
dict(role="assistant", content="Ok."),
|
||||
]
|
||||
|
||||
return True
|
||||
return files_messages
|
||||
|
||||
def run(self):
|
||||
self.done_messages = []
|
||||
self.cur_messages = []
|
||||
self.set_files_messages()
|
||||
|
||||
while True:
|
||||
inp = self.get_input()
|
||||
|
@ -143,8 +133,11 @@ class Coder:
|
|||
|
||||
if self.check_for_local_edits():
|
||||
# files changed, move cur messages back behind the files messages
|
||||
self.set_files_messages("local")
|
||||
self.done_messages += self.cur_messages
|
||||
self.done_messages += [
|
||||
dict(role="user", content=prompts.files_content_local_edits),
|
||||
dict(role="assistant", content="Ok."),
|
||||
]
|
||||
self.cur_messages = []
|
||||
|
||||
self.cur_messages += [
|
||||
|
@ -159,7 +152,7 @@ class Coder:
|
|||
dict(role="system", content=prompts.main_system),
|
||||
]
|
||||
messages += self.done_messages
|
||||
messages += self.files_messages
|
||||
messages += self.get_files_messages()
|
||||
messages += self.cur_messages
|
||||
|
||||
self.show_messages(messages, "all")
|
||||
|
@ -184,8 +177,11 @@ class Coder:
|
|||
continue
|
||||
|
||||
self.check_for_local_edits(True)
|
||||
self.set_files_messages("gpt")
|
||||
self.done_messages += self.cur_messages
|
||||
self.done_messages += [
|
||||
dict(role="user", content=prompts.files_content_gpt_edits),
|
||||
dict(role="assistant", content="Ok."),
|
||||
]
|
||||
self.cur_messages = []
|
||||
|
||||
def show_messages(self, messages, title):
|
||||
|
|
76
prompts.py
76
prompts.py
|
@ -3,12 +3,26 @@
|
|||
main_system = '''
|
||||
I want you to act as an expert software engineer and pair programmer.
|
||||
|
||||
You are to take requests from the user for new features, improvements, bug fixes and other changes to the code.
|
||||
The user will show you the files in the following triple-quoted format.
|
||||
NEVER REPLY USING THIS FORMAT!
|
||||
|
||||
some/dir/example.py
|
||||
```
|
||||
class Foo:
|
||||
# Main functions
|
||||
#
|
||||
# Function to multiply two numbers
|
||||
def mul(a,b)
|
||||
return a * b
|
||||
...
|
||||
```
|
||||
|
||||
Take requests from the user for new features, improvements, bug fixes and other changes to the supplied code.
|
||||
If the user's request is ambiguous, ask questions to fully understand.
|
||||
|
||||
Once you understand each change, your responses must be:
|
||||
Once you understand the user's request, your responses MUST be:
|
||||
|
||||
1. Once you understand the question, briefly explain the needed changes.
|
||||
1. Briefly explain the needed changes.
|
||||
2. For each change to the code, describe it using the ORIGINAL/UPDATED format shown in the example below.
|
||||
|
||||
some/dir/example.py
|
||||
|
@ -17,7 +31,6 @@ some/dir/example.py
|
|||
#
|
||||
# Function to multiply two numbers
|
||||
def mul(a,b)
|
||||
"""
|
||||
=======
|
||||
# Main functions are below.
|
||||
# Add new ones in this section
|
||||
|
@ -25,14 +38,6 @@ some/dir/example.py
|
|||
def mul(a,b):
|
||||
"""Multiplies 2 numbers"""
|
||||
>>>>>>> UPDATED
|
||||
|
||||
THE ORIGINAL BLOCK MUST BE THE *EXACT* LINES FROM THE FILE, INCLUDING LEADING SPACES!!
|
||||
|
||||
Be sure to include the correct path and filename for each edit, exactly as specified by the user.
|
||||
Don't use ``` to mark code blocks!
|
||||
Don't use diff output.
|
||||
ONLY REPLY WITH CODE IN ORIGINAL/UPDATED FORMAT CHANGES SHOWN ABOVE!
|
||||
NEVER REPLY WITH AN ENTIRE FILE!
|
||||
'''
|
||||
|
||||
returned_code = """
|
||||
|
@ -47,17 +52,50 @@ system_reminder = "REMEMBER, ONLY RETURN CODE USING THE ORIGINAL/UPDATED FORMAT!
|
|||
|
||||
### FILES
|
||||
|
||||
files_content_prefix_gpt_edits = (
|
||||
"I made your suggested changes, here are the updated files:\n\n"
|
||||
)
|
||||
files_content_gpt_edits = "I made your suggested changes to the files."
|
||||
|
||||
files_content_prefix_local_edits = (
|
||||
"I made some changes to the files, here are the updated files:\n\n"
|
||||
)
|
||||
files_content_local_edits = "I made some changes to the files myself."
|
||||
|
||||
files_content_prefix_initial = "Here are the files:\n\n"
|
||||
files_content_prefix = "Here is the current content of the files:\n\n"
|
||||
|
||||
files_content_suffix = """
|
||||
|
||||
BASE ANY EDITS ON THE CURRENT CONTENTS OF THE FILES AS SHOWN IN THIS MESSAGE.
|
||||
NEVER REPLY WITH AN ENTIRE FILE IN THE TRIPLE-QUOTED FORMAT LIKE THIS!
|
||||
ANY CODE YOU INCLUDE IN A REPLY MUST BE IN THE ORIGINAL/UPDATED FORMAT!
|
||||
THE ORIGINAL BLOCK MUST BE THE *EXACT* LINES FROM THE FILE!
|
||||
INCLUDE ALL THE LEADING SPACES!!
|
||||
Be sure to include the correct path and filename for each edit, exactly as specified by the user.
|
||||
DO NOT REPLY WITH diff OUTPUT!
|
||||
"""
|
||||
|
||||
|
||||
### EDITOR
|
||||
|
||||
editor_system = """
|
||||
You are an expert code editor.
|
||||
Perform the requested edit.
|
||||
Output ONLY the new version of the file.
|
||||
Just that one file.
|
||||
Do not output explanations!
|
||||
Do not wrap the output in ``` delimiters.
|
||||
"""
|
||||
|
||||
editor_user = """
|
||||
To complete this request:
|
||||
|
||||
{request}
|
||||
|
||||
You need to apply this change:
|
||||
|
||||
{edit}
|
||||
|
||||
To this file:
|
||||
|
||||
{fname}
|
||||
```
|
||||
{content}
|
||||
```
|
||||
|
||||
ONLY OUTPUT {fname} !!!
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue