Skip to content

Commit b8c92f2

Browse files
authored
Merge pull request #5272 from continuedev/nate/apply-fixes
Nate/apply-fixes
2 parents 2260206 + a4cc558 commit b8c92f2

File tree

6 files changed

+64
-12
lines changed

6 files changed

+64
-12
lines changed

core/diff/myers.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,16 @@ describe("Test myers diff function", () => {
4141
{ type: "same", line: "C" },
4242
]);
4343
});
44+
45+
test("should ignore single-line whitespace-only differences", () => {
46+
const linesA = "A\n B\nC\n";
47+
const linesB = "A\nB\nC";
48+
49+
const diffLines = myersDiff(linesA, linesB);
50+
expect(diffLines).toEqual([
51+
{ type: "same", line: "A" },
52+
{ type: "same", line: " B" },
53+
{ type: "same", line: "C" },
54+
]);
55+
});
4456
});

core/diff/myers.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,21 @@ export function myersDiff(oldContent: string, newContent: string): DiffLine[] {
3030
const theirFormat = diffLines(oldContent, newContent, {
3131
ignoreNewlineAtEof: true,
3232
});
33-
const ourFormat = theirFormat.flatMap(convertMyersChangeToDiffLines);
33+
let ourFormat = theirFormat.flatMap(convertMyersChangeToDiffLines);
3434

35+
// Combine consecutive old/new pairs that are identical after trimming
36+
for (let i = 0; i < ourFormat.length - 1; i++) {
37+
if (
38+
ourFormat[i]?.type === "old" &&
39+
ourFormat[i + 1]?.type === "new" &&
40+
ourFormat[i].line.trim() === ourFormat[i + 1].line.trim()
41+
) {
42+
ourFormat[i] = { type: "same", line: ourFormat[i].line };
43+
ourFormat.splice(i + 1, 1);
44+
}
45+
}
46+
47+
// Remove trailing empty old lines
3548
while (
3649
ourFormat.length > 0 &&
3750
ourFormat[ourFormat.length - 1].type === "old" &&

core/edit/streamDiffLines.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,13 @@ export async function* streamDiffLines({
123123

124124
if (systemMessage) {
125125
if (typeof prompt === "string") {
126+
// Removed system prompt because it was causing it to be used for Apply
127+
// We should bring it back only for Edit
126128
prompt = [
127-
{
128-
role: "system",
129-
content: systemMessage,
130-
},
129+
// {
130+
// role: "system",
131+
// content: systemMessage,
132+
// },
131133
{
132134
role: "user",
133135
content: prompt,
@@ -138,10 +140,10 @@ export async function* streamDiffLines({
138140
if (curSysMsg) {
139141
curSysMsg.content = systemMessage + "\n\n" + curSysMsg.content;
140142
} else {
141-
prompt.unshift({
142-
role: "system",
143-
content: systemMessage,
144-
});
143+
// prompt.unshift({
144+
// role: "system",
145+
// content: systemMessage,
146+
// });
145147
}
146148
}
147149
}

core/llm/constructMessages.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\
2020
2121
When addressing code modification requests, present a concise code snippet that
2222
emphasizes only the necessary changes and uses abbreviated placeholders for
23-
unmodified sections. For instance:
23+
unmodified sections. For example:
2424
25-
\`\`\`typescript /path/to/file
25+
\`\`\`language /path/to/file
2626
// ... rest of code here ...
2727
2828
{{ modified code here }}
@@ -34,6 +34,22 @@ export const DEFAULT_CHAT_SYSTEM_MESSAGE = `\
3434
// ... rest of code here ...
3535
\`\`\`
3636
37+
In existing files, you should always restate the function or class that the snippet belongs to:
38+
39+
\`\`\`language /path/to/file
40+
// ... rest of code here ...
41+
42+
function exampleFunction() {
43+
// ... rest of code here ...
44+
45+
{{ modified code here }}
46+
47+
// ... rest of code here ...
48+
}
49+
50+
// ... rest of code here ...
51+
\`\`\`
52+
3753
Since users have access to their complete file, they prefer reading only the
3854
relevant modifications. It's perfectly acceptable to omit unmodified portions
3955
at the beginning, middle, or end of files using these "lazy" comments. Only

core/llm/llms/OpenAI.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,12 @@ class OpenAI extends BaseLLM {
102102
}
103103

104104
protected supportsPrediction(model: string): boolean {
105-
const SUPPORTED_MODELS = ["gpt-4o-mini", "gpt-4o", "mistral-large"];
105+
const SUPPORTED_MODELS = [
106+
"gpt-4o-mini",
107+
"gpt-4o",
108+
"mistral-large",
109+
"Fast-Apply",
110+
];
106111
return SUPPORTED_MODELS.some((m) => model.includes(m));
107112
}
108113

core/llm/llms/Relace.ts

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export class Relace extends OpenAI {
1111
};
1212
protected useOpenAIAdapterFor: (LlmApiRequestType | "*")[] = ["*"];
1313

14+
protected supportsPrediction(model: string): boolean {
15+
return true;
16+
}
17+
1418
getConfigurationStatus() {
1519
if (!this.apiKey) {
1620
return LLMConfigurationStatuses.MISSING_API_KEY;

0 commit comments

Comments
 (0)