From 85c902843a090812701fd0eb5aadfef1f3902061 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Tue, 9 May 2023 00:00:48 -0700 Subject: [PATCH] Move `quoted_file` function from `coder.py` to `utils.py` and update `get_files_content` function in `coder.py` to use `utils.quoted_file`. # Context: USER: move quoted_file to utils ASSISTANT: To move the `quoted_file` function from `coder.py` to `utils.py`, we will remove it from `coder.py` and add it to `utils.py`. ```python coder.py <<<<<<< ORIGINAL def quoted_file(self, fname): prompt = "\n" prompt += fname prompt += "\n```\n" prompt += Path(fname).read_text() prompt += "\n```\n" return prompt def get_files_content(self): prompt = "" for fname in self.fnames: prompt += self.quoted_file(fname) return prompt ======= def get_files_content(self): prompt = "" for fname in self.fnames: prompt += utils.quoted_file(fname) return prompt >>>>>>> UPDATED ``` ```python utils.py <<<<<<< ORIGINAL def strip_quoted_wrapping(res, fname=None): if not res: return res res = res.splitlines() if fname and res[0].strip().endswith(Path(fname).name): res = res[1:] if res[0].startswith("```") and res[-1].startswith("```"): res = res[1:-1] res = "\n".join(res) if res and res[-1] != "\n": res += "\n" return res ======= def quoted_file(fname): prompt = "\n" prompt += fname prompt += "\n```\n" prompt += Path(fname).read_text() prompt += "\n```\n" return prompt def strip_quoted_wrapping(res, fname=None): if not res: return res res = res.splitlines() if fname and res[0].strip().endswith(Path(fname).name): res = res[1:] if res[0].startswith("```") and res[-1].startswith("```"): res = res[1:-1] res = "\n".join(res) if res and res[-1] != "\n": res += "\n" return res >>>>>>> UPDATED ``` Now the `quoted_file` function has been moved to `utils.py`, and the `get_files_content` function in `coder.py` has been updated to use `utils.quoted_file`. --- coder.py | 11 +---------- utils.py | 10 +++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/coder.py b/coder.py index 671342e11..ed44c6234 100755 --- a/coder.py +++ b/coder.py @@ -111,20 +111,11 @@ class Coder: self.repo = repo - def quoted_file(self, fname): - prompt = "\n" - prompt += fname - prompt += "\n```\n" - prompt += Path(fname).read_text() - prompt += "\n```\n" - return prompt - def get_files_content(self): prompt = "" for fname in self.fnames: - prompt += self.quoted_file(fname) + prompt += utils.quoted_file(fname) return prompt - def get_input(self): if self.pretty: self.console.rule() diff --git a/utils.py b/utils.py index 5e539f5aa..c110a8295 100644 --- a/utils.py +++ b/utils.py @@ -44,6 +44,14 @@ def replace_most_similar_chunk(whole, part, replace): return modified_whole +def quoted_file(fname): + prompt = "\n" + prompt += fname + prompt += "\n```\n" + prompt += Path(fname).read_text() + prompt += "\n```\n" + return prompt + def strip_quoted_wrapping(res, fname=None): if not res: return res @@ -60,4 +68,4 @@ def strip_quoted_wrapping(res, fname=None): if res and res[-1] != "\n": res += "\n" - return res + return res \ No newline at end of file