From aebdb332a05866f32ddbf46a90dc7ef6ee2d9be8 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 11 Apr 2023 12:30:58 -0700 Subject: [PATCH] works --- coder.py | 7 +++++-- prompts.py | 35 +++++++---------------------------- 2 files changed, 12 insertions(+), 30 deletions(-) diff --git a/coder.py b/coder.py index aec576661..f9d7ff3e0 100755 --- a/coder.py +++ b/coder.py @@ -159,8 +159,9 @@ class Coder: files_messages = self.get_files_messages(True) - edited_message = 'You need to edit these files: ' + edited_message = 'ORIGINAL/UPDATED formatted changes: ' edited_message += ', '.join(edited) + edited_message += '' cur_messages.pop() cur_messages += [ dict(role = 'assistant', content = edited_message), @@ -224,6 +225,8 @@ class Coder: partial_line = '' for chunk in completion: + if chunk.choices[0].finish_reason: + dump(chunk.choices[0].finish_reason) try: text = chunk.choices[0].delta.content resp += text @@ -291,7 +294,7 @@ class Coder: return ''.join(resp) - pattern = re.compile(r'^(\S+)\n<<<<<<< ORIGINAL\n(.*?)\n=======\n(.*?)\n>>>>>>> UPDATED$', re.MULTILINE | re.DOTALL) + pattern = re.compile(r'^(\S+)\s+<<<<<<< ORIGINAL\n(.*?)\n=======\n(.*?)\n>>>>>>> UPDATED$', re.MULTILINE | re.DOTALL) def update_files(self, content, inp): diff --git a/prompts.py b/prompts.py index abae6d065..4d18c8de4 100644 --- a/prompts.py +++ b/prompts.py @@ -3,7 +3,9 @@ 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. + +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. @@ -34,34 +36,11 @@ example.py ''' returned_code = ''' -It looks like you tried to return code. Don't do that! +It looks like you tried to return a code block. Don't do that! -Only return code using the specific ORIGINAL/UPDATED format shown in the examples below. - -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 - -Here are examples: - -path/to/filename.ext -<<<<<<< ORIGINAL -original lines -to search for -======= -new lines to replace -the original chunk ->>>>>>> UPDATED - -example.py -<<<<<<< ORIGINAL -# Function to multiply two numbers -======= -# Function to multiply two numbers using the standard algorithm ->>>>>>> UPDATED +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!'