From 2339dd480313030f6b1cab2136815959959c5c6e Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 10 May 2023 09:24:27 -0700 Subject: [PATCH] aider: Added `display_fname` arg to `quoted_file` and updated call to `quoted_file` to pass relative file path. # Context: USER: add a display_fname arg to quoted_file. add it, not fname, into the prompt. change the call to quoted_file to pass along the fname relative to self.root ASSISTANT: To add a `display_fname` argument to the `quoted_file` function and update the call to `quoted_file`, follow these changes: 1. Add the `display_fname` argument to the `quoted_file` function definition. 2. Replace `fname` with `display_fname` in the prompt string. 3. Update the call to `quoted_file` in the `get_files_content` method to pass the relative file path. Here are the code changes: ```python aider/utils.py <<<<<<< ORIGINAL def quoted_file(fname): prompt = "\n" prompt += fname ======= def quoted_file(fname, display_fname): prompt = "\n" prompt += display_fname >>>>>>> UPDATED prompt += "\n```\n" prompt += Path(fname).read_text() prompt += "\n```\n" return prompt ``` ```python aider/coder.py <<<<<<< ORIGINAL for fname in self.fnames: prompt += utils.quoted_file(fname) ======= for fname in self.fnames: relative_fname = os.path.relpath(fname, self.root) prompt += utils.quoted_file(fname, relative_fname) >>>>>>> UPDATED return prompt ``` --- aider/coder.py | 3 ++- aider/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/aider/coder.py b/aider/coder.py index 776672715..378d8124a 100755 --- a/aider/coder.py +++ b/aider/coder.py @@ -132,7 +132,8 @@ class Coder: def get_files_content(self): prompt = "" for fname in self.fnames: - prompt += utils.quoted_file(fname) + relative_fname = os.path.relpath(fname, self.root) + prompt += utils.quoted_file(fname, relative_fname) return prompt def get_last_modified(self): diff --git a/aider/utils.py b/aider/utils.py index 00529393a..2d68f2cda 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -45,9 +45,9 @@ def replace_most_similar_chunk(whole, part, replace): return modified_whole -def quoted_file(fname): +def quoted_file(fname, display_fname): prompt = "\n" - prompt += fname + prompt += display_fname prompt += "\n```\n" prompt += Path(fname).read_text() prompt += "\n```\n"