Merge pull request #5380 from continuedev/nate/mercury-prompt
mercury improvements
This commit is contained in:
commit
e8522320da
6 changed files with 86 additions and 20 deletions
|
|
@ -103,7 +103,7 @@ export function postprocessCompletion({
|
|||
}
|
||||
}
|
||||
|
||||
if (llm.model.includes("granite")) {
|
||||
if (llm.model.includes("mercury") || llm.model.includes("granite")) {
|
||||
// Granite tends to repeat the start of the line in the completion output
|
||||
let prefixEnd = prefix.split("\n").pop();
|
||||
if (prefixEnd) {
|
||||
|
|
@ -123,13 +123,14 @@ export function postprocessCompletion({
|
|||
|
||||
// // If completion starts with multiple whitespaces, but the cursor is at the end of the line
|
||||
// // then it should probably be on a new line
|
||||
// if (
|
||||
// (completion.startsWith(" ") || completion.startsWith("\t")) &&
|
||||
// !prefix.endsWith("\n") &&
|
||||
// (suffix.startsWith("\n") || suffix.trim().length === 0)
|
||||
// ) {
|
||||
// completion = "\n" + completion;
|
||||
// }
|
||||
if (
|
||||
llm.model.includes("mercury") &&
|
||||
(completion.startsWith(" ") || completion.startsWith("\t")) &&
|
||||
!prefix.endsWith("\n") &&
|
||||
(suffix.startsWith("\n") || suffix.trim().length === 0)
|
||||
) {
|
||||
completion = "\n" + completion;
|
||||
}
|
||||
|
||||
// If prefix ends with space and so does completion, then remove the space from completion
|
||||
|
||||
|
|
|
|||
|
|
@ -87,9 +87,10 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
|
|||
snippets,
|
||||
workspaceUris,
|
||||
): [string, string] => {
|
||||
|
||||
function getFileName(snippet: { uri: string, uniquePath: string }) {
|
||||
return snippet.uri.startsWith("file://") ? snippet.uniquePath : snippet.uri
|
||||
function getFileName(snippet: { uri: string; uniquePath: string }) {
|
||||
return snippet.uri.startsWith("file://")
|
||||
? snippet.uniquePath
|
||||
: snippet.uri;
|
||||
}
|
||||
|
||||
if (snippets.length === 0) {
|
||||
|
|
@ -135,6 +136,64 @@ const codestralMultifileFimTemplate: AutocompleteTemplate = {
|
|||
},
|
||||
};
|
||||
|
||||
const mercuryMultifileFimTemplate: AutocompleteTemplate = {
|
||||
compilePrefixSuffix: (
|
||||
prefix,
|
||||
suffix,
|
||||
filepath,
|
||||
reponame,
|
||||
snippets,
|
||||
workspaceUris,
|
||||
): [string, string] => {
|
||||
function getFileName(snippet: { uri: string; uniquePath: string }) {
|
||||
return snippet.uri.startsWith("file://")
|
||||
? snippet.uniquePath
|
||||
: snippet.uri;
|
||||
}
|
||||
|
||||
// Our current snippet format doesn't work well with mercury. We need to clean this up
|
||||
snippets = [];
|
||||
|
||||
if (snippets.length === 0) {
|
||||
if (suffix.trim().length === 0 && prefix.trim().length === 0) {
|
||||
return [
|
||||
`<|file_sep|>${getLastNUriRelativePathParts(workspaceUris, filepath, 2)}\n${prefix}`,
|
||||
suffix,
|
||||
];
|
||||
}
|
||||
return [prefix, suffix];
|
||||
}
|
||||
|
||||
const relativePaths = getShortestUniqueRelativeUriPaths(
|
||||
[
|
||||
...snippets.map((snippet) =>
|
||||
"filepath" in snippet ? snippet.filepath : "file:///Untitled.txt",
|
||||
),
|
||||
filepath,
|
||||
],
|
||||
workspaceUris,
|
||||
);
|
||||
|
||||
const otherFiles = snippets
|
||||
.map((snippet, i) => {
|
||||
if (snippet.type === AutocompleteSnippetType.Diff) {
|
||||
return snippet.content;
|
||||
}
|
||||
|
||||
return `<|file_sep|>${getFileName(relativePaths[i])} \n${snippet.content}`;
|
||||
})
|
||||
.join("\n\n");
|
||||
|
||||
return [
|
||||
`${otherFiles}${otherFiles ? "\n\n" : ""}<|file_sep|>${getFileName(relativePaths[relativePaths.length - 1])}\n<|fim_prefix|>${prefix}`,
|
||||
suffix,
|
||||
];
|
||||
},
|
||||
template: (prefix: string, suffix: string): string => {
|
||||
return `${prefix}<|fim_suffix|>${suffix}<|fim_middle|>`;
|
||||
},
|
||||
};
|
||||
|
||||
const codegemmaFimTemplate: AutocompleteTemplate = {
|
||||
template:
|
||||
"<|fim_prefix|>{{{prefix}}}<|fim_suffix|>{{{suffix}}}<|fim_middle|>",
|
||||
|
|
@ -223,8 +282,9 @@ const codegeexFimTemplate: AutocompleteTemplate = {
|
|||
[...snippets.map((snippet) => snippet.filepath), filepath],
|
||||
workspaceUris,
|
||||
);
|
||||
const baseTemplate = `###PATH:${relativePaths[relativePaths.length - 1]
|
||||
}\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`;
|
||||
const baseTemplate = `###PATH:${
|
||||
relativePaths[relativePaths.length - 1]
|
||||
}\n###LANGUAGE:${language}\n###MODE:BLOCK\n<|code_suffix|>${suffix}<|code_prefix|>${prefix}<|code_middle|>`;
|
||||
if (snippets.length === 0) {
|
||||
return `<|user|>\n${baseTemplate}<|assistant|>\n`;
|
||||
}
|
||||
|
|
@ -358,6 +418,9 @@ export function getTemplateForModel(model: string): AutocompleteTemplate {
|
|||
// if (lowerCaseModel.includes("starcoder2")) {
|
||||
// return starcoder2FimTemplate;
|
||||
// }
|
||||
if (lowerCaseModel.includes("mercury")) {
|
||||
return mercuryMultifileFimTemplate;
|
||||
}
|
||||
|
||||
if (lowerCaseModel.includes("qwen") && lowerCaseModel.includes("coder")) {
|
||||
return qwenCoderFimTemplate;
|
||||
|
|
|
|||
|
|
@ -18,11 +18,10 @@ import OpenAI from "./OpenAI.js";
|
|||
class Inception extends OpenAI {
|
||||
static providerName = "inception";
|
||||
static defaultOptions: Partial<LLMOptions> = {
|
||||
apiBase: "https://copenhagen.api.inceptionlabs.ai/v1/",
|
||||
apiBase: "https://api.inceptionlabs.ai/v1/",
|
||||
model: "mercury-editor-small-experimental",
|
||||
completionOptions: {
|
||||
temperature: 0.0,
|
||||
maxTokens: 150,
|
||||
presencePenalty: 1.5,
|
||||
stop: ["\n\n", "\n \n", "<|endoftext|>"],
|
||||
model: "mercury-editor-small-experimental", // Added model to fix TypeScript error
|
||||
|
|
@ -45,8 +44,8 @@ class Inception extends OpenAI {
|
|||
body: JSON.stringify({
|
||||
model: options.model,
|
||||
prompt: prefix,
|
||||
suffix,
|
||||
max_tokens: options.maxTokens,
|
||||
suffix: suffix.trim() === "" ? "<|endoftext|>" : suffix,
|
||||
max_tokens: options.maxTokens ?? 150, // Only want this for /fim, not chat
|
||||
temperature: options.temperature,
|
||||
top_p: options.topP,
|
||||
frequency_penalty: options.frequencyPenalty,
|
||||
|
|
@ -62,6 +61,9 @@ class Inception extends OpenAI {
|
|||
signal,
|
||||
});
|
||||
for await (const chunk of streamSse(resp)) {
|
||||
if (!chunk.choices[0]) {
|
||||
continue;
|
||||
}
|
||||
yield chunk.choices[0].text;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
2
extensions/vscode/package-lock.json
generated
2
extensions/vscode/package-lock.json
generated
|
|
@ -109,7 +109,7 @@
|
|||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"author": "Continue Dev, Inc",
|
||||
"version": "1.1.26",
|
||||
"version": "1.1.27",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
|
|||
2
gui/package-lock.json
generated
2
gui/package-lock.json
generated
|
|
@ -112,7 +112,7 @@
|
|||
"@continuedev/config-yaml": "file:../packages/config-yaml",
|
||||
"@continuedev/fetch": "^1.0.4",
|
||||
"@continuedev/llm-info": "^1.0.8",
|
||||
"@continuedev/openai-adapters": "^1.0.18",
|
||||
"@continuedev/openai-adapters": "^1.0.19",
|
||||
"@modelcontextprotocol/sdk": "^1.5.0",
|
||||
"@mozilla/readability": "^0.5.0",
|
||||
"@octokit/rest": "^20.1.1",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue