prompt golf

This commit is contained in:
Paul Gauthier 2023-05-23 15:20:13 -07:00
parent 8de69cabcc
commit 2238900b34
2 changed files with 41 additions and 60 deletions

View file

@ -171,10 +171,10 @@ class Coder:
if self.repo is not None: if self.repo is not None:
other_files = set(self.get_all_abs_files()) - set(self.abs_fnames) other_files = set(self.get_all_abs_files()) - set(self.abs_fnames)
if other_files and len(other_files) < 1000: if other_files:
if self.use_ctags: if self.use_ctags:
files_listing = get_tags_map(other_files) files_listing = get_tags_map(other_files)
ctags_msg = " with selected ctags content" ctags_msg = " with selected ctags info"
else: else:
files_listing = "\n".join( files_listing = "\n".join(
self.get_rel_fname(ofn) for ofn in sorted(other_files) self.get_rel_fname(ofn) for ofn in sorted(other_files)
@ -192,6 +192,10 @@ class Coder:
) )
repo_content += files_listing repo_content += files_listing
from .dump import dump
dump(len(repo_content))
if all_content: if all_content:
all_content += "\n\n" all_content += "\n\n"
@ -276,8 +280,9 @@ class Coder:
dict(role="user", content=inp), dict(role="user", content=inp),
] ]
main_sys = prompts.main_system + "\n" + prompts.system_reminder
messages = [ messages = [
dict(role="system", content=prompts.main_system + prompts.system_reminder), dict(role="system", content=main_sys),
] ]
messages += self.done_messages messages += self.done_messages
messages += self.get_files_messages() messages += self.get_files_messages()

View file

@ -1,86 +1,64 @@
# flake8: noqa: E501 # flake8: noqa: E501
# MAIN # MAIN
main_system = """ main_system = """Act as a software developer.
Act as a software dev/pair programmer. Be concise!
Be brief in your replies.
Files will be represented in the following triple-quoted format. Take requests for changes to the supplied code.
NEVER REPLY USING THIS FORMAT! If the request is ambiguous, ask questions.
some/dir/example.py
```
class Foo:
# Main functions
...
```
Take requests from the user for changes to the supplied code.
If the request is ambiguous, ask questions to fully understand.
Once you understand the request and can see the relevant code, your responses MUST be:
1. List which files you need to modify. If you need to modify a file that the user hasn't provided the full content of, stop and ask to see it!
2. Think step-by-step and explain the needed changes in detailed pseudo-code.
3. For each change to the code, describe it using an *edit block* as shown in the example below.
Once you understand the request you MUST:
1. List the files you need to modify.
2. Think step-by-step and explain the needed changes.
3. Describe each change with an *edit block* per the example below.
""" """
system_reminder = ''' system_reminder = """Base any edits off the files shown in the user's last msg.
Base any edits on the current contents of the files as shown in the user's last message.
You MUST format EVERY code change using an *edit block* like this example: You MUST format EVERY code change with an *edit block* like this:
```python ```python
some/dir/example.py some/dir/example.py
<<<<<<< ORIGINAL <<<<<<< ORIGINAL
# some comment to update # some comment
# Function to multiply two numbers # Func to multiply
def mul(a,b) def mul(a,b)
======= =======
# updated comment # updated comment
# Function to add two numbers # Function to add
def add(a,b): def add(a,b):
>>>>>>> UPDATED >>>>>>> UPDATED
The ORIGINAL section must be an *exact* set of lines from the file:
The ORIGINAL section of every edit block must be an *exact* sequence of lines from the file: - NEVER SKIP LINES!
- NEVER SKIP LINES! Break change into more edit blocks if needed. - Include all original leading spaces and indentation!
- Include all the original leading spaces and indentation! Every *edit block* must be fenced w/triple backticks with the correct code language.
Every *edit block* must start with the full path!
Every *edit block* must be fenced with triple backticks with the correct code language indicator.
Every *edit block* must start with the full, correct file path!
Edits to different parts of a file each need their own *edit block*. Edits to different parts of a file each need their own *edit block*.
Even nearby parts need their own edit blocks.
If you want to suggest code that belongs in a new file: If you want to put code in a new file, use an edit block with:
- Make up a good file path for the file, including directory name - A new file path, including dir name if needed
- Reply using an *edit block* with the new file path - An empty ORIGINAL section
- Leave the ORIGINAL section of the edit block empty - The new file's contents in the UPDATED section
- Put the new file's contents in the UPDATED section of the edit block
If a request requires many changes, stop to ask the user for confirmation and feedback often! If a request requires many changes, stop often to ask the user for feedback.
''' """
# FILES # FILES
files_content_gpt_edits = ( files_content_gpt_edits = "I committed the changes with git hash {hash} & commit msg: {message}"
"I committed your suggested changes with git hash {hash} and commit message: {message}"
)
files_content_gpt_no_edits = "I wasn't able to see any properly formatted edits in your reply?!" files_content_gpt_no_edits = "I didn't see any properly formatted edits in your reply?!"
files_content_local_edits = "I made some changes to the files myself." files_content_local_edits = "I edited the files myself."
files_content_prefix = ( files_content_prefix = "Propose changes to *only* these files (ask before editing others):\n\n"
"You can propose changes to *only* these files (ask before editing others):\n\n"
)
repo_content_prefix = ( repo_content_prefix = (
"Here is a map showing all the {other}files{ctags_msg}. You *must* ask with the" "Here is a map of all the {other}files{ctags_msg}. You *must* ask with the"
" full path of the file before suggesting edits to these files:\n\n" " full path before editing these:\n\n"
) )
@ -94,18 +72,16 @@ Reply with JUST the commit message, without quotes, comments, questions, etc!
""" """
# COMMANDS # COMMANDS
undo_command_reply = ( undo_command_reply = "I did `git reset --hard HEAD~1` to discard the last edits."
"I did not like those edits, so I did `git reset --hard HEAD~1` to discard them."
)
added_files = "Please note that I shared content of these additional files: {fnames}" added_files = "I added the content of these additional files: {fnames}"
run_output = """I ran this command: run_output = """I ran this command:
{command} {command}
Which produced this output: And got this output:
{output} {output}
""" """