mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
different user msgs for initial, local and gpt edits
This commit is contained in:
parent
d61ab51a74
commit
e9f0c0ced2
2 changed files with 42 additions and 30 deletions
41
coder.py
41
coder.py
|
@ -45,15 +45,17 @@ class Coder:
|
|||
fnames = dict()
|
||||
last_modified = 0
|
||||
|
||||
def __init__(self, use_gpt_4):
|
||||
def __init__(self, use_gpt_4, files):
|
||||
if use_gpt_4:
|
||||
self.main_model = "gpt-4"
|
||||
else:
|
||||
self.main_model = "gpt-3.5-turbo"
|
||||
|
||||
def add_file(self, fname):
|
||||
for fname in files:
|
||||
self.fnames[fname] = Path(fname).stat().st_mtime
|
||||
|
||||
self.check_for_local_edits(True)
|
||||
|
||||
def files_modified(self):
|
||||
for fname, mtime in self.fnames.items():
|
||||
if Path(fname).stat().st_mtime != mtime:
|
||||
|
@ -98,19 +100,26 @@ class Coder:
|
|||
readline.write_history_file(history_file)
|
||||
return inp
|
||||
|
||||
def set_files_messages(self, did_edits=False):
|
||||
def check_for_local_edits(self, init=False):
|
||||
last_modified = max(Path(fname).stat().st_mtime for fname in self.fnames)
|
||||
if last_modified <= self.last_modified:
|
||||
return
|
||||
did_edits = self.last_modified > 0
|
||||
|
||||
since = last_modified - self.last_modified
|
||||
self.last_modified = last_modified
|
||||
if init:
|
||||
return
|
||||
if since > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_files_messages(self, did_edits=None):
|
||||
if did_edits:
|
||||
print("Reloading files...")
|
||||
|
||||
if did_edits:
|
||||
files_content = prompts.files_content_prefix_edited
|
||||
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_plain
|
||||
files_content = prompts.files_content_prefix_initial
|
||||
|
||||
files_content += self.get_files_content()
|
||||
files_content += prompts.files_content_suffix
|
||||
|
@ -132,8 +141,9 @@ class Coder:
|
|||
if inp is None:
|
||||
return
|
||||
|
||||
if self.set_files_messages():
|
||||
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.cur_messages = []
|
||||
|
||||
|
@ -173,7 +183,8 @@ class Coder:
|
|||
if not edited:
|
||||
continue
|
||||
|
||||
self.set_files_messages(True)
|
||||
self.check_for_local_edits(True)
|
||||
self.set_files_messages("gpt")
|
||||
self.done_messages += self.cur_messages
|
||||
self.cur_messages = []
|
||||
|
||||
|
@ -409,13 +420,9 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
use_gpt_4 = not args.gpt_3_5_turbo
|
||||
coder = Coder(use_gpt_4)
|
||||
|
||||
fnames = args.files
|
||||
|
||||
for fname in fnames:
|
||||
coder.add_file(fname)
|
||||
|
||||
coder = Coder(use_gpt_4, fnames)
|
||||
coder.run()
|
||||
|
||||
|
||||
|
|
29
prompts.py
29
prompts.py
|
@ -1,4 +1,3 @@
|
|||
|
||||
### MAIN
|
||||
|
||||
main_system = '''
|
||||
|
@ -36,39 +35,45 @@ ONLY REPLY WITH CODE IN ORIGINAL/UPDATED FORMAT CHANGES SHOWN ABOVE!
|
|||
NEVER REPLY WITH AN ENTIRE FILE!
|
||||
'''
|
||||
|
||||
returned_code = '''
|
||||
returned_code = """
|
||||
It looks like you tried to return a code block. Don't do that!
|
||||
|
||||
Only return code using the specific ORIGINAL/UPDATED format.
|
||||
Be selective!
|
||||
Only return the parts of the code which need changes!
|
||||
'''
|
||||
"""
|
||||
|
||||
system_reminder = 'REMEMBER, ONLY RETURN CODE USING THE ORIGINAL/UPDATED FORMAT!'
|
||||
system_reminder = "REMEMBER, ONLY RETURN CODE USING THE ORIGINAL/UPDATED FORMAT!"
|
||||
|
||||
### FILES
|
||||
|
||||
files_content_prefix_edited = 'I made your suggested changes, here are the updated files:\n\n'
|
||||
files_content_prefix_gpt_edits = (
|
||||
"I made your suggested changes, here are the updated files:\n\n"
|
||||
)
|
||||
|
||||
files_content_prefix_plain = 'Here are the files:\n\n'
|
||||
files_content_prefix_local_edits = (
|
||||
"I made some changes to the files, here are the updated files:\n\n"
|
||||
)
|
||||
|
||||
files_content_suffix = '''
|
||||
files_content_prefix_initial = "Here are the files:\n\n"
|
||||
|
||||
files_content_suffix = """
|
||||
|
||||
BASE ANY EDITS ON THE CURRENT CONTENTS OF THE FILES AS SHOWN IN THIS MESSAGE.
|
||||
'''
|
||||
"""
|
||||
|
||||
### EDITOR
|
||||
|
||||
editor_system = '''
|
||||
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 = '''
|
||||
editor_user = """
|
||||
To complete this request:
|
||||
|
||||
{request}
|
||||
|
@ -85,4 +90,4 @@ To this file:
|
|||
```
|
||||
|
||||
ONLY OUTPUT {fname} !!!
|
||||
'''
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue