From f256b430431e5028b447457d2f9c3bc77dea0bf4 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 8 May 2024 13:35:34 -0700 Subject: [PATCH] wip --- aider/args.py | 6 ++++++ aider/coders/base_coder.py | 1 + aider/coders/base_prompts.py | 10 ++++++++++ aider/coders/editblock_prompts.py | 13 ++----------- aider/coders/udiff_prompts.py | 9 --------- aider/coders/wholefile_prompts.py | 10 ---------- aider/main.py | 7 ++++++- aider/repomap.py | 11 +++++++++-- 8 files changed, 34 insertions(+), 33 deletions(-) diff --git a/aider/args.py b/aider/args.py index b298fd8f8..f77831679 100644 --- a/aider/args.py +++ b/aider/args.py @@ -338,6 +338,12 @@ def get_parser(default_config_files, git_root): help="Print the repo map and exit (debug)", default=False, ) + group.add_argument( + "--show-prompts", + action="store_true", + help="Print the system prompts and exit (debug)", + default=False, + ) group.add_argument( "--message", "--msg", diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 3279e1e3d..e98a715cb 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -415,6 +415,7 @@ class Coder: all_content = "" repo_content = self.get_repo_map() + if repo_content: if all_content: all_content += "\n" diff --git a/aider/coders/base_prompts.py b/aider/coders/base_prompts.py index 5e42c60c8..30779f12a 100644 --- a/aider/coders/base_prompts.py +++ b/aider/coders/base_prompts.py @@ -13,3 +13,13 @@ You always COMPLETELY IMPLEMENT the needed code! """ example_messages = [] + + files_content_prefix = "These are files that you can edit:\n" + + files_no_full_files = "I am not sharing any files that you can edit yet." + + repo_content_prefix = """I'm discussing files that are part of a git repository. +Here are summaries of some files present in my git repo. +Do not propose changes to these files, treat them as *read-only*. +If you need to edit one of them, ask me to *add it to the chat* first. +""" diff --git a/aider/coders/editblock_prompts.py b/aider/coders/editblock_prompts.py index 22f5be45b..29533c0dd 100644 --- a/aider/coders/editblock_prompts.py +++ b/aider/coders/editblock_prompts.py @@ -12,7 +12,7 @@ Take requests for changes to the supplied code. If the request is ambiguous, ask questions. Once you understand the request you MUST: -1. List the files you need to modify. Only suggest changes to a *read-write* files. Before changing *read-only* 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. List the files you need to modify. Only suggest changes to files that the user has given you permission to edit. 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*! @@ -125,7 +125,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 are *read-write*. +Only *SEARCH/REPLACE* files that the user has given you permission to edit. 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. @@ -136,13 +136,4 @@ If you want to put code in a new file, use a *SEARCH/REPLACE block* with: {lazy_prompt} ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*! -""" - - files_content_prefix = "These are the *read-write* files:\n" - - files_no_full_files = "I am not sharing any *read-write* files yet." - - repo_content_prefix = """Below here are summaries of files present in the user's git repository. -Do not propose changes to these files, they are *read-only*. -To make a file *read-write*, ask the user to *add it to the chat*. """ diff --git a/aider/coders/udiff_prompts.py b/aider/coders/udiff_prompts.py index 3c9058632..0975c0076 100644 --- a/aider/coders/udiff_prompts.py +++ b/aider/coders/udiff_prompts.py @@ -105,13 +105,4 @@ To move code within a file, use 2 hunks: 1 to delete it from its current locatio To make a new file, show a diff from `--- /dev/null` to `+++ path/to/new/file.ext`. {lazy_prompt} -""" - - files_content_prefix = "These are the *read-write* files:\n" - - files_no_full_files = "I am not sharing any *read-write* files yet." - - repo_content_prefix = """Below here are summaries of some files present in this git repository. -Do not propose changes to these files, they are *read-only*. -To make a file *read-write*, ask the user to *add it to the chat*. """ diff --git a/aider/coders/wholefile_prompts.py b/aider/coders/wholefile_prompts.py index 60d4f6795..f7b67fea8 100644 --- a/aider/coders/wholefile_prompts.py +++ b/aider/coders/wholefile_prompts.py @@ -61,14 +61,4 @@ Create a new file you MUST return a *file listing* which includes an appropriate {lazy_prompt} """ - files_content_prefix = "Here is the current content of the files:\n" - files_no_full_files = "I am not sharing any files yet." - redacted_edit_message = "No changes are needed." - - # this coder is not able to handle repo content - repo_content_prefix = None - - repo_content_prefix = """Below here are summaries of files present in the user's git repository. -Do not propose changes to these files, they are *read-only*. -""" diff --git a/aider/main.py b/aider/main.py index 57f0f530b..6c23258b3 100644 --- a/aider/main.py +++ b/aider/main.py @@ -7,7 +7,7 @@ import git from dotenv import load_dotenv from streamlit.web import cli -from aider import __version__, models +from aider import __version__, models, utils from aider.args import get_parser from aider.coders import Coder from aider.commands import SwitchModel @@ -341,6 +341,11 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F coder.show_announcements() + if args.show_prompts: + messages = coder.format_messages() + utils.show_messages(messages) + return + if args.commit: coder.commands.cmd_commit("") return diff --git a/aider/repomap.py b/aider/repomap.py index bc918936a..29f4fdc35 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -68,6 +68,9 @@ class RepoMap: self.io.tool_error("Disabling repo map, git repo too large?") self.max_map_tokens = 0 return + + dump(chat_files, other_files) + dump(files_listing) if not files_listing: return @@ -87,6 +90,7 @@ class RepoMap: repo_content += files_listing + dump(repo_content) return repo_content def get_rel_fname(self, fname): @@ -258,8 +262,8 @@ class RepoMap: references[tag.name].append(rel_fname) ## - # dump(defines) - # dump(references) + dump(defines) + dump(references) if not references: references = dict((k, list(v)) for k, v in defines.items()) @@ -287,6 +291,7 @@ class RepoMap: try: ranked = nx.pagerank(G, weight="weight", **pers_args) except ZeroDivisionError: + dump(ZeroDivisionError) return [] # distribute the rank from each source node, across all of its out edges @@ -334,6 +339,8 @@ class RepoMap: ranked_tags = self.get_ranked_tags(chat_fnames, other_fnames) num_tags = len(ranked_tags) + dump(num_tags) + lower_bound = 0 upper_bound = num_tags best_tree = None