Skip to content

Commit 83b5a3c

Browse files
authored
feat: wrap each recently viewed code snippet inside a token block (#7269)
* feat: wrap each recently viewed code snippet inside a token block * fix: update vitest * fix: update test
1 parent f4f9b31 commit 83b5a3c

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

core/nextEdit/templating/NextEditPromptEngine.vitest.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {
1414
MERCURY_EDIT_DIFF_HISTORY_OPEN,
1515
MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE,
1616
MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN,
17+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
18+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
1719
} from "../constants";
1820
import {
1921
renderDefaultSystemPrompt,
@@ -31,7 +33,7 @@ describe("NextEditPromptEngine", () => {
3133

3234
beforeEach(() => {
3335
mercuryHelper = {
34-
modelName: "inception/mercury-coder-nextedit" as NEXT_EDIT_MODELS,
36+
modelName: "inception/mercury-coder" as NEXT_EDIT_MODELS,
3537
fileContents: "function test() {\n const a = 1;\n return a;\n}",
3638
pos: { line: 1, character: 12 } as Position,
3739
lang: { name: "typescript" },
@@ -63,7 +65,7 @@ describe("NextEditPromptEngine", () => {
6365
};
6466
});
6567

66-
it("should render mercury-coder-nextedit prompt correctly", async () => {
68+
it("should render mercury-coder prompt correctly", async () => {
6769
const result = await renderPrompt(mercuryHelper, ctx);
6870

6971
expect(result).toHaveProperty("prompt");
@@ -72,6 +74,8 @@ describe("NextEditPromptEngine", () => {
7274
const content = result.prompt.content;
7375
expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_OPEN);
7476
expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPETS_CLOSE);
77+
expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN);
78+
expect(content).toContain(MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE);
7579
expect(content).toContain(MERCURY_CURRENT_FILE_CONTENT_OPEN);
7680
expect(content).toContain(MERCURY_CURRENT_FILE_CONTENT_CLOSE);
7781
expect(content).toContain(MERCURY_EDIT_DIFF_HISTORY_OPEN);

core/nextEdit/templating/mercuryCoderNextEdit.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {
33
MERCURY_CODE_TO_EDIT_CLOSE,
44
MERCURY_CODE_TO_EDIT_OPEN,
55
MERCURY_CURSOR,
6+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
7+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
68
} from "../constants";
79
import { insertCursorToken } from "./utils";
810

@@ -11,8 +13,10 @@ export function recentlyViewedCodeSnippetsBlock(
1113
) {
1214
return recentlyViewedCodeSnippets.reduce((acc, snippet, i) => {
1315
const block = [
16+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
1417
`code_snippet_file_path: ${snippet.filepath}`,
1518
snippet.content,
19+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
1620
].join("\n");
1721

1822
return (

core/nextEdit/templating/mercuryCoderNextEdit.vitest.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
MERCURY_CODE_TO_EDIT_CLOSE,
55
MERCURY_CODE_TO_EDIT_OPEN,
66
MERCURY_CURSOR,
7+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE,
8+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN,
79
} from "../constants";
810
import {
911
currentFileContentBlock,
@@ -25,10 +27,14 @@ describe("mercuryCoderNextEdit", () => {
2527
const result = recentlyViewedCodeSnippetsBlock(snippets);
2628

2729
const expected =
30+
`${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN}\n` +
2831
"code_snippet_file_path: /path/to/file1.ts\n" +
2932
"const a = 1;\n" +
33+
`${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE}\n` +
34+
`${MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_OPEN}\n` +
3035
"code_snippet_file_path: /path/to/file2.ts\n" +
31-
"function test() { return true; }";
36+
"function test() { return true; }\n" +
37+
MERCURY_RECENTLY_VIEWED_CODE_SNIPPET_CLOSE;
3238

3339
expect(result).toBe(expected);
3440
});

0 commit comments

Comments
 (0)