mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
abandon n-backticks, try some html fences
This commit is contained in:
parent
9151cf03a1
commit
96fda2aa9f
4 changed files with 22 additions and 34 deletions
|
@ -246,7 +246,7 @@ class Coder:
|
||||||
prompt = ""
|
prompt = ""
|
||||||
for fname in fnames:
|
for fname in fnames:
|
||||||
relative_fname = self.get_rel_fname(fname)
|
relative_fname = self.get_rel_fname(fname)
|
||||||
prompt += utils.quoted_file(fname, relative_fname, fence_ticks=self.get_fence_ticks())
|
prompt += utils.quoted_file(fname, relative_fname, fence=self.fence)
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
def get_files_messages(self):
|
def get_files_messages(self):
|
||||||
|
@ -355,31 +355,18 @@ class Coder:
|
||||||
|
|
||||||
return self.send_new_user_message(inp)
|
return self.send_new_user_message(inp)
|
||||||
|
|
||||||
num_ticks = 4
|
fences = [
|
||||||
|
("```", "```"),
|
||||||
|
("<source>", "</source>"),
|
||||||
|
("<code>", "</code>"),
|
||||||
|
("<pre>", "</pre>"),
|
||||||
|
]
|
||||||
|
|
||||||
def get_fence_ticks(self):
|
fence = fences[3]
|
||||||
return "`" * self.num_ticks
|
|
||||||
|
|
||||||
def fmt_system_reminder(self):
|
def fmt_system_reminder(self):
|
||||||
prompt = self.gpt_prompts.system_reminder
|
prompt = self.gpt_prompts.system_reminder
|
||||||
num_ticks = self.num_ticks
|
prompt = prompt.format(fence=self.fence)
|
||||||
|
|
||||||
explain = f"""
|
|
||||||
You *MUST* use {num_ticks} backticks, because some files contain {num_ticks-1} backticks already!"""
|
|
||||||
|
|
||||||
number_mapping = {
|
|
||||||
3: "triple",
|
|
||||||
# 4: "quadruple",
|
|
||||||
# 5: "quintuple",
|
|
||||||
}
|
|
||||||
num_ticks_name = number_mapping.get(num_ticks, str(num_ticks))
|
|
||||||
|
|
||||||
prompt = prompt.format(
|
|
||||||
num_ticks=num_ticks_name,
|
|
||||||
fence=self.get_fence_ticks(),
|
|
||||||
num_ticks_explanation=explain,
|
|
||||||
)
|
|
||||||
|
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
def send_new_user_message(self, inp):
|
def send_new_user_message(self, inp):
|
||||||
|
|
|
@ -36,7 +36,7 @@ class WholeFileCoder(Coder):
|
||||||
fname = None
|
fname = None
|
||||||
new_lines = []
|
new_lines = []
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if line.startswith(self.get_fence_ticks()):
|
if line.startswith(self.fence[0]) or line.startswith(self.fence[1]):
|
||||||
if fname is not None:
|
if fname is not None:
|
||||||
# ending an existing block
|
# ending an existing block
|
||||||
saw_fname = None
|
saw_fname = None
|
||||||
|
@ -79,7 +79,7 @@ class WholeFileCoder(Coder):
|
||||||
else:
|
else:
|
||||||
# TODO: sense which file it is by diff size
|
# TODO: sense which file it is by diff size
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"No filename provided before {self.get_fence_ticks()} in file listing"
|
f"No filename provided before {self.fence[0]} in file listing"
|
||||||
)
|
)
|
||||||
|
|
||||||
elif fname is not None:
|
elif fname is not None:
|
||||||
|
|
|
@ -18,16 +18,16 @@ Once you understand the request you MUST:
|
||||||
You MUST use this *file listing* format:
|
You MUST use this *file listing* format:
|
||||||
|
|
||||||
path/to/filename.js
|
path/to/filename.js
|
||||||
{fence}javascript
|
{fence[0]}
|
||||||
// entire file content goes in the
|
// entire file content ...
|
||||||
// {num_ticks} backtick fenced block
|
// ... goes in between
|
||||||
{fence}
|
{fence[1]}
|
||||||
|
|
||||||
Every *file listing* MUST use this format:
|
Every *file listing* MUST use this format:
|
||||||
- First line: the filename with any originally provided path
|
- First line: the filename with any originally provided path
|
||||||
- Second line: opening {num_ticks} backtick fence with the correct code language.
|
- Second line: opening {fence[0]}
|
||||||
- Final line: closing {num_ticks} backtick fence.
|
- ... entire content of the file ...
|
||||||
{num_ticks_explanation}
|
- Final line: closing {fence[1]}
|
||||||
|
|
||||||
To suggest changes to a file you MUST return a *file listing* that contains the entire content of the file.
|
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 appropriate path.
|
Create a new file you MUST return a *file listing* which includes an appropriate filename, including any appropriate path.
|
||||||
|
|
|
@ -3,10 +3,11 @@ from pathlib import Path
|
||||||
from .dump import dump # noqa: F401
|
from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
def quoted_file(fname, display_fname, fence_ticks="```", number=False):
|
def quoted_file(fname, display_fname, fence=("```", "```"), number=False):
|
||||||
prompt = "\n"
|
prompt = "\n"
|
||||||
prompt += display_fname
|
prompt += display_fname
|
||||||
prompt += f"\n{fence_ticks}\n"
|
prompt += f"\n{fence[0]}\n"
|
||||||
|
|
||||||
file_content = Path(fname).read_text()
|
file_content = Path(fname).read_text()
|
||||||
lines = file_content.splitlines()
|
lines = file_content.splitlines()
|
||||||
for i, line in enumerate(lines, start=1):
|
for i, line in enumerate(lines, start=1):
|
||||||
|
@ -14,7 +15,7 @@ def quoted_file(fname, display_fname, fence_ticks="```", number=False):
|
||||||
prompt += f"{i:4d} "
|
prompt += f"{i:4d} "
|
||||||
prompt += line + "\n"
|
prompt += line + "\n"
|
||||||
|
|
||||||
prompt += f"{fence_ticks}\n"
|
prompt += f"{fence[1]}\n"
|
||||||
return prompt
|
return prompt
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue