mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-23 13:54:59 +00:00
comment
This commit is contained in:
parent
af04fd3540
commit
9ab3af1bc1
1 changed files with 31 additions and 8 deletions
39
coder.py
39
coder.py
|
@ -1,5 +1,17 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""
|
||||
This is a Python script that uses OpenAI's GPT-3 to modify code based on user requests. The script imports the necessary libraries and sets up the OpenAI API key. It then defines a Coder class that contains methods for sending requests to the OpenAI API and updating files based on the API's responses.
|
||||
|
||||
The Coder class has several methods, including system, file, request, quoted_file, run_davinci, run_edit, run, send, update_files, and update_file. These methods are used to interact with the OpenAI API and modify code based on user requests.
|
||||
|
||||
The script begins by defining a prompt for ChatGPT that explains its role. It then creates an instance of the Coder class and sets the system prompt to the prompt defined earlier.
|
||||
|
||||
The script then calls the run method of the Coder class, which prompts the user for input and sends that input to the OpenAI API. The API responds with modified code, which is then used to update the coder.py file.
|
||||
|
||||
Overall, this script is a powerful tool for modifying code based on user requests using OpenAI's GPT-3 API.
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import copy
|
||||
|
@ -22,13 +34,14 @@ You are an expert at understanding code and proposing code changes in response t
|
|||
Study the provided code and then change it according to the user's requests.
|
||||
|
||||
BEFORE YOU MAKE CHANGES TO THE CODE ASK ANY QUESTIONS YOU NEED TO UNDERSTAND THE USER'S REQUEST.
|
||||
ASK QUESTIONS IF YOU NEED HELP UNDERSTANDING THE CODE.
|
||||
ASK THE USER QUESTIONS IF YOU NEED HELP UNDERSTANDING THE CODE.
|
||||
Ask all the questions you need to fully understand what needs to be done.
|
||||
|
||||
ONLY RETURN CODE USING THESE COMMANDS:
|
||||
YOU MUST ONLY RETURN CODE USING THESE COMMANDS:
|
||||
- CHANGE
|
||||
- DELETE
|
||||
- APPEND
|
||||
- PREPEND
|
||||
|
||||
** This is how to use the CHANGE command:
|
||||
|
||||
|
@ -58,12 +71,20 @@ DELETE filename.ext
|
|||
|
||||
** This is how to use the APPEND command:
|
||||
|
||||
APPEND filename.ext APPEND
|
||||
APPEND filename.ext
|
||||
```
|
||||
... lines to add ...
|
||||
... at the end of the file ...
|
||||
```
|
||||
|
||||
** This is how to use the PREPEND command:
|
||||
|
||||
PREPEND filename.ext
|
||||
```
|
||||
... lines to add ...
|
||||
... at the start of the file ...
|
||||
```
|
||||
|
||||
'''
|
||||
|
||||
prompt_comments = '''
|
||||
|
@ -180,7 +201,7 @@ class Coder:
|
|||
while True:
|
||||
content = self.send(messages)
|
||||
inp = input()
|
||||
inp += '\n(Remember if you want to output code, be sure to a correctly formatted CHANGE, DELETE, APPEND command)'
|
||||
#inp += '\n(Remember if you want to output code, be sure to a correctly formatted CHANGE, DELETE, APPEND command)'
|
||||
message = dict(role = 'user', content = inp)
|
||||
messages.append(message)
|
||||
|
||||
|
@ -233,10 +254,12 @@ coder = Coder()
|
|||
|
||||
coder.system(prompt_webdev)
|
||||
|
||||
dname = Path('../easy-chat')
|
||||
coder.file(dname / 'index.html')
|
||||
coder.file(dname / 'chat.css')
|
||||
coder.file(dname / 'chat.js')
|
||||
coder.file(Path('coder.py'))
|
||||
|
||||
#dname = Path('../easy-chat')
|
||||
#coder.file(dname / 'index.html')
|
||||
#coder.file(dname / 'chat.css')
|
||||
#coder.file(dname / 'chat.js')
|
||||
|
||||
#for fname in coder.fnames:
|
||||
# print(coder.quoted_file(fname))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue