From d50b4c4de25f0a066648381163ac8b42c9304fa3 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 2 May 2023 19:31:15 -0700 Subject: [PATCH] gpt-4 --- coder.py | 17 +++++++++-------- prompts.py | 37 +++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/coder.py b/coder.py index 2ad3ef599..84362be3f 100755 --- a/coder.py +++ b/coder.py @@ -163,10 +163,10 @@ class Coder: edited_message = 'ORIGINAL/UPDATED formatted changes: ' edited_message += ', '.join(edited) edited_message += '' - cur_messages.pop() - cur_messages += [ - dict(role = 'user', content = edited_message), - ] + #cur_messages.pop() + #cur_messages += [ + # dict(role = 'user', content = edited_message), + #] done_messages += cur_messages cur_messages = [] @@ -184,12 +184,12 @@ class Coder: for line in content: print(role, line) - def send(self, messages, show_progress = 0): + def send(self, messages, show_progress = 0, model="gpt-4"): #self.show_messages(messages, "all") completion = openai.ChatCompletion.create( #model="gpt-3.5-turbo", - model="gpt-4", + model=model, messages=messages, temperature=0, stream = True, @@ -334,7 +334,8 @@ class Coder: return True def do_gpt_powered_replace(self, fname, edit, request): - print(f'Asking GPT to apply ambiguous edit to {fname}...') + model = 'gpt-3.5-turbo' + print(f'Asking {model} to apply ambiguous edit to {fname}...') fname = Path(fname) content = fname.read_text() @@ -349,7 +350,7 @@ class Coder: dict(role = 'system', content = prompts.editor_system), dict(role = 'user', content = prompt), ] - res = self.send(messages, show_progress = len(content) + len(edit)/2) + res = self.send(messages, show_progress = len(content) + len(edit)/2, model=model) res = self.strip_quoted_wrapping(res, fname) fname.write_text(res) diff --git a/prompts.py b/prompts.py index 49dfd9b1f..32f290b41 100644 --- a/prompts.py +++ b/prompts.py @@ -7,32 +7,29 @@ I want you to act as an expert software engineer and pair programmer. You are to take requests from the user for new features, improvements, bug fixes and other changes to the code. If the user's request is ambiguous, ask questions to fully understand. -# For each change to the code, describe it using the ORIGINAL/UPDATED format shown in the examples below. +Once you understand each change, your responses must be: -First line is the full filename, including path -Next line is exactly: <<<<<<< ORIGINAL -Followed by a chunk of lines from the original file which need to change -Next line is exactly: ======= -Followed by the new lines to replace the original chunk -Last line is exactly: >>>>>>> UPDATED +1. Once you understand the question, briefly explain the needed changes. +2. For each change to the code, describe it using the ORIGINAL/UPDATED format shown in the examples below. -# Here are examples: - -path/to/filename.ext +some/dir/names/example.py <<<<<<< ORIGINAL -original lines -to search for +# Main functions +# + # Function to multiply two numbers + def mul(a,b) + """ ======= -new lines to replace -the original chunk +# Main functions +# + # Function to multiply two numbers using the standard algorithm + def mul(a,b) + """ >>>>>>> UPDATED -example.py -<<<<<<< ORIGINAL -# Function to multiply two numbers -======= -# Function to multiply two numbers using the standard algorithm ->>>>>>> UPDATED +Be sure to include the correct path and filename for each edit, exactly as specified by the user. +LEADING WHITESPACE IS IMPORTANT IN ALL CODE! +NEVER RETURN THE ENTIRE SOURCE FILE. ONLY RETURN CODE IN ORIGINAL/UPDATED FORMAT CHANGES! ''' returned_code = '''