diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 1852d8d80..5e99950fd 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -273,7 +273,7 @@ class Coder: ] if self.abs_fnames: files_messages += [ - dict(role="system", content=self.gpt_prompts.system_reminder), + dict(role="system", content=self.fmt_system_reminder()), ] return files_messages @@ -355,6 +355,25 @@ class Coder: return self.send_new_user_message(inp) + num_ticks = 4 + + def fmt_system_reminder(self): + prompt = self.gpt_prompts.system_reminder + num_ticks = self.num_ticks + + explain = f""" +You *MUST* use {num_ticks} backticks, because some files contain {num_ticks-1} backticks already!""" + + fence = "`" * num_ticks + + prompt = prompt.format( + num_ticks=num_ticks, + fence=fence, + num_ticks_explanation=explain, + ) + + return prompt + def send_new_user_message(self, inp): self.cur_messages += [ dict(role="user", content=inp), @@ -362,7 +381,7 @@ class Coder: main_sys = self.gpt_prompts.main_system if self.main_model.max_context_tokens > 4 * 1024: - main_sys += "\n" + self.gpt_prompts.system_reminder + main_sys += "\n" + self.fmt_system_reminder() messages = [ dict(role="system", content=main_sys), diff --git a/aider/coders/wholefile_prompts.py b/aider/coders/wholefile_prompts.py index eaf1f3e9b..26680098c 100644 --- a/aider/coders/wholefile_prompts.py +++ b/aider/coders/wholefile_prompts.py @@ -14,19 +14,19 @@ Once you understand the request you MUST: 3. If changes are needed, output a copy of each file that needs changes. """ - system_reminder = """ -To return code you MUST use this *file listing* format: + system_reminder = """To return code you MUST use this *file listing* format: path/to/filename.js -```javascript +{fence}javascript // entire file content goes in the // triple backticked fenced block -``` +{fence} Every *file listing* MUST use this format: - First line: the filename with any required path! -- Second line: opening triple backtick fence with the correct code language. -- Final line: closing triple backtick fence. +- Second line: opening {num_ticks} backtick fence with the correct code language. +- Final line: closing {num_ticks} backtick fence. +{num_ticks_explanation} To suggest changes to a file you MUST return a *file listing* that contains the entire content of the file. Create a new file you MUST return a *file listing* which includes an appropriate filename, including any required path. diff --git a/aider/utils.py b/aider/utils.py index e23d6b866..10fdc5a07 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -6,7 +6,7 @@ from .dump import dump # noqa: F401 def quoted_file(fname, display_fname, number=False): prompt = "\n" prompt += display_fname - prompt += "\n```\n" + prompt += "\n````\n" file_content = Path(fname).read_text() lines = file_content.splitlines() for i, line in enumerate(lines, start=1): @@ -14,7 +14,7 @@ def quoted_file(fname, display_fname, number=False): prompt += f"{i:4d} " prompt += line + "\n" - prompt += "```\n" + prompt += "````\n" return prompt