mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
wip
This commit is contained in:
parent
94fc5a69e4
commit
70b829b674
1 changed files with 43 additions and 16 deletions
59
coder.py
59
coder.py
|
@ -22,11 +22,7 @@ prompt_webdev = '''
|
||||||
I want you to act as a web development pair programmer.
|
I want you to act as a web development pair programmer.
|
||||||
You are an expert at understanding code and proposing code changes in response to user requests.
|
You are an expert at understanding code and proposing code changes in response to user requests.
|
||||||
|
|
||||||
Ask any questions you need to fully understand the user's request.
|
YOU MUST ONLY RETURN CODE USING THESE COMMANDS!
|
||||||
|
|
||||||
DO NOT REPLACE ENTIRE FILES!
|
|
||||||
|
|
||||||
YOU MUST ONLY RETURN CODE USING THESE COMMANDS:
|
|
||||||
- BEFORE/AFTER
|
- BEFORE/AFTER
|
||||||
- DELETE
|
- DELETE
|
||||||
- APPEND
|
- APPEND
|
||||||
|
@ -39,8 +35,7 @@ BEFORE path/to/filename.ext
|
||||||
... a series of lines from ...
|
... a series of lines from ...
|
||||||
... the original file ...
|
... the original file ...
|
||||||
... completely unchanged ...
|
... completely unchanged ...
|
||||||
... include ONLY the sections of the file which need changes! ...
|
... use as few lines as possible ...
|
||||||
... DO NOT USE THIS TO REPLACE AN ENTIRE FILES CONTENTS ...
|
|
||||||
```
|
```
|
||||||
AFTER
|
AFTER
|
||||||
```
|
```
|
||||||
|
@ -75,6 +70,7 @@ PREPEND path/to/filename.ext
|
||||||
```
|
```
|
||||||
|
|
||||||
Study the provided code and then ask the user how they want you to change it.
|
Study the provided code and then ask the user how they want you to change it.
|
||||||
|
Ask any questions you need to fully understand the user's request.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
prompt_comments = '''
|
prompt_comments = '''
|
||||||
|
@ -195,31 +191,56 @@ class Coder:
|
||||||
prompt += self.quoted_file(fname)
|
prompt += self.quoted_file(fname)
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
change_notice = '''
|
||||||
|
TAKE NOTE!
|
||||||
|
The contents of the files have been updated!
|
||||||
|
USE THESE FILES NOW.
|
||||||
|
MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
|
'''
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
|
sys.stdout.write('> ')
|
||||||
|
sys.stdout.flush()
|
||||||
|
inp = input()
|
||||||
|
|
||||||
messages = [
|
messages = [
|
||||||
dict(role = 'system', content = self.system_prompt),
|
dict(role = 'system', content = self.system_prompt),
|
||||||
dict(role = 'user', content = self.get_files_message()),
|
dict(role = 'user', content = 'Here is the content of the files. DO NOT OUTPUT CODE USING THIS FORMAT\n' + self.get_files_message()),
|
||||||
|
dict(role = 'user', content = inp),
|
||||||
]
|
]
|
||||||
file_msg_no = 1
|
file_msg_no = 1
|
||||||
|
|
||||||
while True:
|
|
||||||
content = self.send(messages)
|
content = self.send(messages)
|
||||||
self.update_files(content)
|
|
||||||
|
while True:
|
||||||
|
print()
|
||||||
|
if self.update_files(content):
|
||||||
|
print()
|
||||||
|
|
||||||
|
sys.stdout.write('> ')
|
||||||
|
sys.stdout.flush()
|
||||||
inp = input()
|
inp = input()
|
||||||
|
|
||||||
if self.files_modified():
|
if self.files_modified():
|
||||||
print('Updating ChatGPT with current file contents')
|
for fname in self.fnames:
|
||||||
|
self.add_file(fname)
|
||||||
|
|
||||||
|
print('Files have changed, informing ChatGPT.')
|
||||||
|
print()
|
||||||
|
|
||||||
messages[file_msg_no] = dict(role = 'user', content = '<<outdated list of the files and their content -- removed>>')
|
messages[file_msg_no] = dict(role = 'user', content = '<<outdated list of the files and their content -- removed>>')
|
||||||
messages.append(
|
messages.append(
|
||||||
dict(
|
dict(
|
||||||
role = 'user',
|
role = 'user',
|
||||||
content = 'The files have been updated. Here is the current content of the files. Take note! Base future changes on this update!\n' + self.get_files_message(),
|
content = self.change_notice + self.get_files_message(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
file_msg_no = len(messages)-1
|
file_msg_no = len(messages)-1
|
||||||
|
|
||||||
message = dict(role = 'user', content = inp)
|
message = dict(role = 'user', content = inp)
|
||||||
messages.append(message)
|
messages.append(message)
|
||||||
|
content = self.send(messages)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def send(self, messages):
|
def send(self, messages):
|
||||||
|
@ -240,9 +261,6 @@ class Coder:
|
||||||
sys.stdout.write(text)
|
sys.stdout.write(text)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
print()
|
|
||||||
print('='*40)
|
|
||||||
|
|
||||||
resp = ''.join(resp)
|
resp = ''.join(resp)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
|
@ -276,6 +294,9 @@ class Coder:
|
||||||
lines[start-1:end+1]
|
lines[start-1:end+1]
|
||||||
for start,end in pairs
|
for start,end in pairs
|
||||||
]
|
]
|
||||||
|
if not ops:
|
||||||
|
return
|
||||||
|
|
||||||
ops.reverse()
|
ops.reverse()
|
||||||
while ops:
|
while ops:
|
||||||
op = ops.pop()
|
op = ops.pop()
|
||||||
|
@ -287,6 +308,9 @@ class Coder:
|
||||||
if cmd == 'APPEND':
|
if cmd == 'APPEND':
|
||||||
self.do_append(cmd, fname, op_lines)
|
self.do_append(cmd, fname, op_lines)
|
||||||
continue
|
continue
|
||||||
|
raise ValueError(op)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
def do_append(self, cmd, fname, op_lines):
|
def do_append(self, cmd, fname, op_lines):
|
||||||
if fname not in self.fnames:
|
if fname not in self.fnames:
|
||||||
|
@ -300,6 +324,8 @@ class Coder:
|
||||||
content += '\n'
|
content += '\n'
|
||||||
fname.write_text(content)
|
fname.write_text(content)
|
||||||
|
|
||||||
|
print('Applied APPEND', fname)
|
||||||
|
|
||||||
def do_before(self, cmd, fname, op_lines, after_op):
|
def do_before(self, cmd, fname, op_lines, after_op):
|
||||||
after_cmd,after_fname,after_lines = self.parse_op(after_op)
|
after_cmd,after_fname,after_lines = self.parse_op(after_op)
|
||||||
if after_cmd != 'AFTER':
|
if after_cmd != 'AFTER':
|
||||||
|
@ -324,6 +350,7 @@ class Coder:
|
||||||
new_content = '\n'.join(new_content) + '\n'
|
new_content = '\n'.join(new_content) + '\n'
|
||||||
|
|
||||||
fname.write_text(new_content)
|
fname.write_text(new_content)
|
||||||
|
print('Applied CHANGE', fname)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -352,7 +379,7 @@ coder.run()
|
||||||
'''
|
'''
|
||||||
Change all the speaker icons to orange.
|
Change all the speaker icons to orange.
|
||||||
|
|
||||||
The speaker icons come before the text of each message. Move them so they come after the text instead.
|
Currently the speaker icons come before the text of each message. Move them so they come after the text instead.
|
||||||
|
|
||||||
Move the About and New Chat links into a hamburger menu.
|
Move the About and New Chat links into a hamburger menu.
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue