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
This commit is contained in:
parent
fd4e931f44
commit
d8cc0b69d2
5 changed files with 21 additions and 34 deletions
|
|
@ -14,6 +14,7 @@ const RULES = [
|
|||
`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.`,
|
||||
"You must keep at least one line above and below from the original code, so that we can identify what the previous code was.",
|
||||
`Do not place miscellaneous "${UNCHANGED_CODE}" comments at the top or bottom of the file when there is nothing to replace them.`,
|
||||
"Leave existing comments in place unless changes require modifying them.",
|
||||
// `You should write "${UNCHANGED_CODE}" at least for each function that is unchanged, rather than grouping them into a single comment.`,
|
||||
// `You should lean toward using a smaller number of these comments rather than rewriting it for every function if all of them are unchanged.`,
|
||||
// `You may do this for imports as well if needed.`,
|
||||
|
|
@ -21,7 +22,7 @@ const RULES = [
|
|||
"The code should always be syntactically valid, even with the comments.",
|
||||
];
|
||||
|
||||
function claude35SonnetLazyApplyPrompt(
|
||||
function claudeSonnetLazyApplyPrompt(
|
||||
...args: Parameters<LazyApplyPrompt>
|
||||
): ReturnType<LazyApplyPrompt> {
|
||||
const userContent = dedent`
|
||||
|
|
@ -55,7 +56,7 @@ export function lazyApplyPromptForModel(
|
|||
provider: string,
|
||||
): LazyApplyPrompt | undefined {
|
||||
if (model.includes("sonnet")) {
|
||||
return claude35SonnetLazyApplyPrompt;
|
||||
return claudeSonnetLazyApplyPrompt;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
|
|
|
|||
|
|
@ -7,19 +7,7 @@ const simplifiedEditPrompt = `Consider the following code:
|
|||
\`\`\`
|
||||
Edit the code to perfectly satisfy the following user request:
|
||||
{{{userInput}}}
|
||||
Output nothing except for the code. No code block, no English explanation, no start/end tags.`;
|
||||
|
||||
const simplestEditPrompt = `Here is the code before editing:
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
\`\`\`
|
||||
|
||||
Here is the edit requested:
|
||||
"{{{userInput}}}"
|
||||
|
||||
Here is the code after editing:`;
|
||||
|
||||
const codellamaInfillEditPrompt = "{{filePrefix}}<FILL>{{fileSuffix}}";
|
||||
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.`;
|
||||
|
||||
const START_TAG = "<START EDITING HERE>";
|
||||
const osModelsEditPrompt: PromptTemplate = (history, otherData) => {
|
||||
|
|
@ -55,7 +43,7 @@ ${otherData.codeToEdit}
|
|||
${suffixTag}
|
||||
\`\`\`
|
||||
|
||||
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}`,
|
||||
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}`,
|
||||
},
|
||||
{
|
||||
role: "assistant",
|
||||
|
|
@ -75,7 +63,7 @@ ${otherData.codeToEdit}
|
|||
${suffixTag}
|
||||
\`\`\`
|
||||
|
||||
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}
|
||||
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}
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
@ -93,12 +81,12 @@ const mistralEditPrompt = `[INST] You are a helpful code assistant. Your task is
|
|||
{{{codeToEdit}}}
|
||||
\`\`\`
|
||||
|
||||
Just rewrite the code without explanations: [/INST]
|
||||
Leave existing comments in place unless changes require modifying them. Just rewrite the code without explanations: [/INST]
|
||||
\`\`\`{{{language}}}`;
|
||||
|
||||
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.
|
||||
|
||||
### Instruction: Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
### Instruction: Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
|
||||
### Input:
|
||||
|
||||
|
|
@ -116,7 +104,7 @@ const phindEditPrompt = `### System Prompt
|
|||
You are an expert programmer and write code on the first attempt without any errors or fillers.
|
||||
|
||||
### User Message:
|
||||
Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -131,7 +119,7 @@ Sure! Here's the code you requested:
|
|||
const deepseekEditPrompt = `### System Prompt
|
||||
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.
|
||||
### Instruction:
|
||||
Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -145,7 +133,7 @@ Sure! Here's the code you requested:
|
|||
const zephyrEditPrompt = `<|system|>
|
||||
You are an expert programmer and write code on the first attempt without any errors or fillers.</s>
|
||||
<|user|>
|
||||
Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
Leave existing comments in place unless changes require modifying them. Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -160,12 +148,12 @@ const openchatEditPrompt = `GPT4 Correct User: You are an expert programmer and
|
|||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
\`\`\`
|
||||
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:
|
||||
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:
|
||||
\`\`\`{{{language}}}
|
||||
`;
|
||||
|
||||
const xWinCoderEditPrompt = `<system>: You are an AI coding agent that helps people with programming. Write a response that appropriately completes the user's request.
|
||||
<user>: Please rewrite the following code with these instructions: "{{{userInput}}}"
|
||||
<user>: Please rewrite the following code (without changing existing code comments) with these instructions: "{{{userInput}}}"
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
\`\`\`
|
||||
|
|
@ -177,7 +165,7 @@ Just rewrite the code without explanations:
|
|||
const neuralChatEditPrompt = `### System:
|
||||
You are an expert programmer and write code on the first attempt without any errors or fillers.
|
||||
### User:
|
||||
Rewrite the code to satisfy this request: "{{{userInput}}}"
|
||||
Rewrite the code (without changing existing code comments) to satisfy this request: "{{{userInput}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -188,7 +176,7 @@ Sure! Here's the code you requested:
|
|||
\`\`\`{{{language}}}
|
||||
`;
|
||||
|
||||
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}}}"
|
||||
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}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -209,7 +197,7 @@ You are an expert programmer. You will rewrite the above code to do the followin
|
|||
|
||||
${otherData.userInput}
|
||||
|
||||
Output only a code block with the rewritten code:
|
||||
Leave existing comments in place unless changes require modifying them. Output only a code block with the rewritten code:
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
@ -224,12 +212,12 @@ const llama3EditPrompt: PromptTemplate = `<|begin_of_text|><|start_header_id|>us
|
|||
{{{codeToEdit}}}
|
||||
\`\`\`
|
||||
|
||||
Rewrite the above code to satisfy this request: "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
||||
Rewrite the above code to satisfy this request (without changing existing code comments): "{{{userInput}}}"<|eot_id|><|start_header_id|>assistant<|end_header_id|>
|
||||
Sure! Here's the code you requested:
|
||||
\`\`\`{{{language}}}`;
|
||||
|
||||
const gemmaEditPrompt = `<start_of_turn>user
|
||||
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}}}"
|
||||
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}}}"
|
||||
|
||||
\`\`\`{{{language}}}
|
||||
{{{codeToEdit}}}
|
||||
|
|
@ -244,7 +232,6 @@ export {
|
|||
alpacaEditPrompt,
|
||||
claudeEditPrompt,
|
||||
codeLlama70bEditPrompt,
|
||||
codellamaInfillEditPrompt,
|
||||
deepseekEditPrompt,
|
||||
gemmaEditPrompt,
|
||||
gptEditPrompt,
|
||||
|
|
@ -254,7 +241,6 @@ export {
|
|||
openchatEditPrompt,
|
||||
osModelsEditPrompt,
|
||||
phindEditPrompt,
|
||||
simplestEditPrompt,
|
||||
simplifiedEditPrompt,
|
||||
xWinCoderEditPrompt,
|
||||
zephyrEditPrompt,
|
||||
|
|
|
|||
|
|
@ -76,5 +76,5 @@ export const defaultApplyPrompt: PromptTemplateFunction = (
|
|||
history,
|
||||
otherData,
|
||||
) => {
|
||||
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.`;
|
||||
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.`;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class ApplyToFileHandler(
|
|||
}
|
||||
|
||||
private fun buildApplyPrompt(): String {
|
||||
return "The following code was suggested as an edit:\n```\n${params.text}\n```\nPlease apply it to the previous code."
|
||||
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."
|
||||
}
|
||||
|
||||
private fun createDiffStreamHandler(
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ export class ApplyManager {
|
|||
* Creates a prompt for applying code edits
|
||||
*/
|
||||
private getApplyPrompt(text: string): string {
|
||||
return `The following code was suggested as an edit:\n\`\`\`\n${text}\n\`\`\`\nPlease apply it to the previous code.`;
|
||||
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.`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue