From 6638efbee42d526d238f615ee3f44ee47b61c037 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 14 May 2024 06:02:16 -0700 Subject: [PATCH] better prompting for LLM to suggest files --- aider/coders/base_coder.py | 5 ++++- aider/coders/base_prompts.py | 3 ++- aider/coders/editblock_coder.py | 2 +- aider/coders/editblock_prompts.py | 4 ++-- aider/prompts.py | 4 +++- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 3b05b90b4..de8e11b49 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -448,7 +448,10 @@ class Coder: files_reply = "Ok, any changes I propose will be to those files." elif repo_content: files_content = self.gpt_prompts.files_no_full_files_with_repo_map - files_reply = "Ok, based on your requests I will suggest which files need to be edited." + files_reply = ( + "Ok, based on your requests I will suggest which files need to be edited and then" + " stop and wait for your approval." + ) else: files_content = self.gpt_prompts.files_no_full_files files_reply = "Ok." diff --git a/aider/coders/base_prompts.py b/aider/coders/base_prompts.py index 7d12ef308..f00d090e9 100644 --- a/aider/coders/base_prompts.py +++ b/aider/coders/base_prompts.py @@ -20,7 +20,8 @@ You always COMPLETELY IMPLEMENT the needed code! files_no_full_files = "I am not sharing any files that you can edit yet." - files_no_full_files_with_repo_map = """Tell me which files in my repo are the most likely to **need changes** to solve the requests I make. + files_no_full_files_with_repo_map = """Don't try and edit any existing code without asking me to add the files to the chat! +Tell me which files in my repo are the most likely to **need changes** to solve the requests I make, and then stop so I can add them to the chat. Only include the 1-2 files that are most likely to actually need to be edited. Don't include files that might contain relevant context, just files that will need to be changed. """ # noqa: E501 diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index 8d710c196..159435e8a 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -478,7 +478,7 @@ Hope you like it! print(list(find_original_update_blocks(edit))) -def find_similar_lines(search_lines, content_lines, threshold=0.9): +def find_similar_lines(search_lines, content_lines, threshold=0.8): search_lines = search_lines.splitlines() content_lines = content_lines.splitlines() diff --git a/aider/coders/editblock_prompts.py b/aider/coders/editblock_prompts.py index 08b985089..64c2f0051 100644 --- a/aider/coders/editblock_prompts.py +++ b/aider/coders/editblock_prompts.py @@ -14,7 +14,7 @@ If the request is ambiguous, ask questions. Always reply to the user in the same language they are using. Once you understand the request you MUST: -1. List the files you need to modify. Only suggest changes to files that the user says you can edit. Before changing other files, you *MUST* tell the user their full path names and ask them to *add the files to the chat*. End your reply and wait for their approval. +1. Decide if you need to propose *SEARCH/REPLACE* edits to any files that haven't been added to the chat. You can create new files without asking. But if you need to propose edits to existing files not already added to the chat, you *MUST* tell the user their full path names and ask them to *add the files to the chat*. End your reply and wait for their approval. You can keep asking if you then decide you need to edit more files. 2. Think step-by-step and explain the needed changes with a numbered list of short sentences. 3. Describe each change with a *SEARCH/REPLACE block* per the examples below. All changes to files must use this *SEARCH/REPLACE block* format. ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! @@ -126,7 +126,7 @@ Every *SEARCH* section must *EXACTLY MATCH* the existing source code, character Include *ALL* the code being searched and replaced! -Only *SEARCH/REPLACE* files that the user says you can edit. +Only create *SEARCH/REPLACE* blocks for files that the user has added to the chat! To move code within a file, use 2 *SEARCH/REPLACE* blocks: 1 to delete it from its current location, 1 to insert it in the new location. diff --git a/aider/prompts.py b/aider/prompts.py index e747f8470..10089c90c 100644 --- a/aider/prompts.py +++ b/aider/prompts.py @@ -17,7 +17,9 @@ undo_command_reply = ( " why the changes were reverted." ) -added_files = "I added these files to the chat: {fnames}" +added_files = """I added these files to the chat: {fnames}. + +If you need to propose edits to other existing files not already added to the chat, you *MUST* tell the me their full path names and ask me to *add the files to the chat*. End your reply and wait for my approval. You can keep asking if you then decide you need to edit more files.""" run_output = """I ran this command: