From e9f0c0ced24f47dcc9b4453acbd362bbc56ff4e0 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sun, 7 May 2023 20:40:17 -0700 Subject: [PATCH] different user msgs for initial, local and gpt edits --- coder.py | 43 +++++++++++++++++++++++++------------------ prompts.py | 29 +++++++++++++++++------------ 2 files changed, 42 insertions(+), 30 deletions(-) diff --git a/coder.py b/coder.py index e00eb02c3..a9e6dcc48 100755 --- a/coder.py +++ b/coder.py @@ -45,14 +45,16 @@ class Coder: fnames = dict() last_modified = 0 - def __init__(self, use_gpt_4): + def __init__(self, use_gpt_4, files): if use_gpt_4: self.main_model = "gpt-4" else: self.main_model = "gpt-3.5-turbo" - def add_file(self, fname): - self.fnames[fname] = Path(fname).stat().st_mtime + for fname in files: + self.fnames[fname] = Path(fname).stat().st_mtime + + self.check_for_local_edits(True) def files_modified(self): for fname, mtime in self.fnames.items(): @@ -98,19 +100,26 @@ class Coder: readline.write_history_file(history_file) return inp - def set_files_messages(self, did_edits=False): + def check_for_local_edits(self, init=False): last_modified = max(Path(fname).stat().st_mtime for fname in self.fnames) - if last_modified <= self.last_modified: - return - did_edits = self.last_modified > 0 - + since = last_modified - self.last_modified self.last_modified = last_modified - print("Reloading files...") + if init: + return + if since > 0: + return True + return False + def set_files_messages(self, did_edits=None): if did_edits: - files_content = prompts.files_content_prefix_edited + print("Reloading files...") + + if did_edits == "gpt": + files_content = prompts.files_content_prefix_gpt_edits + elif did_edits == "local": + files_content = prompts.files_content_prefix_local_edits else: - files_content = prompts.files_content_prefix_plain + files_content = prompts.files_content_prefix_initial files_content += self.get_files_content() files_content += prompts.files_content_suffix @@ -132,8 +141,9 @@ class Coder: if inp is None: return - if self.set_files_messages(): + if self.check_for_local_edits(): # files changed, move cur messages back behind the files messages + self.set_files_messages("local") self.done_messages += self.cur_messages self.cur_messages = [] @@ -173,7 +183,8 @@ class Coder: if not edited: continue - self.set_files_messages(True) + self.check_for_local_edits(True) + self.set_files_messages("gpt") self.done_messages += self.cur_messages self.cur_messages = [] @@ -409,13 +420,9 @@ def main(): args = parser.parse_args() use_gpt_4 = not args.gpt_3_5_turbo - coder = Coder(use_gpt_4) - fnames = args.files - for fname in fnames: - coder.add_file(fname) - + coder = Coder(use_gpt_4, fnames) coder.run() diff --git a/prompts.py b/prompts.py index 42290120b..8daae2b89 100644 --- a/prompts.py +++ b/prompts.py @@ -1,4 +1,3 @@ - ### MAIN main_system = ''' @@ -36,39 +35,45 @@ ONLY REPLY WITH CODE IN ORIGINAL/UPDATED FORMAT CHANGES SHOWN ABOVE! NEVER REPLY WITH AN ENTIRE FILE! ''' -returned_code = ''' +returned_code = """ It looks like you tried to return a code block. Don't do that! Only return code using the specific ORIGINAL/UPDATED format. Be selective! Only return the parts of the code which need changes! -''' +""" -system_reminder = 'REMEMBER, ONLY RETURN CODE USING THE ORIGINAL/UPDATED FORMAT!' +system_reminder = "REMEMBER, ONLY RETURN CODE USING THE ORIGINAL/UPDATED FORMAT!" ### FILES -files_content_prefix_edited = 'I made your suggested changes, here are the updated files:\n\n' +files_content_prefix_gpt_edits = ( + "I made your suggested changes, here are the updated files:\n\n" +) -files_content_prefix_plain = 'Here are the files:\n\n' +files_content_prefix_local_edits = ( + "I made some changes to the files, here are the updated files:\n\n" +) -files_content_suffix = ''' +files_content_prefix_initial = "Here are the files:\n\n" + +files_content_suffix = """ BASE ANY EDITS ON THE CURRENT CONTENTS OF THE FILES AS SHOWN IN THIS MESSAGE. -''' +""" ### EDITOR -editor_system = ''' +editor_system = """ You are an expert code editor. Perform the requested edit. Output ONLY the new version of the file. Just that one file. Do not output explanations! Do not wrap the output in ``` delimiters. -''' +""" -editor_user = ''' +editor_user = """ To complete this request: {request} @@ -85,4 +90,4 @@ To this file: ``` ONLY OUTPUT {fname} !!! -''' +"""