mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-25 14:55:00 +00:00
better
This commit is contained in:
parent
70b829b674
commit
cd3e89d4fd
1 changed files with 50 additions and 41 deletions
87
coder.py
87
coder.py
|
@ -22,52 +22,38 @@ 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.
|
||||||
|
|
||||||
YOU MUST ONLY RETURN CODE USING THESE COMMANDS!
|
Your job is to:
|
||||||
|
|
||||||
|
1. Understand what the user wants changed in the code.
|
||||||
|
|
||||||
|
2. Use these editing commands to make the requested changes to the code. When you answer with these commands the file is immediately updated.
|
||||||
- BEFORE/AFTER
|
- BEFORE/AFTER
|
||||||
- DELETE
|
- REVERT
|
||||||
- APPEND
|
|
||||||
- PREPEND
|
3. Listen to feedback from the user on the changes. If the user doesn't like your changes, use REVERT to undo them!
|
||||||
|
|
||||||
|
4. Continue to use the editing commands to try and achieve the user's needs.
|
||||||
|
|
||||||
|
DON'T OUTPUT CODE BLOCKS EXCEPT BY USING THE EDITING COMMANDS.
|
||||||
|
|
||||||
|
* Here is how the editing commands work:
|
||||||
|
|
||||||
** This is how to replace lines from a file with a new set of lines.
|
** This is how to replace lines from a file with a new set of lines.
|
||||||
|
|
||||||
BEFORE path/to/filename.ext
|
BEFORE path/to/filename.ext
|
||||||
```
|
```
|
||||||
... a series of lines from ...
|
... unchanged lines from the original file ...
|
||||||
... the original file ...
|
... don't include a lot of extra lines which won't change! ...
|
||||||
... completely unchanged ...
|
... NEVER INCLUDE AN ENTIRE FILE! ...
|
||||||
... use as few lines as possible ...
|
|
||||||
```
|
```
|
||||||
AFTER
|
AFTER
|
||||||
```
|
```
|
||||||
... all occurances of the before lines ...
|
... new lines to replace them with ...
|
||||||
... will get replaced with the after lines ...
|
|
||||||
```
|
```
|
||||||
|
|
||||||
** This is how to remove lines from a file:
|
** This is how you can undo all the changes you made to a file, and restore it to the original state:
|
||||||
|
|
||||||
DELETE path/to/filename.ext
|
REVERT path/to/filename.ext
|
||||||
```
|
|
||||||
... a series of sequential entire lines from ...
|
|
||||||
... the original file ...
|
|
||||||
... completely unchanged ...
|
|
||||||
... that will be deleted ...
|
|
||||||
```
|
|
||||||
|
|
||||||
** This is how to append lines onto the end of a file:
|
|
||||||
|
|
||||||
APPEND path/to/filename.ext
|
|
||||||
```
|
|
||||||
... lines to add ...
|
|
||||||
... at the end of the file ...
|
|
||||||
```
|
|
||||||
|
|
||||||
** This is how to insert lines at the start of a file:
|
|
||||||
|
|
||||||
PREPEND path/to/filename.ext
|
|
||||||
```
|
|
||||||
... lines to add ...
|
|
||||||
... at the start of the file ...
|
|
||||||
```
|
|
||||||
|
|
||||||
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.
|
Ask any questions you need to fully understand the user's request.
|
||||||
|
@ -203,25 +189,41 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
inp = input()
|
inp = input()
|
||||||
|
|
||||||
|
prompt = ''
|
||||||
|
prompt += inp
|
||||||
|
prompt += '\n###\n'
|
||||||
|
prompt += 'Here is the content of the files. DO NOT OUTPUT CODE USING THIS FORMAT\n'
|
||||||
|
prompt += self.get_files_message()
|
||||||
|
|
||||||
messages = [
|
messages = [
|
||||||
dict(role = 'system', content = self.system_prompt),
|
dict(role = 'system', content = self.system_prompt),
|
||||||
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 = prompt),
|
||||||
dict(role = 'user', content = inp),
|
|
||||||
]
|
]
|
||||||
file_msg_no = 1
|
file_msg_no = 1
|
||||||
|
|
||||||
content = self.send(messages)
|
content = self.send(messages)
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
messages.append(
|
||||||
|
dict(
|
||||||
|
role = 'assistant',
|
||||||
|
content = content,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
print()
|
print()
|
||||||
|
try:
|
||||||
if self.update_files(content):
|
if self.update_files(content):
|
||||||
print()
|
print()
|
||||||
|
except Exception as err:
|
||||||
|
print(err)
|
||||||
|
print()
|
||||||
|
|
||||||
sys.stdout.write('> ')
|
sys.stdout.write('> ')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
inp = input()
|
inp = input()
|
||||||
|
|
||||||
if self.files_modified():
|
if False and self.files_modified():
|
||||||
for fname in self.fnames:
|
for fname in self.fnames:
|
||||||
self.add_file(fname)
|
self.add_file(fname)
|
||||||
|
|
||||||
|
@ -244,6 +246,8 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
|
|
||||||
|
|
||||||
def send(self, messages):
|
def send(self, messages):
|
||||||
|
dump(messages)
|
||||||
|
|
||||||
completion = openai.ChatCompletion.create(
|
completion = openai.ChatCompletion.create(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
#model="gpt-4",
|
#model="gpt-4",
|
||||||
|
@ -267,7 +271,7 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
quotes = '```'
|
quotes = '```'
|
||||||
|
|
||||||
def parse_op(self, lines):
|
def parse_op(self, lines):
|
||||||
if lines[1] != self.quotes or lines[-1] != self.quotes:
|
if lines[1].rstrip() != self.quotes or lines[-1].rstrip() != self.quotes:
|
||||||
raise ValueError(lines)
|
raise ValueError(lines)
|
||||||
|
|
||||||
pieces = lines[0].split()
|
pieces = lines[0].split()
|
||||||
|
@ -287,8 +291,13 @@ MAKE ANY CHANGES BASED OFF THESE FILES!
|
||||||
def update_files(self, content):
|
def update_files(self, content):
|
||||||
|
|
||||||
lines = content.splitlines()
|
lines = content.splitlines()
|
||||||
line_nums = [i for i, j in enumerate(lines) if j == self.quotes]
|
line_nums = [i for i, j in enumerate(lines) if j.rstrip() == self.quotes]
|
||||||
|
try:
|
||||||
pairs = [(line_nums[i], line_nums[i+1]) for i in range(0, len(line_nums), 2)]
|
pairs = [(line_nums[i], line_nums[i+1]) for i in range(0, len(line_nums), 2)]
|
||||||
|
except Exception:
|
||||||
|
dump(content)
|
||||||
|
dump(lines)
|
||||||
|
raise
|
||||||
|
|
||||||
ops = [
|
ops = [
|
||||||
lines[start-1:end+1]
|
lines[start-1:end+1]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue