mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-21 12:55:00 +00:00
works
This commit is contained in:
parent
8e0498a35f
commit
692e649c3f
1 changed files with 31 additions and 55 deletions
86
coder.py
86
coder.py
|
@ -18,8 +18,10 @@ openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||||
|
|
||||||
prompt_webdev = '''
|
prompt_webdev = '''
|
||||||
I want you to act as a web development expert.
|
I want you to act as a web development expert.
|
||||||
You are to carefully study the provided code and follow the user instructions.
|
I want you to answer only with code.
|
||||||
Be detail oriented, explicit and thorough in following user instructions.
|
Make the requested change to the provided code and output the changed code.
|
||||||
|
MAKE NO OTHER CHANGES!
|
||||||
|
Do not provide explanations!
|
||||||
'''
|
'''
|
||||||
|
|
||||||
class Chat:
|
class Chat:
|
||||||
|
@ -39,36 +41,15 @@ class Chat:
|
||||||
prompt += '\n```\n'
|
prompt += '\n```\n'
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
def plan(self):
|
def setup(self):
|
||||||
self.plan_prompt = '''
|
prompt = ''
|
||||||
Briefly describe all the code changes needed to complete the user request.
|
|
||||||
Think carefully about the code and the request!
|
|
||||||
Just describe ALL the changes needed to complete the request.
|
|
||||||
Just describe the changes, don't output code for them.
|
|
||||||
Be thorough. Describe ALL the changes needed to complete the request.
|
|
||||||
Only describe changes related to the request.
|
|
||||||
Don't output the changed code!
|
|
||||||
Just briefly describe the changes.
|
|
||||||
|
|
||||||
Request:
|
|
||||||
'''
|
|
||||||
prompt = self.plan_prompt
|
|
||||||
prompt += self.request_prompt + '\n###\n'
|
|
||||||
|
|
||||||
for fname in self.fnames:
|
for fname in self.fnames:
|
||||||
prompt += self.quoted_file(fname)
|
prompt += self.quoted_file(fname)
|
||||||
|
|
||||||
###
|
prompt += '\n###\n'
|
||||||
#print(self.system_prompt)
|
prompt += self.request_prompt
|
||||||
#print(prompt)
|
|
||||||
#sys.exit()
|
|
||||||
|
|
||||||
self.messages = [
|
self.prompt = prompt
|
||||||
dict(role = 'system', content = self.system_prompt),
|
|
||||||
dict(role = 'user', content = prompt),
|
|
||||||
]
|
|
||||||
self.plan = self.send(self.messages)
|
|
||||||
self.messages.append(dict(role = 'assistant', content = self.plan))
|
|
||||||
|
|
||||||
def send(self, messages):
|
def send(self, messages):
|
||||||
completion = openai.ChatCompletion.create(
|
completion = openai.ChatCompletion.create(
|
||||||
|
@ -94,39 +75,33 @@ Request:
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
def update_files(self):
|
def update_files(self):
|
||||||
|
random.shuffle(self.fnames)
|
||||||
for fname in self.fnames:
|
for fname in self.fnames:
|
||||||
self.update_file(fname)
|
self.update_file(fname)
|
||||||
|
|
||||||
def update_file(self, fname):
|
def update_file(self, fname):
|
||||||
prompt = self.plan_prompt
|
prompt = self.prompt
|
||||||
prompt += self.request_prompt + '\n###\n'
|
prompt += f'''
|
||||||
prompt += self.quoted_file(fname)
|
Output the updated version of {fname.name}
|
||||||
|
'''
|
||||||
|
|
||||||
messages = [
|
messages = [
|
||||||
dict(role = 'system', content = self.system_prompt),
|
dict(role = 'system', content = self.system_prompt),
|
||||||
dict(role = 'user', content = prompt),
|
dict(role = 'user', content = prompt),
|
||||||
dict(role = 'assistant', content = self.plan),
|
|
||||||
dict(role = 'user',
|
|
||||||
content = f'''
|
|
||||||
Make the requested changes to {fname.name} and output the changed code.
|
|
||||||
MAKE NO OTHER CHANGES!
|
|
||||||
JUST OUTPUT CODE.
|
|
||||||
NO EXPLANATIONS.
|
|
||||||
IF NO CHANGES ARE NEEDED, JUST OUTPUT: NONE
|
|
||||||
'''
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
dump(messages)
|
|
||||||
|
|
||||||
new_content = chat.send(messages)
|
content = chat.send(messages)
|
||||||
if new_content.strip() == 'NONE':
|
if content.strip() == 'NONE':
|
||||||
return
|
return
|
||||||
|
|
||||||
if new_content.startswith('```\n'):
|
lines = content.splitlines()
|
||||||
new_content = new_content[4:]
|
if lines[0].startswith(fname.name):
|
||||||
if new_content.endswith('```'):
|
lines = lines[1:]
|
||||||
new_content = new_content[:-3]
|
if lines[0].startswith('```'):
|
||||||
fname.write_text(new_content)
|
lines = lines[1:]
|
||||||
|
if lines[-1].startswith('```'):
|
||||||
|
lines = lines[:-1]
|
||||||
|
fname.write_text('\n'.join(lines))
|
||||||
|
|
||||||
chat = Chat()
|
chat = Chat()
|
||||||
|
|
||||||
|
@ -137,13 +112,14 @@ chat.file(dname / 'index.html')
|
||||||
chat.file(dname / 'chat.css')
|
chat.file(dname / 'chat.css')
|
||||||
chat.file(dname / 'chat.js')
|
chat.file(dname / 'chat.js')
|
||||||
|
|
||||||
|
#for fname in chat.fnames:
|
||||||
|
# print(chat.quoted_file(fname))
|
||||||
|
#sys.exit()
|
||||||
|
|
||||||
chat.request('''
|
chat.request('''
|
||||||
Every time I click on the speaker, it adds ANOTHER speaker icon.
|
Right now the speaker icons come after the text in each speech bubble.
|
||||||
Clicking the icon should just speak the text, it should not add additional speaker icons.
|
Move all the speaker icons so they come before the text.
|
||||||
Fix this bug.
|
|
||||||
''')
|
''')
|
||||||
|
|
||||||
chat.plan()
|
chat.setup()
|
||||||
input()
|
|
||||||
|
|
||||||
chat.update_files()
|
chat.update_files()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue