diff --git a/coder.py b/coder.py index e116492b7..8d3aa915b 100755 --- a/coder.py +++ b/coder.py @@ -67,7 +67,6 @@ class Coder: prompt = '' for fname in self.fnames: prompt += self.quoted_file(fname) - prompt += prompts.files_content_suffix return prompt def get_input(self): @@ -98,23 +97,26 @@ class Coder: return if did_edits: - files_prefix = prompts.files_content_prefix_edited + files_content = prompts.files_content_prefix_edited else: - files_prefix = prompts.files_content_prefix_plain + files_content = prompts.files_content_prefix_plain - files_prefix += '\n\n' + files_content += self.get_files_content() + files_content += prompts.files_content_suffix messages += [ - dict(role = 'user', content = files_prefix + self.get_files_content()), + dict(role = 'user', content = files_content), dict(role = 'assistant', content = "Ok."), - dict(role = 'user', content = inp), + dict(role = 'user', content = inp + prompts.user_suffix), ] content = self.send(messages) - user_msg = messages.pop() - messages.pop() - messages.pop() - messages.append(user_msg) + messages.pop() # user msg + messages.pop() # assistant Ok. + messages.pop() # user files content + + # put back the user message without prompts.user_suffix + messages.append(dict(role = 'user', content = inp)) messages.append(dict(role = 'assistant', content = content)) print() @@ -129,8 +131,8 @@ class Coder: traceback.print_exc() def send(self, messages, show_progress = 0): - #for msg in messages: - # dump(msg) + for msg in messages: + dump(msg) completion = openai.ChatCompletion.create( model="gpt-3.5-turbo", diff --git a/prompts.py b/prompts.py index 93acf347c..203619956 100644 --- a/prompts.py +++ b/prompts.py @@ -1,12 +1,10 @@ +### MAIN + main_system = ''' I want you to act as an expert software engineer and pair programmer. You are an expert at understanding code and proposing code changes in response to user requests. -Your job is to: - - Understand what the user wants. Ask questions if the user's request is not clear. - - Suggest changes to the code by performing search and replace using the syntax below. - FOR EACH CHANGE TO THE CODE, DESCRIBE IT USING THIS FORMAT: path/to/filename.ext @@ -18,9 +16,8 @@ new lines to replace the original chunk >>>>>>> UPDATED -ONLY USE THIS ORIGINAL/UPDATED FORMAT TO DESCRIBE CODE CHANGES! - -Example for how to just ADD lines to a file, without altering existing lines: +Here is an example for how to just ADD lines to a file, without altering existing lines. +This anchors the location of the new code in the file by including 2-3 lines from the. foo.py <<<<<<< ORIGINAL @@ -32,23 +29,27 @@ def foo(a): def bar(b): return b*b*b >>>>>>> UPDATED - -This anchors the location of the new code in the file by including 2-3 lines from the ORIGINAL file. -NEVER PUT AN ENTIRE FILE IN THE ORIGINAL BLOCK! MAKE YOUR EDITS SMALL AND SURGICAL! ''' -files_content_suffix = '''' +### FILES + +files_content_prefix_edited = 'I made your suggested changes, here are the updated files:\n\n' + +files_content_prefix_plain = 'Here are the files:\n\n' + +files_content_suffix = ''' YOU CAN ONLY EDIT THESE FILES. NEVER REPLY WITH WHOLE FILES LIKE THIS! -ONLY TELL ME CODE CHANGES USING ORIGINAL/UPDATED EDIT COMMANDS! ''' -files_content_prefix_edited = 'I made your suggested changes, here are the updated files:' - -files_content_prefix_plain = 'Here are the files:' +user_suffix = ''' +NEVER INCLUDE AN ENTIRE FILE IN YOUR REPLY! +ONLY TELL ME CODE CHANGES BY USING ORIGINAL/UPDATED EDIT COMMANDS! +''' +### EDITOR editor_system = ''' You are an expert code editor.