diff --git a/core/autocomplete/postprocessing/index.ts b/core/autocomplete/postprocessing/index.ts index c2cf5049b..bf0284cb2 100644 --- a/core/autocomplete/postprocessing/index.ts +++ b/core/autocomplete/postprocessing/index.ts @@ -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 diff --git a/core/autocomplete/templating/AutocompleteTemplate.ts b/core/autocomplete/templating/AutocompleteTemplate.ts index 2c8b12a31..b304c4058 100644 --- a/core/autocomplete/templating/AutocompleteTemplate.ts +++ b/core/autocomplete/templating/AutocompleteTemplate.ts @@ -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; diff --git a/core/llm/llms/Inception.ts b/core/llm/llms/Inception.ts index ef204fec1..6e38975f3 100644 --- a/core/llm/llms/Inception.ts +++ b/core/llm/llms/Inception.ts @@ -18,11 +18,10 @@ import OpenAI from "./OpenAI.js"; class Inception extends OpenAI { static providerName = "inception"; static defaultOptions: Partial = { - 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; } } diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 22390e25e..9bd027d77 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -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", diff --git a/extensions/vscode/package.json b/extensions/vscode/package.json index 079e05660..88746cf4b 100644 --- a/extensions/vscode/package.json +++ b/extensions/vscode/package.json @@ -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" diff --git a/gui/package-lock.json b/gui/package-lock.json index 765d4d78a..bb64c07ff 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -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",