Skip to content

Commit d8cc0b6

Browse files
authored
feat: sonnet lazy apply prompt should not change comments (#8665)
* feat: sonnet lazy apply prompt should not change comments * change for ApplyManager.getApplyPrompt * change for ApplyToFileHandler.buildApplyPrompt * remove unused edit prompts in edit templates * add do not change comments to edit templates * tweak prompt to remove explicitly
1 parent fd4e931 commit d8cc0b6

File tree

5 files changed

+21
-34
lines changed

5 files changed

+21
-34
lines changed

core/edit/lazy/prompts.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ const RULES = [
1414
`Whenever any part of the code is the same as before, you may simply indicate this with a comment that says "${UNCHANGED_CODE}" instead of rewriting.`,
1515
"You must keep at least one line above and below from the original code, so that we can identify what the previous code was.",
1616
`Do not place miscellaneous "${UNCHANGED_CODE}" comments at the top or bottom of the file when there is nothing to replace them.`,
17+
"Leave existing comments in place unless changes require modifying them.",
1718
// `You should write "${UNCHANGED_CODE}" at least for each function that is unchanged, rather than grouping them into a single comment.`,
1819
// `You should lean toward using a smaller number of these comments rather than rewriting it for every function if all of them are unchanged.`,
1920
// `You may do this for imports as well if needed.`,
2021
// `Do not explain your changes either before or after the code block.`,
2122
"The code should always be syntactically valid, even with the comments.",
2223
];
2324

24-
function claude35SonnetLazyApplyPrompt(
25+
function claudeSonnetLazyApplyPrompt(
2526
...args: Parameters<LazyApplyPrompt>
2627
): ReturnType<LazyApplyPrompt> {
2728
const userContent = dedent`
@@ -55,7 +56,7 @@ export function lazyApplyPromptForModel(
5556
provider: string,
5657
): LazyApplyPrompt | undefined {
5758
if (model.includes("sonnet")) {
58-
return claude35SonnetLazyApplyPrompt;
59+
return claudeSonnetLazyApplyPrompt;
5960
}
6061

6162
return undefined;

core/llm/templates/edit.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ const simplifiedEditPrompt = `Consider the following code:
77
\`\`\`
88
Edit the code to perfectly satisfy the following user request:
99
{{{userInput}}}
10-
Output nothing except for the code. No code block, no English explanation, no start/end tags.`;
11-
12-
const simplestEditPrompt = `Here is the code before editing:
13-
\`\`\`{{{language}}}
14-
{{{codeToEdit}}}
15-
\`\`\`
16-
17-
Here is the edit requested:
18-
"{{{userInput}}}"
19-
20-
Here is the code after editing:`;
21-
22-
const codellamaInfillEditPrompt = "{{filePrefix}}<FILL>{{fileSuffix}}";
10+
Output nothing except for the code. No code block, no English explanation, no start/end tags. Leave existing comments in place unless changes require modifying them.`;
2311

2412
const START_TAG = "<START EDITING HERE>";
2513
const osModelsEditPrompt: PromptTemplate = (history, otherData) => {
@@ -55,7 +43,7 @@ ${otherData.codeToEdit}
5543
${suffixTag}
5644
\`\`\`
5745
58-
Please rewrite the entire code block above in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before.${suffixExplanation}`,
46+
Please rewrite the entire code block above in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before. Leave existing comments in place unless changes require modifying them.${suffixExplanation}`,
5947
},
6048
{
6149
role: "assistant",
@@ -75,7 +63,7 @@ ${otherData.codeToEdit}
7563
${suffixTag}
7664
\`\`\`
7765
78-
Please rewrite the entire code block above, editing the portion below "${START_TAG}" in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before.${suffixExplanation}
66+
Please rewrite the entire code block above, editing the portion below "${START_TAG}" in order to satisfy the following request: "${otherData.userInput}". You should rewrite the entire code block without leaving placeholders, even if the code is the same as before. Leave existing comments in place unless changes require modifying them.${suffixExplanation}
7967
`,
8068
},
8169
{
@@ -93,12 +81,12 @@ const mistralEditPrompt = `[INST] You are a helpful code assistant. Your task is
9381
{{{codeToEdit}}}
9482
\`\`\`
9583
96-
Just rewrite the code without explanations: [/INST]
84+
Leave existing comments in place unless changes require modifying them. Just rewrite the code without explanations: [/INST]
9785
\`\`\`{{{language}}}`;
9886

9987
const alpacaEditPrompt = `Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
10088
101-
### Instruction: Rewrite the code to satisfy this request: "{{{userInput}}}"
89+
### Instruction: Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
10290
10391
### Input:
10492
@@ -116,7 +104,7 @@ const phindEditPrompt = `### System Prompt
116104
You are an expert programmer and write code on the first attempt without any errors or fillers.
117105
118106
### User Message:
119-
Rewrite the code to satisfy this request: "{{{userInput}}}"
107+
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
120108
121109
\`\`\`{{{language}}}
122110
{{{codeToEdit}}}
@@ -131,7 +119,7 @@ Sure! Here's the code you requested:
131119
const deepseekEditPrompt = `### System Prompt
132120
You are an AI programming assistant, utilizing the DeepSeek Coder model, developed by DeepSeek Company, and your role is to assist with questions related to computer science. For politically sensitive questions, security and privacy issues, and other non-computer science questions, you will not answer.
133121
### Instruction:
134-
Rewrite the code to satisfy this request: "{{{userInput}}}"
122+
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
135123
136124
\`\`\`{{{language}}}
137125
{{{codeToEdit}}}
@@ -145,7 +133,7 @@ Sure! Here's the code you requested:
145133
const zephyrEditPrompt = `<|system|>
146134
You are an expert programmer and write code on the first attempt without any errors or fillers.</s>
147135
<|user|>
148-
Rewrite the code to satisfy this request: "{{{userInput}}}"
136+
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
149137
150138
\`\`\`{{{language}}}
151139
{{{codeToEdit}}}
@@ -160,12 +148,12 @@ const openchatEditPrompt = `GPT4 Correct User: You are an expert programmer and
160148
\`\`\`{{{language}}}
161149
{{{codeToEdit}}}
162150
\`\`\`
163-
Please only respond with code and put it inside of a markdown code block. Do not give any explanation, but your code should perfectly satisfy the user request.<|end_of_turn|>GPT4 Correct Assistant: Sure thing! Here is the rewritten code that you requested:
151+
Please only respond with code and put it inside of a markdown code block. Do not give any explanation, but your code should perfectly satisfy the user request. Leave existing comments in place unless changes require modifying them.<|end_of_turn|>GPT4 Correct Assistant: Sure thing! Here is the rewritten code that you requested:
164152
\`\`\`{{{language}}}
165153
`;
166154

167155
const xWinCoderEditPrompt = `<system>: You are an AI coding agent that helps people with programming. Write a response that appropriately completes the user's request.
168-
<user>: Please rewrite the following code with these instructions: "{{{userInput}}}"
156+
<user>: Please rewrite the following code (without changing existing code comments) with these instructions: "{{{userInput}}}"
169157
\`\`\`{{{language}}}
170158
{{{codeToEdit}}}
171159
\`\`\`
@@ -177,7 +165,7 @@ Just rewrite the code without explanations:
177165
const neuralChatEditPrompt = `### System:
178166
You are an expert programmer and write code on the first attempt without any errors or fillers.
179167
### User:
180-
Rewrite the code to satisfy this request: "{{{userInput}}}"
168+
Rewrite the code (without changing existing code comments) to satisfy this request: "{{{userInput}}}"
181169
182170
\`\`\`{{{language}}}
183171
{{{codeToEdit}}}
@@ -188,7 +176,7 @@ Sure! Here's the code you requested:
188176
\`\`\`{{{language}}}
189177
`;
190178

191-
const codeLlama70bEditPrompt = `<s>Source: system\n\n You are an expert programmer and write code on the first attempt without any errors or fillers. <step> Source: user\n\n Rewrite the code to satisfy this request: "{{{userInput}}}"
179+
const codeLlama70bEditPrompt = `<s>Source: system\n\n You are an expert programmer and write code on the first attempt without any errors or fillers. <step> Source: user\n\n Rewrite the code (without changing existing code comments) to satisfy this request: "{{{userInput}}}"
192180
193181
\`\`\`{{{language}}}
194182
{{{codeToEdit}}}
@@ -209,7 +197,7 @@ You are an expert programmer. You will rewrite the above code to do the followin
209197
210198
${otherData.userInput}
211199
212-
Output only a code block with the rewritten code:
200+
Leave existing comments in place unless changes require modifying them. Output only a code block with the rewritten code:
213201
`,
214202
},
215203
{
@@ -224,12 +212,12 @@ const llama3EditPrompt: PromptTemplate = `<|begin_of_text|><|start_header_id|>us
224212
{{{codeToEdit}}}
225213
\`\`\`
226214
227-
Rewrite the above code to satisfy this request: "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
215+
Rewrite the above code to satisfy this request (without changing existing code comments): "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
228216
Sure! Here's the code you requested:
229217
\`\`\`{{{language}}}`;
230218

231219
const gemmaEditPrompt = `<start_of_turn>user
232-
You are an expert programmer and write code on the first attempt without any errors or fillers. Rewrite the code to satisfy this request: "{{{userInput}}}"
220+
You are an expert programmer and write code on the first attempt without any errors or fillers. Rewrite the code to satisfy this request (without changing existing code comments): "{{{userInput}}}"
233221
234222
\`\`\`{{{language}}}
235223
{{{codeToEdit}}}
@@ -244,7 +232,6 @@ export {
244232
alpacaEditPrompt,
245233
claudeEditPrompt,
246234
codeLlama70bEditPrompt,
247-
codellamaInfillEditPrompt,
248235
deepseekEditPrompt,
249236
gemmaEditPrompt,
250237
gptEditPrompt,
@@ -254,7 +241,6 @@ export {
254241
openchatEditPrompt,
255242
osModelsEditPrompt,
256243
phindEditPrompt,
257-
simplestEditPrompt,
258244
simplifiedEditPrompt,
259245
xWinCoderEditPrompt,
260246
zephyrEditPrompt,

core/llm/templates/edit/gpt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,5 @@ export const defaultApplyPrompt: PromptTemplateFunction = (
7676
history,
7777
otherData,
7878
) => {
79-
return `${otherData.original_code}\n\nThe following code was suggested as an edit:\n\`\`\`\n${otherData.new_code}\n\`\`\`\nPlease apply it to the previous code. Do not change comments unless explicitly requested.`;
79+
return `${otherData.original_code}\n\nThe following code was suggested as an edit:\n\`\`\`\n${otherData.new_code}\n\`\`\`\nPlease apply it to the previous code. Leave existing comments in place unless changes require modifying them.`;
8080
};

extensions/intellij/src/main/kotlin/com/github/continuedev/continueintellijextension/continue/ApplyToFileHandler.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ApplyToFileHandler(
141141
}
142142

143143
private fun buildApplyPrompt(): String {
144-
return "The following code was suggested as an edit:\n```\n${params.text}\n```\nPlease apply it to the previous code."
144+
return "The following code was suggested as an edit:\n```\n${params.text}\n```\nPlease apply it to the previous code. Leave existing comments in place unless changes require modifying them."
145145
}
146146

147147
private fun createDiffStreamHandler(

extensions/vscode/src/apply/ApplyManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class ApplyManager {
171171
* Creates a prompt for applying code edits
172172
*/
173173
private getApplyPrompt(text: string): string {
174-
return `The following code was suggested as an edit:\n\`\`\`\n${text}\n\`\`\`\nPlease apply it to the previous code.`;
174+
return `The following code was suggested as an edit:\n\`\`\`\n${text}\n\`\`\`\nPlease apply it to the previous code. Leave existing comments in place unless changes require modifying them.`;
175175
}
176176

177177
/**

0 commit comments

Comments
 (0)