Roughed in updated sys msg for whole format

This commit is contained in:
Paul Gauthier 2023-06-25 15:27:06 -07:00
parent 976f84bac5
commit f005404ec0
3 changed files with 29 additions and 10 deletions

View file

@ -273,7 +273,7 @@ class Coder:
] ]
if self.abs_fnames: if self.abs_fnames:
files_messages += [ files_messages += [
dict(role="system", content=self.gpt_prompts.system_reminder), dict(role="system", content=self.fmt_system_reminder()),
] ]
return files_messages return files_messages
@ -355,6 +355,25 @@ class Coder:
return self.send_new_user_message(inp) 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): def send_new_user_message(self, inp):
self.cur_messages += [ self.cur_messages += [
dict(role="user", content=inp), dict(role="user", content=inp),
@ -362,7 +381,7 @@ class Coder:
main_sys = self.gpt_prompts.main_system main_sys = self.gpt_prompts.main_system
if self.main_model.max_context_tokens > 4 * 1024: 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 = [ messages = [
dict(role="system", content=main_sys), dict(role="system", content=main_sys),

View file

@ -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. 3. If changes are needed, output a copy of each file that needs changes.
""" """
system_reminder = """ system_reminder = """To return code you MUST use this *file listing* format:
To return code you MUST use this *file listing* format:
path/to/filename.js path/to/filename.js
```javascript {fence}javascript
// entire file content goes in the // entire file content goes in the
// triple backticked fenced block // triple backticked fenced block
``` {fence}
Every *file listing* MUST use this format: Every *file listing* MUST use this format:
- First line: the filename with any required path! - First line: the filename with any required path!
- Second line: opening triple backtick fence with the correct code language. - Second line: opening {num_ticks} backtick fence with the correct code language.
- Final line: closing triple backtick fence. - 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. 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. Create a new file you MUST return a *file listing* which includes an appropriate filename, including any required path.

View file

@ -6,7 +6,7 @@ from .dump import dump # noqa: F401
def quoted_file(fname, display_fname, number=False): def quoted_file(fname, display_fname, number=False):
prompt = "\n" prompt = "\n"
prompt += display_fname prompt += display_fname
prompt += "\n```\n" prompt += "\n````\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 +14,7 @@ def quoted_file(fname, display_fname, number=False):
prompt += f"{i:4d} " prompt += f"{i:4d} "
prompt += line + "\n" prompt += line + "\n"
prompt += "```\n" prompt += "````\n"
return prompt return prompt