Merge branch 'preview' of https://github.com/continuedev/continue into preview
This commit is contained in:
commit
2ed16c5163
32 changed files with 2788 additions and 1429 deletions
82
core/autocomplete/cache.ts
Normal file
82
core/autocomplete/cache.ts
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
import { open } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
import { DatabaseConnection } from "../indexing/refreshIndex";
|
||||
import { getTabAutocompleteCacheSqlitePath } from "../util/paths";
|
||||
|
||||
export class AutocompleteLruCache {
|
||||
private static capacity: number = 1000;
|
||||
|
||||
db: DatabaseConnection;
|
||||
|
||||
constructor(db: DatabaseConnection) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
static async get(): Promise<AutocompleteLruCache> {
|
||||
const db = await open({
|
||||
filename: getTabAutocompleteCacheSqlitePath(),
|
||||
driver: sqlite3.Database,
|
||||
});
|
||||
|
||||
await db.run(`
|
||||
CREATE TABLE IF NOT EXISTS cache (
|
||||
key TEXT PRIMARY KEY,
|
||||
value TEXT NOT NULL,
|
||||
timestamp INTEGER NOT NULL
|
||||
)
|
||||
`);
|
||||
|
||||
return new AutocompleteLruCache(db);
|
||||
}
|
||||
|
||||
async get(key: string): Promise<string | undefined> {
|
||||
const result = await this.db.get(
|
||||
"SELECT value FROM cache WHERE key = ?",
|
||||
key
|
||||
);
|
||||
|
||||
if (result) {
|
||||
await this.db.run(
|
||||
"UPDATE cache SET timestamp = ? WHERE key = ?",
|
||||
Date.now(),
|
||||
key
|
||||
);
|
||||
return result.value;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async put(key: string, value: string) {
|
||||
const result = await this.db.get(
|
||||
"SELECT key FROM cache WHERE key = ?",
|
||||
key
|
||||
);
|
||||
|
||||
if (result) {
|
||||
await this.db.run(
|
||||
"UPDATE cache SET value = ?, timestamp = ? WHERE key = ?",
|
||||
value,
|
||||
Date.now(),
|
||||
key
|
||||
);
|
||||
} else {
|
||||
const count = await this.db.get("SELECT COUNT(*) as count FROM cache");
|
||||
|
||||
if (count.count >= AutocompleteLruCache.capacity) {
|
||||
await this.db.run(
|
||||
"DELETE FROM cache WHERE key = (SELECT key FROM cache ORDER BY timestamp ASC LIMIT 1)"
|
||||
);
|
||||
}
|
||||
|
||||
await this.db.run(
|
||||
"INSERT INTO cache (key, value, timestamp) VALUES (?, ?, ?)",
|
||||
key,
|
||||
value,
|
||||
Date.now()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default AutocompleteLruCache;
|
||||
128
core/autocomplete/constructPrompt.ts
Normal file
128
core/autocomplete/constructPrompt.ts
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
import Parser from "web-tree-sitter";
|
||||
import {
|
||||
countTokens,
|
||||
pruneLinesFromBottom,
|
||||
pruneLinesFromTop,
|
||||
} from "../llm/countTokens";
|
||||
import { getBasename } from "../util";
|
||||
import { getParserForFile } from "../util/treeSitter";
|
||||
import { AutocompleteLanguageInfo, Typescript } from "./languages";
|
||||
import {
|
||||
MAX_PROMPT_TOKENS,
|
||||
MAX_SUFFIX_PERCENTAGE,
|
||||
PREFIX_PERCENTAGE,
|
||||
} from "./parameters";
|
||||
|
||||
export function languageForFilepath(
|
||||
filepath: string
|
||||
): AutocompleteLanguageInfo {
|
||||
return Typescript;
|
||||
}
|
||||
|
||||
function formatExternalSnippet(
|
||||
filepath: string,
|
||||
snippet: string,
|
||||
language: AutocompleteLanguageInfo
|
||||
) {
|
||||
const comment = language.comment;
|
||||
const lines = [
|
||||
comment + " Path: " + getBasename(filepath),
|
||||
...snippet.split("\n").map((line) => comment + " " + line),
|
||||
comment,
|
||||
];
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
async function getTreePathAtCursor(
|
||||
filepath: string,
|
||||
fileContents: string,
|
||||
cursorIndex: number
|
||||
): Promise<Parser.SyntaxNode[]> {
|
||||
const parser = await getParserForFile(filepath);
|
||||
const ast = parser.parse(fileContents);
|
||||
const path = [ast.rootNode];
|
||||
while (path[path.length - 1].childCount > 0) {
|
||||
let foundChild = false;
|
||||
for (let child of path[path.length - 1].children) {
|
||||
if (child.startIndex <= cursorIndex && child.endIndex >= cursorIndex) {
|
||||
path.push(child);
|
||||
foundChild = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundChild) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
export interface AutocompleteSnippet {
|
||||
filepath: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export async function constructAutocompletePrompt(
|
||||
filepath: string,
|
||||
fullPrefix: string,
|
||||
fullSuffix: string,
|
||||
clipboardText: string,
|
||||
language: AutocompleteLanguageInfo,
|
||||
getDefinition: (
|
||||
filepath: string,
|
||||
line: number,
|
||||
character: number
|
||||
) => Promise<AutocompleteSnippet | undefined>
|
||||
): Promise<{ prefix: string; suffix: string; useFim: boolean }> {
|
||||
// Find external snippets
|
||||
const snippets: AutocompleteSnippet[] = [];
|
||||
|
||||
const treePath = await getTreePathAtCursor(
|
||||
filepath,
|
||||
fullPrefix + fullSuffix,
|
||||
fullPrefix.length
|
||||
);
|
||||
|
||||
// Get function def when inside call expression
|
||||
let callExpression = undefined;
|
||||
for (let node of treePath.reverse()) {
|
||||
if (node.type === "call_expression") {
|
||||
callExpression = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (callExpression) {
|
||||
const definition = await getDefinition(
|
||||
filepath,
|
||||
callExpression.startPosition.row,
|
||||
callExpression.startPosition.column
|
||||
);
|
||||
if (definition) {
|
||||
snippets.push(definition);
|
||||
}
|
||||
}
|
||||
|
||||
// Construct basic prefix / suffix
|
||||
const formattedSnippets = snippets
|
||||
.map((snippet) =>
|
||||
formatExternalSnippet(snippet.filepath, snippet.content, language)
|
||||
)
|
||||
.join("\n");
|
||||
const maxPrefixTokens =
|
||||
MAX_PROMPT_TOKENS * PREFIX_PERCENTAGE -
|
||||
countTokens(formattedSnippets, "gpt-4");
|
||||
let prefix = pruneLinesFromTop(fullPrefix, maxPrefixTokens);
|
||||
if (formattedSnippets.length > 0) {
|
||||
prefix = formattedSnippets + "\n" + prefix;
|
||||
}
|
||||
|
||||
const maxSuffixTokens = Math.min(
|
||||
MAX_PROMPT_TOKENS - countTokens(prefix, "gpt-4"),
|
||||
MAX_SUFFIX_PERCENTAGE * MAX_PROMPT_TOKENS
|
||||
);
|
||||
let suffix = pruneLinesFromBottom(fullSuffix, maxSuffixTokens);
|
||||
|
||||
return { prefix, suffix, useFim: true };
|
||||
}
|
||||
0
core/autocomplete/index.ts
Normal file
0
core/autocomplete/index.ts
Normal file
11
core/autocomplete/languages.ts
Normal file
11
core/autocomplete/languages.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
export interface AutocompleteLanguageInfo {
|
||||
stopWords: string[];
|
||||
comment: string;
|
||||
endOfLine: string[];
|
||||
}
|
||||
|
||||
export const Typescript = {
|
||||
stopWords: ["function", "class", "module", "export "],
|
||||
comment: "//",
|
||||
endOfLine: [";"],
|
||||
};
|
||||
4
core/autocomplete/parameters.ts
Normal file
4
core/autocomplete/parameters.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export const MAX_PROMPT_TOKENS = 1_000;
|
||||
export const PREFIX_PERCENTAGE = 0.85;
|
||||
export const MAX_SUFFIX_PERCENTAGE = 0.25;
|
||||
export const DEBOUNCE_DELAY = 350;
|
||||
55
core/autocomplete/templates.ts
Normal file
55
core/autocomplete/templates.ts
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
// Fill in the middle prompts
|
||||
|
||||
import { CompletionOptions } from "..";
|
||||
|
||||
interface AutocompleteTemplate {
|
||||
template: string | ((prefix: string, suffix: string) => string);
|
||||
completionOptions?: Partial<CompletionOptions>;
|
||||
}
|
||||
|
||||
// https://huggingface.co/stabilityai/stable-code-3b
|
||||
const stableCodeFimTemplate: AutocompleteTemplate = {
|
||||
template: "<fim_prefix>{{{prefix}}}<fim_suffix>{{{suffix}}}<fim_middle>",
|
||||
completionOptions: {
|
||||
stop: ["<fim_prefix>", "<fim_suffix>", "<fim_middle>", "<|endoftext|>"],
|
||||
},
|
||||
};
|
||||
|
||||
const codeLlamaFimTemplate: AutocompleteTemplate = {
|
||||
template: "<PRE> {{{prefix}}} <SUF>{{{suffix}}} <MID>",
|
||||
completionOptions: { stop: ["<PRE>", "<SUF>", "<MID>"] },
|
||||
};
|
||||
|
||||
// https://huggingface.co/deepseek-ai/deepseek-coder-1.3b-base
|
||||
const deepseekFimTemplate: AutocompleteTemplate = {
|
||||
template:
|
||||
"<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>",
|
||||
completionOptions: {
|
||||
stop: ["<|fim▁begin|>", "<|fim▁hole|>", "<|fim▁end|>", "//"],
|
||||
},
|
||||
};
|
||||
|
||||
const deepseekFimTemplateWrongPipeChar: AutocompleteTemplate = {
|
||||
template: "<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>",
|
||||
completionOptions: { stop: ["<|fim▁begin|>", "<|fim▁hole|>", "<|fim▁end|>"] },
|
||||
};
|
||||
|
||||
export function getTemplateForModel(model: string): AutocompleteTemplate {
|
||||
if (
|
||||
model.includes("starcoder") ||
|
||||
model.includes("star-coder") ||
|
||||
model.includes("stable")
|
||||
) {
|
||||
return stableCodeFimTemplate;
|
||||
}
|
||||
|
||||
if (model.includes("codellama")) {
|
||||
return codeLlamaFimTemplate;
|
||||
}
|
||||
|
||||
if (model.includes("deepseek")) {
|
||||
return deepseekFimTemplate;
|
||||
}
|
||||
|
||||
return stableCodeFimTemplate;
|
||||
}
|
||||
|
|
@ -80,6 +80,20 @@ async function intermediateToFinalConfig(
|
|||
models.push(llm);
|
||||
}
|
||||
|
||||
let autocompleteLlm: BaseLLM | undefined = undefined;
|
||||
if (config.tabAutocompleteModel) {
|
||||
if (isModelDescription(config.tabAutocompleteModel)) {
|
||||
autocompleteLlm = await llmFromDescription(
|
||||
config.tabAutocompleteModel,
|
||||
readFile,
|
||||
config.completionOptions,
|
||||
config.systemMessage
|
||||
);
|
||||
} else {
|
||||
autocompleteLlm = new CustomLLMClass(config.tabAutocompleteModel);
|
||||
}
|
||||
}
|
||||
|
||||
const contextProviders: IContextProvider[] = [new FileContextProvider({})];
|
||||
for (const provider of config.contextProviders || []) {
|
||||
if (isContextProviderWithParams(provider)) {
|
||||
|
|
@ -112,6 +126,7 @@ async function intermediateToFinalConfig(
|
|||
contextProviders,
|
||||
models,
|
||||
embeddingsProvider: config.embeddingsProvider as any,
|
||||
tabAutocompleteModel: autocompleteLlm,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
18
core/index.d.ts
vendored
18
core/index.d.ts
vendored
|
|
@ -452,7 +452,6 @@ export type ModelName =
|
|||
| "wizardcoder-34b"
|
||||
| "zephyr-7b"
|
||||
| "codeup-13b"
|
||||
| "deepseek-1b"
|
||||
| "deepseek-7b"
|
||||
| "deepseek-33b"
|
||||
| "neural-chat-7b"
|
||||
|
|
@ -465,7 +464,12 @@ export type ModelName =
|
|||
// Mistral
|
||||
| "mistral-tiny"
|
||||
| "mistral-small"
|
||||
| "mistral-medium";
|
||||
| "mistral-medium"
|
||||
// Tab autocomplete
|
||||
| "deepseek-1b"
|
||||
| "starcoder-1b"
|
||||
| "starcoder-3b"
|
||||
| "stable-code-3b";
|
||||
|
||||
export interface RequestOptions {
|
||||
timeout?: number;
|
||||
|
|
@ -540,6 +544,11 @@ export interface EmbeddingsProvider {
|
|||
embed(chunks: string[]): Promise<number[][]>;
|
||||
}
|
||||
|
||||
export interface TabAutocompleteOptions {
|
||||
useCopyBuffer?: boolean;
|
||||
useSuffix?: boolean;
|
||||
}
|
||||
|
||||
export interface SerializedContinueConfig {
|
||||
disallowedSteps?: string[];
|
||||
allowAnonymousTelemetry?: boolean;
|
||||
|
|
@ -553,6 +562,8 @@ export interface SerializedContinueConfig {
|
|||
disableSessionTitles?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: EmbeddingsProviderDescription;
|
||||
tabAutocompleteModel?: ModelDescription;
|
||||
tabAutocompleteOptions?: TabAutocompleteOptions;
|
||||
}
|
||||
|
||||
export interface Config {
|
||||
|
|
@ -581,6 +592,8 @@ export interface Config {
|
|||
userToken?: string;
|
||||
/** The provider used to calculate embeddings. If left empty, Continue will use transformers.js to calculate the embeddings with all-MiniLM-L6-v2 */
|
||||
embeddingsProvider?: EmbeddingsProviderDescription | EmbeddingsProvider;
|
||||
/** The model that Continue will use for tab autocompletions. */
|
||||
tabAutocompleteModel?: CustomLLM | ModelDescription;
|
||||
}
|
||||
|
||||
export interface ContinueConfig {
|
||||
|
|
@ -594,4 +607,5 @@ export interface ContinueConfig {
|
|||
disableIndexing?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
tabAutocompleteModel?: ILLM;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
import { Chunk, ChunkWithoutID } from "../..";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants";
|
||||
import { countTokens } from "../../llm/countTokens";
|
||||
import { supportedLanguages } from "../../util/treeSitter";
|
||||
import { basicChunker } from "./basic";
|
||||
import { codeChunker, supportedLanguages } from "./code";
|
||||
import { codeChunker } from "./code";
|
||||
|
||||
async function* chunkDocumentWithoutId(
|
||||
filepath: string,
|
||||
|
|
|
|||
|
|
@ -1,97 +1,7 @@
|
|||
// import treeSitterBash from "tree-sitter-wasms/out/tree-sitter-bash.wasm";
|
||||
// import treeSitterC from "tree-sitter-wasms/out/tree-sitter-c.wasm";
|
||||
// import treeSitterCSharp from "tree-sitter-wasms/out/tree-sitter-c_sharp.wasm";
|
||||
// import treeSitterCpp from "tree-sitter-wasms/out/tree-sitter-cpp.wasm";
|
||||
// import treeSitterCss from "tree-sitter-wasms/out/tree-sitter-css.wasm";
|
||||
// // import treeSitterElisp from "tree-sitter-wasms/out/tree-sitter-elisp.wasm"
|
||||
// // import treeSitterElixir from "tree-sitter-wasms/out/tree-sitter-elixir.wasm"
|
||||
// import treeSitterElm from "tree-sitter-wasms/out/tree-sitter-elm.wasm";
|
||||
// // import treeSitterEmbeddedTemplate from "tree-sitter-wasms/out/tree-sitter-embedded_template.wasm"
|
||||
// import treeSitterGo from "tree-sitter-wasms/out/tree-sitter-go.wasm";
|
||||
// import treeSitterHtml from "tree-sitter-wasms/out/tree-sitter-html.wasm";
|
||||
// import treeSitterJava from "tree-sitter-wasms/out/tree-sitter-java.wasm";
|
||||
// import treeSitterJavascript from "tree-sitter-wasms/out/tree-sitter-javascript.wasm";
|
||||
// import treeSitterJson from "tree-sitter-wasms/out/tree-sitter-json.wasm";
|
||||
// // import treeSitterLua from "tree-sitter-wasms/out/tree-sitter-lua.wasm"
|
||||
// import treeSitterOcaml from "tree-sitter-wasms/out/tree-sitter-ocaml.wasm";
|
||||
// import treeSitterPhp from "tree-sitter-wasms/out/tree-sitter-php.wasm";
|
||||
// import treeSitterPython from "tree-sitter-wasms/out/tree-sitter-python.wasm";
|
||||
// // import treeSitterQl from "tree-sitter-wasms/out/tree-sitter-ql.wasm"
|
||||
// // import treeSitterRescript from "tree-sitter-wasms/out/tree-sitter-rescript.wasm"
|
||||
// import treeSitterRuby from "tree-sitter-wasms/out/tree-sitter-ruby.wasm";
|
||||
// import treeSitterRust from "tree-sitter-wasms/out/tree-sitter-rust.wasm";
|
||||
// // import treeSitterSystemRdl from "tree-sitter-wasms/out/tree-sitter-systemrdl.wasm"
|
||||
// import treeSitterToml from "tree-sitter-wasms/out/tree-sitter-toml.wasm";
|
||||
// import treeSitterTsx from "tree-sitter-wasms/out/tree-sitter-tsx.wasm";
|
||||
// import treeSitterTypescript from "tree-sitter-wasms/out/tree-sitter-typescript.wasm";
|
||||
// import treeSitterVue from "tree-sitter-wasms/out/tree-sitter-vue.wasm";
|
||||
// import treeSitterYaml from "tree-sitter-wasms/out/tree-sitter-yaml.wasm";
|
||||
|
||||
import Parser, { SyntaxNode } from "web-tree-sitter";
|
||||
import { ChunkWithoutID } from "../..";
|
||||
import { countTokens } from "../../llm/countTokens";
|
||||
|
||||
// export const fileExtensionToWasm: { [key: string]: string } = {
|
||||
// py: treeSitterPython,
|
||||
// js: treeSitterJavascript,
|
||||
// html: treeSitterHtml,
|
||||
// java: treeSitterJava,
|
||||
// go: treeSitterGo,
|
||||
// rb: treeSitterRuby,
|
||||
// rs: treeSitterRust,
|
||||
// c: treeSitterC,
|
||||
// cpp: treeSitterCpp,
|
||||
// cs: treeSitterCSharp,
|
||||
// php: treeSitterPhp,
|
||||
// css: treeSitterCss,
|
||||
// bash: treeSitterBash,
|
||||
// json: treeSitterJson,
|
||||
// ts: treeSitterTypescript,
|
||||
// tsx: treeSitterTsx,
|
||||
// vue: treeSitterVue,
|
||||
// yaml: treeSitterYaml,
|
||||
// toml: treeSitterToml,
|
||||
// ocaml: treeSitterOcaml,
|
||||
// elm: treeSitterElm,
|
||||
// // jl: treeSitterJulia,
|
||||
// // swift: "swift",
|
||||
// // kt: "kotlin",
|
||||
// // scala: treeSitterScala,
|
||||
// };
|
||||
|
||||
export const supportedLanguages: { [key: string]: string } = {
|
||||
cpp: "cpp",
|
||||
cs: "csharp",
|
||||
php: "php",
|
||||
css: "css",
|
||||
bash: "bash",
|
||||
json: "json",
|
||||
ts: "typescript",
|
||||
tsx: "tsx",
|
||||
vue: "vue",
|
||||
yaml: "yaml",
|
||||
toml: "toml",
|
||||
ocaml: "ocaml",
|
||||
elm: "elm",
|
||||
rb: "ruby",
|
||||
js: "javascript",
|
||||
// jl: "julia",
|
||||
// swift: "swift",
|
||||
// kt: "kotlin",
|
||||
// scala: "scala",
|
||||
};
|
||||
|
||||
async function getParserForFile(filepath: string) {
|
||||
await Parser.init();
|
||||
const parser = new Parser();
|
||||
const segs = filepath.split(".");
|
||||
const wasmPath = `${__dirname}/tree-sitter-wasms/tree-sitter-${
|
||||
supportedLanguages[segs[segs.length - 1]]
|
||||
}.wasm`;
|
||||
const Language = await Parser.Language.load(wasmPath);
|
||||
parser.setLanguage(Language);
|
||||
return parser;
|
||||
}
|
||||
import { getParserForFile } from "../../util/treeSitter";
|
||||
|
||||
function collapsedReplacement(node: SyntaxNode): string {
|
||||
if (node.type === "statement_block") {
|
||||
|
|
|
|||
|
|
@ -72,6 +72,26 @@ function countChatMessageTokens(
|
|||
return countTokens(chatMessage.content, modelName) + TOKENS_PER_MESSAGE;
|
||||
}
|
||||
|
||||
function pruneLinesFromTop(prompt: string, maxTokens: number): string {
|
||||
let totalTokens = countTokens(prompt, "gpt-4");
|
||||
const lines = prompt.split("\n");
|
||||
while (totalTokens > maxTokens && lines.length > 0) {
|
||||
totalTokens -= countTokens(lines.shift()!, "gpt-4");
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function pruneLinesFromBottom(prompt: string, maxTokens: number): string {
|
||||
let totalTokens = countTokens(prompt, "gpt-4");
|
||||
const lines = prompt.split("\n");
|
||||
while (totalTokens > maxTokens && lines.length > 0) {
|
||||
totalTokens -= countTokens(lines.pop()!, "gpt-4");
|
||||
}
|
||||
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function pruneStringFromBottom(
|
||||
modelName: string,
|
||||
maxTokens: number,
|
||||
|
|
@ -307,6 +327,9 @@ function compileChatMessages(
|
|||
export {
|
||||
compileChatMessages,
|
||||
countTokens,
|
||||
pruneLinesFromBottom,
|
||||
pruneLinesFromTop,
|
||||
pruneRawPromptFromTop,
|
||||
pruneStringFromBottom,
|
||||
pruneStringFromTop,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ class Ollama extends BaseLLM {
|
|||
"deepseek-7b": "deepseek-coder:6.7b",
|
||||
"deepseek-33b": "deepseek-coder:33b",
|
||||
"neural-chat-7b": "neural-chat:7b-v3.3",
|
||||
"starcoder-1b": "starcoder:1b",
|
||||
"starcoder-3b": "starcoder:3b",
|
||||
"stable-code-3b": "stable-code:3b",
|
||||
}[this.model] || this.model
|
||||
);
|
||||
}
|
||||
|
|
@ -204,6 +207,14 @@ class Ollama extends BaseLLM {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
async listModels(): Promise<string[]> {
|
||||
const response = await this.fetch(`${this.apiBase}/api/tags`, {
|
||||
method: "GET",
|
||||
});
|
||||
const data = await response.json();
|
||||
return data.models.map((model: any) => model.name);
|
||||
}
|
||||
}
|
||||
|
||||
export default Ollama;
|
||||
|
|
|
|||
|
|
@ -26,10 +26,13 @@ class Replicate extends BaseLLM {
|
|||
"nateraw/zephyr-7b-beta:b79f33de5c6c4e34087d44eaea4a9d98ce5d3f3a09522f7328eea0685003a931",
|
||||
"mistral-7b":
|
||||
"mistralai/mistral-7b-instruct-v0.1:83b6a56e7c828e667f21fd596c338fd4f0039b46bcfa18d973e8e70e455fda70",
|
||||
"mistral-8x7b": "mistralai/mixtral-8x7b-instruct-v0.1" as any,
|
||||
"wizardcoder-34b":
|
||||
"andreasjansson/wizardcoder-python-34b-v1-gguf:67eed332a5389263b8ede41be3ee7dc119fa984e2bde287814c4abed19a45e54",
|
||||
"neural-chat-7b":
|
||||
"tomasmcm/neural-chat-7b-v3-1:acb450496b49e19a1e410b50c574a34acacd54820bc36c19cbfe05148de2ba57",
|
||||
"deepseek-7b": "kcaverly/deepseek-coder-33b-instruct-gguf" as any,
|
||||
"phind-codellama-34b": "kcaverly/phind-codellama-34b-v2-gguf" as any,
|
||||
};
|
||||
|
||||
static providerName: ModelProvider = "replicate";
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class Together extends OpenAI {
|
|||
"mistral-7b": "mistralai/Mistral-7B-Instruct-v0.1",
|
||||
"mistral-8x7b": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
||||
"phind-codellama-34b": "Phind/Phind-CodeLlama-34B-v2",
|
||||
"wizardcoder-34b": "WizardLM/WizardCoder-Python-34B-V1.0",
|
||||
};
|
||||
|
||||
private _getModelName(model: string) {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ export function renderPromptTemplate(
|
|||
}
|
||||
}
|
||||
|
||||
export function getBasename(filepath: string): string {
|
||||
export function getBasename(filepath: string, n: number = 1): string {
|
||||
return filepath.split(/[\\/]/).pop() || "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -176,6 +176,10 @@ export function getLanceDbPath(): string {
|
|||
return path.join(getIndexFolderPath(), "lancedb");
|
||||
}
|
||||
|
||||
export function getTabAutocompleteCacheSqlitePath(): string {
|
||||
return path.join(getIndexFolderPath(), "autocompleteCache.sqlite");
|
||||
}
|
||||
|
||||
export function getDocsSqlitePath(): string {
|
||||
return path.join(getIndexFolderPath(), "docs.sqlite");
|
||||
}
|
||||
|
|
|
|||
92
core/util/treeSitter.ts
Normal file
92
core/util/treeSitter.ts
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
// import treeSitterBash from "tree-sitter-wasms/out/tree-sitter-bash.wasm";
|
||||
// import treeSitterC from "tree-sitter-wasms/out/tree-sitter-c.wasm";
|
||||
// import treeSitterCSharp from "tree-sitter-wasms/out/tree-sitter-c_sharp.wasm";
|
||||
// import treeSitterCpp from "tree-sitter-wasms/out/tree-sitter-cpp.wasm";
|
||||
// import treeSitterCss from "tree-sitter-wasms/out/tree-sitter-css.wasm";
|
||||
// // import treeSitterElisp from "tree-sitter-wasms/out/tree-sitter-elisp.wasm"
|
||||
// // import treeSitterElixir from "tree-sitter-wasms/out/tree-sitter-elixir.wasm"
|
||||
// import treeSitterElm from "tree-sitter-wasms/out/tree-sitter-elm.wasm";
|
||||
// // import treeSitterEmbeddedTemplate from "tree-sitter-wasms/out/tree-sitter-embedded_template.wasm"
|
||||
// import treeSitterGo from "tree-sitter-wasms/out/tree-sitter-go.wasm";
|
||||
// import treeSitterHtml from "tree-sitter-wasms/out/tree-sitter-html.wasm";
|
||||
// import treeSitterJava from "tree-sitter-wasms/out/tree-sitter-java.wasm";
|
||||
// import treeSitterJavascript from "tree-sitter-wasms/out/tree-sitter-javascript.wasm";
|
||||
// import treeSitterJson from "tree-sitter-wasms/out/tree-sitter-json.wasm";
|
||||
// // import treeSitterLua from "tree-sitter-wasms/out/tree-sitter-lua.wasm"
|
||||
// import treeSitterOcaml from "tree-sitter-wasms/out/tree-sitter-ocaml.wasm";
|
||||
// import treeSitterPhp from "tree-sitter-wasms/out/tree-sitter-php.wasm";
|
||||
// import treeSitterPython from "tree-sitter-wasms/out/tree-sitter-python.wasm";
|
||||
// // import treeSitterQl from "tree-sitter-wasms/out/tree-sitter-ql.wasm"
|
||||
// // import treeSitterRescript from "tree-sitter-wasms/out/tree-sitter-rescript.wasm"
|
||||
// import treeSitterRuby from "tree-sitter-wasms/out/tree-sitter-ruby.wasm";
|
||||
// import treeSitterRust from "tree-sitter-wasms/out/tree-sitter-rust.wasm";
|
||||
// // import treeSitterSystemRdl from "tree-sitter-wasms/out/tree-sitter-systemrdl.wasm"
|
||||
// import treeSitterToml from "tree-sitter-wasms/out/tree-sitter-toml.wasm";
|
||||
// import treeSitterTsx from "tree-sitter-wasms/out/tree-sitter-tsx.wasm";
|
||||
// import treeSitterTypescript from "tree-sitter-wasms/out/tree-sitter-typescript.wasm";
|
||||
// import treeSitterVue from "tree-sitter-wasms/out/tree-sitter-vue.wasm";
|
||||
// import treeSitterYaml from "tree-sitter-wasms/out/tree-sitter-yaml.wasm";
|
||||
|
||||
import Parser from "web-tree-sitter";
|
||||
|
||||
// export const fileExtensionToWasm: { [key: string]: string } = {
|
||||
// py: treeSitterPython,
|
||||
// js: treeSitterJavascript,
|
||||
// html: treeSitterHtml,
|
||||
// java: treeSitterJava,
|
||||
// go: treeSitterGo,
|
||||
// rb: treeSitterRuby,
|
||||
// rs: treeSitterRust,
|
||||
// c: treeSitterC,
|
||||
// cpp: treeSitterCpp,
|
||||
// cs: treeSitterCSharp,
|
||||
// php: treeSitterPhp,
|
||||
// css: treeSitterCss,
|
||||
// bash: treeSitterBash,
|
||||
// json: treeSitterJson,
|
||||
// ts: treeSitterTypescript,
|
||||
// tsx: treeSitterTsx,
|
||||
// vue: treeSitterVue,
|
||||
// yaml: treeSitterYaml,
|
||||
// toml: treeSitterToml,
|
||||
// ocaml: treeSitterOcaml,
|
||||
// elm: treeSitterElm,
|
||||
// // jl: treeSitterJulia,
|
||||
// // swift: "swift",
|
||||
// // kt: "kotlin",
|
||||
// // scala: treeSitterScala,
|
||||
// };
|
||||
|
||||
export const supportedLanguages: { [key: string]: string } = {
|
||||
cpp: "cpp",
|
||||
cs: "csharp",
|
||||
php: "php",
|
||||
css: "css",
|
||||
bash: "bash",
|
||||
json: "json",
|
||||
ts: "typescript",
|
||||
tsx: "tsx",
|
||||
vue: "vue",
|
||||
yaml: "yaml",
|
||||
toml: "toml",
|
||||
ocaml: "ocaml",
|
||||
elm: "elm",
|
||||
rb: "ruby",
|
||||
js: "javascript",
|
||||
// jl: "julia",
|
||||
// swift: "swift",
|
||||
// kt: "kotlin",
|
||||
// scala: "scala",
|
||||
};
|
||||
|
||||
export async function getParserForFile(filepath: string) {
|
||||
await Parser.init();
|
||||
const parser = new Parser();
|
||||
const segs = filepath.split(".");
|
||||
const wasmPath = `${__dirname}/tree-sitter-wasms/tree-sitter-${
|
||||
supportedLanguages[segs[segs.length - 1]]
|
||||
}.wasm`;
|
||||
const Language = await Parser.Language.load(wasmPath);
|
||||
parser.setLanguage(Language);
|
||||
return parser;
|
||||
}
|
||||
38
docs/static/schemas/config.json
vendored
38
docs/static/schemas/config.json
vendored
|
|
@ -435,10 +435,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -569,10 +572,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -610,10 +616,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -785,7 +794,6 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"claude-2",
|
||||
|
|
@ -793,7 +801,11 @@
|
|||
"gemini-pro",
|
||||
"mistral-tiny",
|
||||
"mistral-small",
|
||||
"mistral-medium"
|
||||
"mistral-medium",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -1295,6 +1307,16 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteModel": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"markdownDescription": "The model used for tab autocompletion. If undefined, Continue will not do tab autocompletion.",
|
||||
"default": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -435,10 +435,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -569,10 +572,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -610,10 +616,13 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"neural-chat-7b"
|
||||
"neural-chat-7b",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -785,7 +794,6 @@
|
|||
"wizardcoder-34b",
|
||||
"zephyr-7b",
|
||||
"codeup-13b",
|
||||
"deepseek-1b",
|
||||
"deepseek-7b",
|
||||
"deepseek-33b",
|
||||
"claude-2",
|
||||
|
|
@ -793,7 +801,11 @@
|
|||
"gemini-pro",
|
||||
"mistral-tiny",
|
||||
"mistral-small",
|
||||
"mistral-medium"
|
||||
"mistral-medium",
|
||||
"deepseek-1b",
|
||||
"stable-code-3b",
|
||||
"starcoder-1b",
|
||||
"starcoder-3b"
|
||||
]
|
||||
},
|
||||
{ "type": "string" }
|
||||
|
|
@ -1295,6 +1307,16 @@
|
|||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteModel": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"markdownDescription": "The model used for tab autocompletion. If undefined, Continue will not do tab autocompletion.",
|
||||
"default": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,13 @@
|
|||
function mergeSortAlgorithm(arr) {
|
||||
// TODO
|
||||
}
|
||||
import { factorial, repeat } from "./factorial";
|
||||
|
||||
function fib(n) {
|
||||
if (n <= 1) return n;
|
||||
return fib(n - 2) + fib(n - 1);
|
||||
}
|
||||
|
||||
let d = repeat(5, "a");
|
||||
console.log(d);
|
||||
|
||||
let e = factorial(3);
|
||||
console.log(e);
|
||||
|
||||
|
|
|
|||
8
extensions/vscode/manual-testing-sandbox/factorial.ts
Normal file
8
extensions/vscode/manual-testing-sandbox/factorial.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
export function factorial(n) {
|
||||
if (n <= 1) return 1;
|
||||
return n * factorial(n - 1);
|
||||
}
|
||||
|
||||
export function repeat(n: number, a: string) {
|
||||
return a.repeat(n);
|
||||
}
|
||||
1819
extensions/vscode/package-lock.json
generated
1819
extensions/vscode/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "continue",
|
||||
"icon": "media/icon.png",
|
||||
"version": "0.9.42",
|
||||
"version": "0.9.43",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/continuedev/continue"
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
"description": "Open-source autopilot for software development - bring the power of ChatGPT to your IDE",
|
||||
"publisher": "Continue",
|
||||
"engines": {
|
||||
"vscode": "^1.67.0"
|
||||
"vscode": "^1.70.0"
|
||||
},
|
||||
"galleryBanner": {
|
||||
"color": "#1E1E1E",
|
||||
|
|
@ -55,17 +55,17 @@
|
|||
"continue.telemetryEnabled": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Continue collects anonymous usage data, cleaned of PII, to help us improve the product for our users. Read more at https://continue.dev/docs/telemetry."
|
||||
"markdownDescription": "Continue collects anonymous usage data, cleaned of PII, to help us improve the product for our users. Read more at [continue.dev › Telemetry](https://continue.dev/docs/telemetry)."
|
||||
},
|
||||
"continue.showInlineTip": {
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
"description": "Show inline suggestion to use the Continue keyboard shortcuts."
|
||||
},
|
||||
"continue.proxyServerUrl": {
|
||||
"type": "string",
|
||||
"default": "http://localhost:65433",
|
||||
"description": "An optional proxy server URL through which you can route all Continue requests. Do not change this unless you have set up your own server to proxy requests."
|
||||
"continue.enableTabAutocomplete": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"markdownDescription": "Enable Continue's experimental tab autocomplete feature. Read our walkthrough to learn about configuration and how to share feedback: [continue.dev › Walkthrough: Tab Autocomplete](https://continue.dev/docs/walkthroughs/tab-autocomplete)"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -430,7 +430,7 @@
|
|||
"@types/node-fetch": "^2.6.2",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"@types/request": "^2.48.8",
|
||||
"@types/vscode": "1.67",
|
||||
"@types/vscode": "1.70",
|
||||
"@types/ws": "^8.5.4",
|
||||
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
||||
"@typescript-eslint/parser": "^5.45.0",
|
||||
|
|
@ -459,6 +459,7 @@
|
|||
"express": "^4.18.2",
|
||||
"fkill": "^8.1.0",
|
||||
"follow-redirects": "^1.15.4",
|
||||
"handlebars": "^4.7.8",
|
||||
"highlight.js": "^11.7.0",
|
||||
"highlightable": "^1.3.0-beta.0",
|
||||
"http-proxy": "^1.18.1",
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ if (args[2] === "--target") {
|
|||
execSync("npm install");
|
||||
console.log("npm install in gui completed");
|
||||
|
||||
execSync("npm run build");
|
||||
if (ghAction()) {
|
||||
execSync("npm run build");
|
||||
}
|
||||
|
||||
// Copy over the dist folder to the Intellij extension //
|
||||
const intellijExtensionWebviewPath = path.join(
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ import IdeProtocolClient from "../continueIdeClient";
|
|||
import { ContinueGUIWebviewViewProvider } from "../debugPanel";
|
||||
import registerQuickFixProvider from "../lang-server/codeActions";
|
||||
import { registerAllCodeLensProviders } from "../lang-server/codeLens";
|
||||
import {
|
||||
ContinueCompletionProvider,
|
||||
setupStatusBar,
|
||||
} from "../lang-server/completionProvider";
|
||||
import { vsCodeIndexCodebase } from "../util/indexCodebase";
|
||||
import { getExtensionUri } from "../util/vscode";
|
||||
import { setupInlineTips } from "./inlineTips";
|
||||
|
|
@ -85,6 +89,17 @@ export async function activateExtension(context: vscode.ExtensionContext) {
|
|||
await openTutorialFirstTime(context);
|
||||
setupInlineTips(context);
|
||||
showRefactorMigrationMessage();
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get<boolean>("enableTabAutocomplete");
|
||||
setupStatusBar(enabled);
|
||||
|
||||
// Register inline completion provider
|
||||
context.subscriptions.push(
|
||||
vscode.languages.registerInlineCompletionItemProvider(
|
||||
[{ pattern: "**" }],
|
||||
new ContinueCompletionProvider()
|
||||
)
|
||||
);
|
||||
|
||||
ideProtocolClient = new IdeProtocolClient(context);
|
||||
|
||||
|
|
|
|||
|
|
@ -74,7 +74,10 @@ export function setupInlineTips(context: vscode.ExtensionContext) {
|
|||
context.subscriptions.push(
|
||||
vscode.window.onDidChangeActiveTextEditor((editor) => {
|
||||
if (editor?.document.getText() === "") {
|
||||
if (editor.document.uri.toString().startsWith("output:")) {
|
||||
if (
|
||||
editor.document.uri.toString().startsWith("output:") ||
|
||||
editor.document.uri.scheme === "comment"
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import {
|
|||
streamEdit,
|
||||
verticalPerLineDiffManager,
|
||||
} from "./diff/verticalPerLine/manager";
|
||||
import { AutocompleOutcome } from "./lang-server/completionProvider";
|
||||
|
||||
function addHighlightedCodeToContext(edit: boolean) {
|
||||
const editor = vscode.window.activeTextEditor;
|
||||
|
|
@ -322,6 +323,23 @@ const commandsMap: { [command: string]: (...args: any) => any } = {
|
|||
`/references ${filepath.fsPath} ${position.line} ${position.character}`
|
||||
);
|
||||
},
|
||||
"continue.logAutocompleteOutcome": (
|
||||
outcome: AutocompleOutcome,
|
||||
logRejectionTimeout: NodeJS.Timeout
|
||||
) => {
|
||||
clearTimeout(logRejectionTimeout);
|
||||
outcome.accepted = true;
|
||||
ideProtocolClient.logDevData("autocomplete", outcome);
|
||||
},
|
||||
"continue.toggleTabAutocompleteEnabled": () => {
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get("enableTabAutocomplete");
|
||||
config.update(
|
||||
"enableTabAutocomplete",
|
||||
!enabled,
|
||||
vscode.ConfigurationTarget.Global
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export function registerAllCommands(context: vscode.ExtensionContext) {
|
||||
|
|
|
|||
|
|
@ -410,6 +410,21 @@ class IdeProtocolClient {
|
|||
return contents;
|
||||
}
|
||||
|
||||
async readRangeInFile(
|
||||
filepath: string,
|
||||
range: vscode.Range
|
||||
): Promise<string> {
|
||||
const contents = new TextDecoder().decode(
|
||||
await vscode.workspace.fs.readFile(vscode.Uri.file(filepath))
|
||||
);
|
||||
const lines = contents.split("\n");
|
||||
return (
|
||||
lines.slice(range.start.line, range.end.line).join("\n") +
|
||||
"\n" +
|
||||
lines[range.end.line].slice(0, range.end.character)
|
||||
);
|
||||
}
|
||||
|
||||
async getTerminalContents(commands: number = -1): Promise<string> {
|
||||
const tempCopyBuffer = await vscode.env.clipboard.readText();
|
||||
if (commands < 0) {
|
||||
|
|
|
|||
279
extensions/vscode/src/lang-server/completionProvider.ts
Normal file
279
extensions/vscode/src/lang-server/completionProvider.ts
Normal file
|
|
@ -0,0 +1,279 @@
|
|||
import { AutocompleteLruCache } from "core/autocomplete/cache";
|
||||
import {
|
||||
AutocompleteSnippet,
|
||||
constructAutocompletePrompt,
|
||||
languageForFilepath,
|
||||
} from "core/autocomplete/constructPrompt";
|
||||
import { DEBOUNCE_DELAY } from "core/autocomplete/parameters";
|
||||
import { getTemplateForModel } from "core/autocomplete/templates";
|
||||
import Handlebars from "handlebars";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import * as vscode from "vscode";
|
||||
import { ideProtocolClient } from "../activation/activate";
|
||||
import { TabAutocompleteModel } from "../loadConfig";
|
||||
|
||||
const statusBarItemText = (enabled: boolean | undefined) =>
|
||||
enabled ? "$(check) Continue" : "$(circle-slash) Continue";
|
||||
|
||||
const statusBarItemTooltip = (enabled: boolean | undefined) =>
|
||||
enabled ? "Tab autocomplete is enabled" : "Click to enable tab autocomplete";
|
||||
|
||||
let lastStatusBar: vscode.StatusBarItem | undefined = undefined;
|
||||
export function setupStatusBar(
|
||||
enabled: boolean | undefined,
|
||||
loading?: boolean
|
||||
) {
|
||||
const statusBarItem = vscode.window.createStatusBarItem(
|
||||
vscode.StatusBarAlignment.Right
|
||||
);
|
||||
statusBarItem.text = loading
|
||||
? "$(loading~spin) Continue"
|
||||
: statusBarItemText(enabled);
|
||||
statusBarItem.tooltip = statusBarItemTooltip(enabled);
|
||||
statusBarItem.command = "continue.toggleTabAutocompleteEnabled";
|
||||
|
||||
// Swap out with old status bar
|
||||
if (lastStatusBar) {
|
||||
lastStatusBar.dispose();
|
||||
}
|
||||
statusBarItem.show();
|
||||
lastStatusBar = statusBarItem;
|
||||
|
||||
vscode.workspace.onDidChangeConfiguration((event) => {
|
||||
if (event.affectsConfiguration("continue")) {
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get<boolean>("enableTabAutocomplete");
|
||||
statusBarItem.dispose();
|
||||
setupStatusBar(enabled);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function getDefinition(
|
||||
filepath: string,
|
||||
line: number,
|
||||
character: number
|
||||
): Promise<AutocompleteSnippet | undefined> {
|
||||
const definitions = (await vscode.commands.executeCommand(
|
||||
"vscode.executeDefinitionProvider",
|
||||
vscode.Uri.file(filepath),
|
||||
new vscode.Position(line, character)
|
||||
)) as any;
|
||||
|
||||
if (definitions[0]?.targetRange) {
|
||||
return {
|
||||
filepath,
|
||||
content: await ideProtocolClient.readRangeInFile(
|
||||
definitions[0].targetUri.fsPath,
|
||||
definitions[0].targetRange
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface AutocompleOutcome {
|
||||
accepted?: boolean;
|
||||
time: number;
|
||||
prompt: string;
|
||||
completion: string;
|
||||
modelProvider: string;
|
||||
modelName: string;
|
||||
completionOptions: any;
|
||||
}
|
||||
|
||||
const autocompleteCache = AutocompleteLruCache.get();
|
||||
|
||||
async function getTabCompletion(
|
||||
document: vscode.TextDocument,
|
||||
pos: vscode.Position,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<AutocompleOutcome | undefined> {
|
||||
const startTime = Date.now();
|
||||
|
||||
// Filter
|
||||
const lang = languageForFilepath(document.fileName);
|
||||
const line = document.lineAt(pos).text;
|
||||
for (const endOfLine of lang.endOfLine) {
|
||||
if (line.endsWith(endOfLine) && pos.character >= endOfLine.length) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// Model
|
||||
const llm = await TabAutocompleteModel.get();
|
||||
if (!llm) return;
|
||||
|
||||
// Prompt
|
||||
const fullPrefix = document.getText(
|
||||
new vscode.Range(new vscode.Position(0, 0), pos)
|
||||
);
|
||||
const fullSuffix = document.getText(
|
||||
new vscode.Range(
|
||||
pos,
|
||||
new vscode.Position(document.lineCount, Number.MAX_SAFE_INTEGER)
|
||||
)
|
||||
);
|
||||
const clipboardText = await vscode.env.clipboard.readText();
|
||||
const { prefix, suffix } = await constructAutocompletePrompt(
|
||||
document.fileName,
|
||||
fullPrefix,
|
||||
fullSuffix,
|
||||
clipboardText,
|
||||
lang,
|
||||
getDefinition
|
||||
);
|
||||
|
||||
const { template, completionOptions } = getTemplateForModel(llm.model);
|
||||
|
||||
const compiledTemplate = Handlebars.compile(template);
|
||||
const prompt = compiledTemplate({ prefix, suffix });
|
||||
|
||||
// Completion
|
||||
let completion = "";
|
||||
|
||||
const cache = await autocompleteCache;
|
||||
const cachedCompletion = await cache.get(prompt);
|
||||
if (cachedCompletion) {
|
||||
// Cache
|
||||
completion = cachedCompletion;
|
||||
} else {
|
||||
setupStatusBar(true, true);
|
||||
|
||||
// LLM
|
||||
for await (const update of llm.streamComplete(prompt, {
|
||||
...completionOptions,
|
||||
temperature: 0,
|
||||
raw: true,
|
||||
stop: [
|
||||
...(completionOptions?.stop || []),
|
||||
"\n\n",
|
||||
"```",
|
||||
...lang.stopWords,
|
||||
],
|
||||
})) {
|
||||
completion += update;
|
||||
if (token.isCancellationRequested) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let foundEndLine = false;
|
||||
for (const end of lang.endOfLine) {
|
||||
if (completion.includes(end + "\n")) {
|
||||
completion =
|
||||
completion.slice(0, completion.indexOf(end + "\n")) + end;
|
||||
foundEndLine = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (foundEndLine) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Don't return empty
|
||||
if (completion.trim().length <= 0) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Post-processing
|
||||
completion = completion.trimEnd();
|
||||
}
|
||||
|
||||
const time = Date.now() - startTime;
|
||||
return {
|
||||
time,
|
||||
completion,
|
||||
prompt,
|
||||
modelProvider: llm.providerName,
|
||||
modelName: llm.model,
|
||||
completionOptions,
|
||||
};
|
||||
} catch (e) {
|
||||
console.warn("Error generating autocompletion: ", e);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class ContinueCompletionProvider
|
||||
implements vscode.InlineCompletionItemProvider
|
||||
{
|
||||
private static debounceTimeout: NodeJS.Timeout | undefined = undefined;
|
||||
private static debouncing: boolean = false;
|
||||
private static lastUUID: string | undefined = undefined;
|
||||
|
||||
public async provideInlineCompletionItems(
|
||||
document: vscode.TextDocument,
|
||||
position: vscode.Position,
|
||||
context: vscode.InlineCompletionContext,
|
||||
token: vscode.CancellationToken
|
||||
//@ts-ignore
|
||||
): ProviderResult<InlineCompletionItem[] | InlineCompletionList> {
|
||||
// Debounce
|
||||
const uuid = uuidv4();
|
||||
ContinueCompletionProvider.lastUUID = uuid;
|
||||
|
||||
if (ContinueCompletionProvider.debouncing) {
|
||||
ContinueCompletionProvider.debounceTimeout?.refresh();
|
||||
const lastUUID = await new Promise((resolve) =>
|
||||
setTimeout(() => {
|
||||
resolve(ContinueCompletionProvider.lastUUID);
|
||||
}, DEBOUNCE_DELAY)
|
||||
);
|
||||
if (uuid !== lastUUID) {
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
ContinueCompletionProvider.debouncing = true;
|
||||
ContinueCompletionProvider.debounceTimeout = setTimeout(async () => {
|
||||
ContinueCompletionProvider.debouncing = false;
|
||||
}, DEBOUNCE_DELAY);
|
||||
}
|
||||
|
||||
const enableTabAutocomplete =
|
||||
vscode.workspace
|
||||
.getConfiguration("continue")
|
||||
.get<boolean>("enableTabAutocomplete") || false;
|
||||
if (token.isCancellationRequested || !enableTabAutocomplete) {
|
||||
return [];
|
||||
}
|
||||
|
||||
try {
|
||||
const outcome = await getTabCompletion(document, position, token);
|
||||
const completion = outcome?.completion;
|
||||
|
||||
if (!completion) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Do some stuff later so as not to block return. Latency matters
|
||||
setTimeout(async () => {
|
||||
(await autocompleteCache).put(outcome.prompt, completion);
|
||||
}, 100);
|
||||
|
||||
const logRejectionTimeout = setTimeout(() => {
|
||||
// Wait 10 seconds, then assume it wasn't accepted
|
||||
outcome.accepted = false;
|
||||
ideProtocolClient.logDevData("autocomplete", outcome);
|
||||
}, 10_000);
|
||||
|
||||
return [
|
||||
new vscode.InlineCompletionItem(
|
||||
completion,
|
||||
new vscode.Range(position, position.translate(0, completion.length)),
|
||||
{
|
||||
title: "Log Autocomplete Outcome",
|
||||
command: "continue.logAutocompleteOutcome",
|
||||
arguments: [outcome, logRejectionTimeout],
|
||||
}
|
||||
),
|
||||
];
|
||||
} catch (e: any) {
|
||||
console.log("Error getting autocompletion: ", e.message);
|
||||
} finally {
|
||||
setupStatusBar(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import { ContinueConfig, IDE, ILLM } from "core";
|
||||
import Ollama from "core/llm/llms/Ollama";
|
||||
import * as fs from "fs";
|
||||
import { Agent, ProxyAgent, fetch } from "undici";
|
||||
import * as vscode from "vscode";
|
||||
|
|
@ -30,29 +31,7 @@ export const configHandler = new VsCodeConfigHandler();
|
|||
|
||||
const TIMEOUT = 7200; // 7200 seconds = 2 hours
|
||||
|
||||
export async function llmFromTitle(title?: string): Promise<ILLM> {
|
||||
let config = await configHandler.loadConfig(new VsCodeIde());
|
||||
|
||||
if (title === undefined) {
|
||||
const resp = await webviewRequest("getDefaultModelTitle");
|
||||
if (resp?.defaultModelTitle) {
|
||||
title = resp.defaultModelTitle;
|
||||
}
|
||||
}
|
||||
|
||||
let llm = title
|
||||
? config.models.find((llm) => llm.title === title)
|
||||
: config.models[0];
|
||||
if (!llm) {
|
||||
// Try to reload config
|
||||
configHandler.reloadConfig();
|
||||
config = await configHandler.loadConfig(new VsCodeIde());
|
||||
llm = config.models.find((llm) => llm.title === title);
|
||||
if (!llm) {
|
||||
throw new Error(`Unknown model ${title}`);
|
||||
}
|
||||
}
|
||||
|
||||
function setupLlm(llm: ILLM): ILLM {
|
||||
// Since we know this is happening in Node.js, we can add requestOptions through a custom agent
|
||||
const ca = [...tls.rootCertificates];
|
||||
const customCerts =
|
||||
|
|
@ -128,6 +107,111 @@ export async function llmFromTitle(title?: string): Promise<ILLM> {
|
|||
|
||||
outputChannel.append(log);
|
||||
};
|
||||
|
||||
return llm;
|
||||
}
|
||||
|
||||
export async function llmFromTitle(title?: string): Promise<ILLM> {
|
||||
let config = await configHandler.loadConfig(new VsCodeIde());
|
||||
|
||||
if (title === undefined) {
|
||||
const resp = await webviewRequest("getDefaultModelTitle");
|
||||
if (resp?.defaultModelTitle) {
|
||||
title = resp.defaultModelTitle;
|
||||
}
|
||||
}
|
||||
|
||||
let llm = title
|
||||
? config.models.find((llm) => llm.title === title)
|
||||
: config.models[0];
|
||||
if (!llm) {
|
||||
// Try to reload config
|
||||
configHandler.reloadConfig();
|
||||
config = await configHandler.loadConfig(new VsCodeIde());
|
||||
llm = config.models.find((llm) => llm.title === title);
|
||||
if (!llm) {
|
||||
throw new Error(`Unknown model ${title}`);
|
||||
}
|
||||
}
|
||||
|
||||
return setupLlm(llm);
|
||||
}
|
||||
|
||||
export class TabAutocompleteModel {
|
||||
private static _llm: ILLM | undefined;
|
||||
private static defaultTag: string = "deepseek-coder:1.3b-base";
|
||||
|
||||
private static shownOllamaWarning: boolean = false;
|
||||
private static shownDeepseekWarning: boolean = false;
|
||||
|
||||
static async getDefaultTabAutocompleteModel() {
|
||||
const llm = new Ollama({
|
||||
model: TabAutocompleteModel.defaultTag,
|
||||
});
|
||||
|
||||
// Check that deepseek is already downloaded
|
||||
try {
|
||||
const models = await llm.listModels();
|
||||
if (!models.includes(TabAutocompleteModel.defaultTag)) {
|
||||
// Raise warning and explain how to download
|
||||
if (!TabAutocompleteModel.shownDeepseekWarning) {
|
||||
vscode.window
|
||||
.showWarningMessage(
|
||||
`Your local Ollama instance doesn't yet have DeepSeek Coder. To download this model, run \`ollama run deepseek-coder:1.3b-base\` (recommended). If you'd like to use a custom model for tab autocomplete, learn more in the docs`,
|
||||
"Documentation",
|
||||
"Copy Command"
|
||||
)
|
||||
.then((value) => {
|
||||
if (value === "Documentation") {
|
||||
vscode.env.openExternal(
|
||||
vscode.Uri.parse(
|
||||
"https://continue.dev/docs/walkthroughs/tab-autocomplete"
|
||||
)
|
||||
);
|
||||
} else if (value === "Copy Command") {
|
||||
vscode.env.clipboard.writeText(
|
||||
"ollama run deepseek-coder:1.3b-base"
|
||||
);
|
||||
}
|
||||
});
|
||||
TabAutocompleteModel.shownDeepseekWarning = true;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
} catch (e) {
|
||||
if (!TabAutocompleteModel.shownOllamaWarning) {
|
||||
vscode.window
|
||||
.showWarningMessage(
|
||||
"Continue failed to connect to Ollama, which is used by default for tab-autocomplete. If you haven't downloaded it yet, you can do so at https://ollama.ai (recommended). If you'd like to use a custom model for tab autocomplete, learn more in the docs",
|
||||
"Documentation"
|
||||
)
|
||||
.then((value) => {
|
||||
if (value === "Documentation") {
|
||||
vscode.env.openExternal(
|
||||
vscode.Uri.parse(
|
||||
"https://continue.dev/docs/walkthroughs/tab-autocomplete"
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
TabAutocompleteModel.shownOllamaWarning = true;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return llm;
|
||||
}
|
||||
|
||||
static async get() {
|
||||
if (!TabAutocompleteModel._llm) {
|
||||
const config = await configHandler.loadConfig(new VsCodeIde());
|
||||
if (config.tabAutocompleteModel) {
|
||||
TabAutocompleteModel._llm = setupLlm(config.tabAutocompleteModel);
|
||||
} else {
|
||||
TabAutocompleteModel._llm =
|
||||
await TabAutocompleteModel.getDefaultTabAutocompleteModel();
|
||||
}
|
||||
}
|
||||
|
||||
return TabAutocompleteModel._llm;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -412,11 +412,31 @@ const deepseek: ModelPackage = {
|
|||
description:
|
||||
"A model pre-trained on 2 trillion tokens including 80+ programming languages and a repo-level corpus.",
|
||||
params: {
|
||||
title: "DeepSeek",
|
||||
title: "DeepSeek-7b",
|
||||
model: "deepseek-7b",
|
||||
contextLength: 4096,
|
||||
},
|
||||
providerOptions: ["lmstudio", "llamacpp"],
|
||||
dimensions: [
|
||||
{
|
||||
name: "Parameter Count",
|
||||
description: "The number of parameters in the model",
|
||||
options: {
|
||||
"1b": {
|
||||
model: "deepseek-1b",
|
||||
title: "DeepSeek-1b",
|
||||
},
|
||||
"7b": {
|
||||
model: "deepseek-7b",
|
||||
title: "DeepSeek-7b",
|
||||
},
|
||||
"33b": {
|
||||
model: "deepseek-33b",
|
||||
title: "DeepSeek-33b",
|
||||
},
|
||||
}
|
||||
},
|
||||
],
|
||||
providerOptions: ["ollama", "lmstudio", "llamacpp"],
|
||||
};
|
||||
|
||||
const codeup: ModelPackage = {
|
||||
|
|
@ -451,6 +471,7 @@ const osModels = [
|
|||
codeup,
|
||||
zephyr,
|
||||
neuralChat,
|
||||
deepseek,
|
||||
];
|
||||
|
||||
const gpt4turbo: ModelPackage = {
|
||||
|
|
@ -703,7 +724,7 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
|
|||
params: {
|
||||
apiBase: "http://localhost:1234/v1",
|
||||
},
|
||||
packages: [...osModels, deepseek],
|
||||
packages: osModels,
|
||||
collectInputFor: [...completionParamsInputs],
|
||||
},
|
||||
replicate: {
|
||||
|
|
@ -752,7 +773,7 @@ export const PROVIDER_INFO: { [key: string]: ModelInfo } = {
|
|||
After it's up and running, you can start using Continue.`,
|
||||
icon: "llamacpp.png",
|
||||
tags: [ModelProviderTag.Local, ModelProviderTag["Open-Source"]],
|
||||
packages: [...osModels, deepseek],
|
||||
packages: osModels,
|
||||
collectInputFor: [...completionParamsInputs],
|
||||
},
|
||||
palm: {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue