Merge branch 'preview' into nate/refactor-core
This commit is contained in:
commit
3355d18617
282 changed files with 37091 additions and 34761 deletions
|
|
@ -56,9 +56,12 @@ Continue is continuously improving, but a feature isn't complete until it is ref
|
|||
|
||||
### Environment Setup
|
||||
|
||||
#### VS Code
|
||||
#### Pre-requisites
|
||||
|
||||
Pre-requisite: You should have Node.js version 20.11.0 (LTS) or higher installed. You can get it on [nodejs.org](https://nodejs.org/en/download) or, if you are using NVM (Node Version Manager), you can set the correct version of Node.js for this project by running the following command in the root of the project:
|
||||
- You should have Node.js version 20.11.0 (LTS) or higher installed. You can get it on [nodejs.org](https://nodejs.org/en/download) or, if you are using NVM (Node Version Manager), you can set the correct version of Node.js for this project by running the following command in the root of the project:
|
||||
- Continue uses `pnpm` to manage node_modules. You can install `pnpm` globally with `npm install -g pnpm`, or another method described in [their docs](https://pnpm.io/installation#using-npm).
|
||||
|
||||
#### VS Code
|
||||
|
||||
```bash
|
||||
nvm use
|
||||
|
|
@ -77,7 +80,7 @@ nvm use
|
|||
1. The new VS Code window with the extension is referred to as the _Host VS Code_
|
||||
2. The window you started debugging from is referred to as the _Main VS Code_
|
||||
|
||||
4. To package the extension, run `npm run package` in the `extensions/vscode` directory. This will generate `extensions/vscode/build/continue-patch.vsix`, which you can install by right-clicking and selecting "Install Extension VSIX".
|
||||
4. To package the extension, run `pnpm package` in the `extensions/vscode` directory. This will generate `extensions/vscode/build/continue-patch.vsix`, which you can install by right-clicking and selecting "Install Extension VSIX".
|
||||
|
||||
> Note: Breakpoints can be used in both the `core` and `extensions/vscode` folders while debugging, but are not currently supported inside of `gui` code. Hot-reloading is enabled with Vite, so if you make any changes to the `gui`, they should be automatically reflected without rebuilding. Similarly, any changes to `core` or `extensions/vscode` will be automatically included by just reloading the _Host VS Code_ window with cmd/ctrl+shift+p "Reload Window".
|
||||
|
||||
|
|
|
|||
3058
binary/package-lock.json
generated
3058
binary/package-lock.json
generated
File diff suppressed because it is too large
Load diff
5758
binary/pnpm-lock.yaml
generated
Normal file
5758
binary/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
27
core/.eslintrc.json
Normal file
27
core/.eslintrc.json
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6,
|
||||
"sourceType": "module"
|
||||
},
|
||||
"extends": ["plugin:require-extensions/recommended"],
|
||||
"plugins": ["@typescript-eslint", "import", "require-extensions"],
|
||||
"rules": {
|
||||
"quotes": ["warn", "double", {}],
|
||||
"import/extensions": ["error", "always", {
|
||||
"js": "never",
|
||||
"jsx": "never",
|
||||
"ts": "never",
|
||||
"tsx": "never"
|
||||
}],
|
||||
"@typescript-eslint/naming-convention": "warn",
|
||||
"@typescript-eslint/semi": "warn",
|
||||
"curly": "warn",
|
||||
"eqeqeq": "warn",
|
||||
"no-throw-literal": "warn",
|
||||
"semi": "off"
|
||||
},
|
||||
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
|
||||
}
|
||||
|
||||
|
|
@ -14,15 +14,28 @@ Once it has been downloaded, you should begin to see completions in VS Code.
|
|||
|
||||
## Setting up a custom model
|
||||
|
||||
All of the configuration options available for chat models are available to use for tab-autocomplete. For example, if you wanted to use a remote Ollama instance you would edit your `config.json` like this (note that it is not inside the models array):
|
||||
All of the configuration options available for chat models are available to use for tab-autocomplete. For example, if you wanted to use a remote vLLM instance you would edit your `config.json` like this (note that it is not inside the models array), filling in the correct model name and vLLM endpoint:
|
||||
|
||||
```json title=~/.continue/config.json
|
||||
{
|
||||
"tabAutocompleteModel": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"provider": "openai",
|
||||
"model": "<MODEL_NAME>",
|
||||
"apiBase": "<VLLM_ENDPOINT_URL>"
|
||||
},
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
As another example, say you want to use a different model, `deepseek-coder:6.7b-base`, with Ollama:
|
||||
|
||||
```json title=~/.continue/config.json
|
||||
{
|
||||
"tabAutocompleteModel": {
|
||||
"title": "Tab Autocomplete Model",
|
||||
"provider": "ollama",
|
||||
"model": "starcoder:3b",
|
||||
"apiBase": "https://<my endpoint>"
|
||||
"model": "deepseek-coder:6.7b-base"
|
||||
},
|
||||
...
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type Parser from "web-tree-sitter";
|
||||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import { getParserForFile } from "../util/treeSitter";
|
||||
import Parser from "web-tree-sitter";
|
||||
import { RangeInFileWithContents } from "../commands/util.js";
|
||||
import { getParserForFile } from "../util/treeSitter.js";
|
||||
|
||||
export async function getAst(
|
||||
filepath: string,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { open } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
import type { DatabaseConnection } from "../indexing/refreshIndex";
|
||||
import { getTabAutocompleteCacheSqlitePath } from "../util/paths";
|
||||
import { DatabaseConnection } from "../indexing/refreshIndex.js";
|
||||
import { getTabAutocompleteCacheSqlitePath } from "../util/paths.js";
|
||||
|
||||
export class AutocompleteLruCache {
|
||||
private static capacity = 1000;
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ export async function* noFirstCharNewline(stream: AsyncGenerator<string>) {
|
|||
for await (const char of stream) {
|
||||
if (first) {
|
||||
first = false;
|
||||
if (char === "\n") return;
|
||||
if (char === "\n") {return;}
|
||||
}
|
||||
yield char;
|
||||
}
|
||||
|
|
@ -48,9 +48,9 @@ export async function* stopOnUnmatchedClosingBracket(
|
|||
): AsyncGenerator<string> {
|
||||
const stack: string[] = [];
|
||||
for (let i = 0; i < suffix.length; i++) {
|
||||
if (suffix[i] === " ") continue;
|
||||
if (suffix[i] === " ") {continue;}
|
||||
const openBracket = BRACKETS_REVERSE[suffix[i]];
|
||||
if (!openBracket) break;
|
||||
if (!openBracket) {break;}
|
||||
stack.unshift(openBracket);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,30 +2,37 @@ import Handlebars from "handlebars";
|
|||
import ignore from "ignore";
|
||||
import path from "path";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import type { IDE, ILLM, Position, Range, TabAutocompleteOptions } from "..";
|
||||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import type { ConfigHandler } from "../config/handler";
|
||||
import { streamLines } from "../diff/util";
|
||||
import OpenAI from "../llm/llms/OpenAI";
|
||||
import { getBasename } from "../util";
|
||||
import { logDevData } from "../util/devdata";
|
||||
import { RangeInFileWithContents } from "../commands/util.js";
|
||||
import { ConfigHandler } from "../config/handler.js";
|
||||
import { streamLines } from "../diff/util.js";
|
||||
import {
|
||||
IDE,
|
||||
ILLM,
|
||||
Position,
|
||||
Range,
|
||||
TabAutocompleteOptions,
|
||||
} from "../index.js";
|
||||
import OpenAI from "../llm/llms/OpenAI.js";
|
||||
import { logDevData } from "../util/devdata.js";
|
||||
import { getBasename } from "../util/index.js";
|
||||
import {
|
||||
COUNT_COMPLETION_REJECTED_AFTER,
|
||||
DEFAULT_AUTOCOMPLETE_OPTS,
|
||||
} from "../util/parameters";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
import { getRangeInString } from "../util/ranges";
|
||||
import AutocompleteLruCache from "./cache";
|
||||
} from "../util/parameters.js";
|
||||
import { Telemetry } from "../util/posthog.js";
|
||||
import { getRangeInString } from "../util/ranges.js";
|
||||
import AutocompleteLruCache from "./cache.js";
|
||||
import {
|
||||
noFirstCharNewline,
|
||||
onlyWhitespaceAfterEndOfLine,
|
||||
stopOnUnmatchedClosingBracket,
|
||||
} from "./charStream";
|
||||
} from "./charStream.js";
|
||||
import {
|
||||
constructAutocompletePrompt,
|
||||
languageForFilepath,
|
||||
} from "./constructPrompt";
|
||||
import type { AutocompleteLanguageInfo } from "./languages";
|
||||
} from "./constructPrompt.js";
|
||||
import { isOnlyPunctuationAndWhitespace } from "./filter.js";
|
||||
import { AutocompleteLanguageInfo } from "./languages.js";
|
||||
import {
|
||||
avoidPathLine,
|
||||
noTopLevelKeywordsMidline,
|
||||
|
|
@ -33,17 +40,18 @@ import {
|
|||
stopAtRepeatingLines,
|
||||
stopAtSimilarLine,
|
||||
streamWithNewLines,
|
||||
} from "./lineStream";
|
||||
import type { AutocompleteSnippet } from "./ranking";
|
||||
import { getTemplateForModel } from "./templates";
|
||||
import { GeneratorReuseManager } from "./util";
|
||||
} from "./lineStream.js";
|
||||
import { AutocompleteSnippet } from "./ranking.js";
|
||||
import { RecentlyEditedRange } from "./recentlyEdited.js";
|
||||
import { getTemplateForModel } from "./templates.js";
|
||||
import { GeneratorReuseManager } from "./util.js";
|
||||
|
||||
export interface AutocompleteInput {
|
||||
completionId: string;
|
||||
filepath: string;
|
||||
pos: Position;
|
||||
recentlyEditedFiles: RangeInFileWithContents[];
|
||||
recentlyEditedRanges: RangeInFileWithContents[];
|
||||
recentlyEditedRanges: RecentlyEditedRange[];
|
||||
clipboardText: string;
|
||||
// Used for notebook files
|
||||
manuallyPassFileContents?: string;
|
||||
|
|
@ -53,6 +61,7 @@ export interface AutocompleteInput {
|
|||
text: string;
|
||||
range: Range;
|
||||
};
|
||||
injectDetails?: string;
|
||||
}
|
||||
|
||||
export interface AutocompleteOutcome extends TabAutocompleteOptions {
|
||||
|
|
@ -77,7 +86,7 @@ const STARCODER2_T_ARTIFACTS = ["t.", "\nt", "<file_sep>"];
|
|||
const PYTHON_ENCODING = "#- coding: utf-8";
|
||||
const CODE_BLOCK_END = "```";
|
||||
|
||||
const multilineStops: string[] = []; // [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE];
|
||||
const multilineStops: string[] = [DOUBLE_NEWLINE, WINDOWS_DOUBLE_NEWLINE];
|
||||
const commonStops = [SRC_DIRECTORY, PYTHON_ENCODING, CODE_BLOCK_END];
|
||||
|
||||
// Errors that can be expected on occasion even during normal functioning should not be shown.
|
||||
|
|
@ -112,6 +121,14 @@ const nonAutocompleteModels = [
|
|||
"instruct",
|
||||
];
|
||||
|
||||
export type GetLspDefinitionsFunction = (
|
||||
filepath: string,
|
||||
contents: string,
|
||||
cursorIndex: number,
|
||||
ide: IDE,
|
||||
lang: AutocompleteLanguageInfo,
|
||||
) => Promise<AutocompleteSnippet[]>;
|
||||
|
||||
export async function getTabCompletion(
|
||||
token: AbortSignal,
|
||||
options: TabAutocompleteOptions,
|
||||
|
|
@ -119,12 +136,7 @@ export async function getTabCompletion(
|
|||
ide: IDE,
|
||||
generatorReuseManager: GeneratorReuseManager,
|
||||
input: AutocompleteInput,
|
||||
getDefinitionsFromLsp: (
|
||||
filepath: string,
|
||||
contents: string,
|
||||
cursorIndex: number,
|
||||
ide: IDE,
|
||||
) => Promise<AutocompleteSnippet[]>,
|
||||
getDefinitionsFromLsp: GetLspDefinitionsFunction,
|
||||
): Promise<AutocompleteOutcome | undefined> {
|
||||
const startTime = Date.now();
|
||||
|
||||
|
|
@ -151,7 +163,9 @@ export async function getTabCompletion(
|
|||
}
|
||||
|
||||
// Model
|
||||
if (!llm) return;
|
||||
if (!llm) {
|
||||
return;
|
||||
}
|
||||
if (llm instanceof OpenAI) {
|
||||
llm.useLegacyCompletionsEndpoint = true;
|
||||
} else if (
|
||||
|
|
@ -170,35 +184,56 @@ export async function getTabCompletion(
|
|||
) {
|
||||
shownGptClaudeWarning = true;
|
||||
throw new Error(
|
||||
`Warning: ${llm.model} is not trained for tab-autocomplete, and may result in low-quality suggestions. See the docs for our recommended models: https://docs.continue.dev/setup/select-model#autocomplete`,
|
||||
`Warning: ${llm.model} is not trained for tab-autocomplete, and will result in low-quality suggestions. See the docs to learn more about why: https://docs.continue.dev/walkthroughs/tab-autocomplete#i-want-better-completions-should-i-use-gpt-4`,
|
||||
);
|
||||
}
|
||||
|
||||
// Prompt
|
||||
const fullPrefix =
|
||||
let fullPrefix =
|
||||
getRangeInString(fileContents, {
|
||||
start: { line: 0, character: 0 },
|
||||
end: input.selectedCompletionInfo?.range.start ?? pos,
|
||||
}) + (input.selectedCompletionInfo?.text ?? "");
|
||||
|
||||
if (input.injectDetails) {
|
||||
const lines = fullPrefix.split("\n");
|
||||
fullPrefix = `${lines.slice(0, -1).join("\n")}\n${
|
||||
lang.comment
|
||||
} ${input.injectDetails.split("\n").join(`\n${lang.comment} `)}\n${
|
||||
lines[lines.length - 1]
|
||||
}`;
|
||||
}
|
||||
|
||||
const fullSuffix = getRangeInString(fileContents, {
|
||||
start: pos,
|
||||
end: { line: fileLines.length - 1, character: Number.MAX_SAFE_INTEGER },
|
||||
});
|
||||
const lineBelowCursor =
|
||||
fileLines[Math.min(pos.line + 1, fileLines.length - 1)];
|
||||
|
||||
let extrasSnippets = (await Promise.race([
|
||||
getDefinitionsFromLsp(
|
||||
filepath,
|
||||
fullPrefix + fullSuffix,
|
||||
fullPrefix.length,
|
||||
ide,
|
||||
),
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve([]), 100);
|
||||
}),
|
||||
])) as AutocompleteSnippet[];
|
||||
// First non-whitespace line below the cursor
|
||||
let lineBelowCursor = "";
|
||||
let i = 1;
|
||||
while (
|
||||
lineBelowCursor.trim() === "" &&
|
||||
pos.line + i <= fileLines.length - 1
|
||||
) {
|
||||
lineBelowCursor = fileLines[Math.min(pos.line + i, fileLines.length - 1)];
|
||||
i++;
|
||||
}
|
||||
|
||||
let extrasSnippets = options.useOtherFiles
|
||||
? ((await Promise.race([
|
||||
getDefinitionsFromLsp(
|
||||
filepath,
|
||||
fullPrefix + fullSuffix,
|
||||
fullPrefix.length,
|
||||
ide,
|
||||
lang,
|
||||
),
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve([]), 100);
|
||||
}),
|
||||
])) as AutocompleteSnippet[])
|
||||
: [];
|
||||
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
if (options.onlyMyCode) {
|
||||
|
|
@ -280,7 +315,7 @@ export async function getTabCompletion(
|
|||
...(llm.model.toLowerCase().includes("starcoder2")
|
||||
? STARCODER2_T_ARTIFACTS
|
||||
: []),
|
||||
...lang.stopWords,
|
||||
...lang.stopWords.map((word) => `\n${word}`),
|
||||
];
|
||||
|
||||
const multiline =
|
||||
|
|
@ -372,12 +407,7 @@ export class CompletionProvider {
|
|||
private readonly ide: IDE,
|
||||
private readonly getLlm: () => Promise<ILLM | undefined>,
|
||||
private readonly _onError: (e: any) => void,
|
||||
private readonly getDefinitionsFromLsp: (
|
||||
filepath: string,
|
||||
contents: string,
|
||||
cursorIndex: number,
|
||||
ide: IDE,
|
||||
) => Promise<AutocompleteSnippet[]>,
|
||||
private readonly getDefinitionsFromLsp: GetLspDefinitionsFunction,
|
||||
) {
|
||||
this.generatorReuseManager = new GeneratorReuseManager(
|
||||
this.onError.bind(this),
|
||||
|
|
@ -390,6 +420,13 @@ export class CompletionProvider {
|
|||
|
||||
private onError(e: any) {
|
||||
console.warn("Error generating autocompletion: ", e);
|
||||
if (
|
||||
ERRORS_TO_IGNORE.some((err) =>
|
||||
typeof e === "string" ? e.includes(err) : e?.message?.includes(err),
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (!this.errorsShown.has(e.message)) {
|
||||
this.errorsShown.add(e.message);
|
||||
this._onError(e);
|
||||
|
|
@ -532,6 +569,11 @@ export class CompletionProvider {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
// Filter out unwanted results
|
||||
if (isOnlyPunctuationAndWhitespace(outcome.completion)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Do some stuff later so as not to block return. Latency matters
|
||||
const completionToCache = outcome.completion;
|
||||
setTimeout(async () => {
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
import type Parser from "web-tree-sitter";
|
||||
import type { TabAutocompleteOptions } from "..";
|
||||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import Parser from "web-tree-sitter";
|
||||
import { RangeInFileWithContents } from "../commands/util.js";
|
||||
import { TabAutocompleteOptions } from "../index.js";
|
||||
|
||||
import {
|
||||
countTokens,
|
||||
pruneLinesFromBottom,
|
||||
pruneLinesFromTop,
|
||||
} from "../llm/countTokens";
|
||||
import { getAst, getTreePathAtCursor } from "./ast";
|
||||
} from "../llm/countTokens.js";
|
||||
import { getAst, getTreePathAtCursor } from "./ast.js";
|
||||
import {
|
||||
type AutocompleteLanguageInfo,
|
||||
AutocompleteLanguageInfo,
|
||||
LANGUAGES,
|
||||
Typescript,
|
||||
} from "./languages";
|
||||
} from "./languages.js";
|
||||
import {
|
||||
type AutocompleteSnippet,
|
||||
fillPromptWithSnippets,
|
||||
rankSnippets,
|
||||
removeRangeFromSnippets,
|
||||
} from "./ranking";
|
||||
import { slidingWindowMatcher } from "./slidingWindow";
|
||||
type AutocompleteSnippet,
|
||||
} from "./ranking.js";
|
||||
import { RecentlyEditedRange, findMatchingRange } from "./recentlyEdited.js";
|
||||
|
||||
export function languageForFilepath(
|
||||
filepath: string,
|
||||
|
|
@ -60,7 +60,19 @@ async function shouldCompleteMultiline(
|
|||
filepath: string,
|
||||
fullPrefix: string,
|
||||
fullSuffix: string,
|
||||
language: AutocompleteLanguageInfo,
|
||||
): Promise<boolean> {
|
||||
// Don't complete multi-line for single-line comments
|
||||
if (
|
||||
fullPrefix
|
||||
.split("\n")
|
||||
.slice(-1)[0]
|
||||
?.trimStart()
|
||||
.startsWith(language.comment)
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First, if the line before ends with an opening bracket, then assume multi-line
|
||||
if (
|
||||
["{", "(", "["].includes(
|
||||
|
|
@ -99,7 +111,7 @@ export async function constructAutocompletePrompt(
|
|||
clipboardText: string,
|
||||
language: AutocompleteLanguageInfo,
|
||||
options: TabAutocompleteOptions,
|
||||
recentlyEditedRanges: RangeInFileWithContents[],
|
||||
recentlyEditedRanges: RecentlyEditedRange[],
|
||||
recentlyEditedFiles: RangeInFileWithContents[],
|
||||
modelName: string,
|
||||
extraSnippets: AutocompleteSnippet[],
|
||||
|
|
@ -135,29 +147,47 @@ export async function constructAutocompletePrompt(
|
|||
options.slidingWindowSize * (1 - options.slidingWindowPrefixPercentage),
|
||||
);
|
||||
|
||||
const slidingWindowMatches = await slidingWindowMatcher(
|
||||
recentlyEditedFiles,
|
||||
windowAroundCursor,
|
||||
3,
|
||||
options.slidingWindowSize,
|
||||
);
|
||||
snippets.push(...slidingWindowMatches);
|
||||
// This was much too slow, and not super useful
|
||||
// const slidingWindowMatches = await slidingWindowMatcher(
|
||||
// recentlyEditedFiles,
|
||||
// windowAroundCursor,
|
||||
// 3,
|
||||
// options.slidingWindowSize,
|
||||
// );
|
||||
// snippets.push(...slidingWindowMatches);
|
||||
|
||||
const recentlyEdited = (
|
||||
await Promise.all(
|
||||
recentlyEditedRanges.map(async (r) => {
|
||||
return r;
|
||||
// return await getScopeAroundRange(r);
|
||||
}),
|
||||
)
|
||||
).filter((s) => !!s);
|
||||
snippets.push(...(recentlyEdited as any));
|
||||
// Filter out empty snippets
|
||||
snippets = snippets.filter(
|
||||
(s) =>
|
||||
s.contents.trim() !== "" &&
|
||||
!(prefix + suffix).includes(s.contents.trim()),
|
||||
);
|
||||
// snippets.push(
|
||||
// ...recentlyEditedRanges.map((r) => ({
|
||||
// ...r,
|
||||
// contents: r.lines.join("\n"),
|
||||
// })),
|
||||
// );
|
||||
|
||||
if (options.useRecentlyEdited) {
|
||||
const currentLinePrefix = prefix.trim().split("\n").slice(-1)[0];
|
||||
if (currentLinePrefix?.length > options.recentLinePrefixMatchMinLength) {
|
||||
const matchingRange = findMatchingRange(
|
||||
recentlyEditedRanges,
|
||||
currentLinePrefix,
|
||||
);
|
||||
if (matchingRange) {
|
||||
snippets.push({
|
||||
...matchingRange,
|
||||
contents: matchingRange.lines.join("\n"),
|
||||
score: 0.8,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out empty snippets and ones that are already in the prefix/suffix
|
||||
snippets = snippets
|
||||
.map((snippet) => ({ ...snippet }))
|
||||
.filter(
|
||||
(s) =>
|
||||
s.contents.trim() !== "" &&
|
||||
!(prefix + suffix).includes(s.contents.trim()),
|
||||
);
|
||||
|
||||
// Rank / order the snippets
|
||||
const scoredSnippets = rankSnippets(snippets, windowAroundCursor);
|
||||
|
|
@ -207,6 +237,7 @@ export async function constructAutocompletePrompt(
|
|||
filepath,
|
||||
fullPrefix,
|
||||
fullSuffix,
|
||||
language,
|
||||
),
|
||||
snippets,
|
||||
};
|
||||
|
|
|
|||
4
core/autocomplete/filter.ts
Normal file
4
core/autocomplete/filter.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
export function isOnlyPunctuationAndWhitespace(completion: string): boolean {
|
||||
const punctuationAndWhitespaceRegex = /^[^\w\d]+$/;
|
||||
return punctuationAndWhitespaceRegex.test(completion);
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ export const Typescript = {
|
|||
export const Python = {
|
||||
// """"#" is for .ipynb files, where we add '"""' surrounding markdown blocks.
|
||||
// This stops the model from trying to complete the start of a new markdown block
|
||||
stopWords: ["def", "class", '"""#'],
|
||||
stopWords: ["def", "class", "\"\"\"#"],
|
||||
comment: "#",
|
||||
endOfLine: [],
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { distance } from "fastest-levenshtein";
|
||||
import type { DiffLine } from "..";
|
||||
import type { LineStream } from "../diff/util";
|
||||
import { LineStream } from "../diff/util.js";
|
||||
import { DiffLine } from "../index.js";
|
||||
|
||||
export async function* noTopLevelKeywordsMidline(
|
||||
lines: LineStream,
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import type { Range } from "..";
|
||||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import { countTokens } from "../llm/countTokens";
|
||||
import { RangeInFileWithContents } from "../commands/util.js";
|
||||
import { Range } from "../index.js";
|
||||
import { countTokens } from "../llm/countTokens.js";
|
||||
|
||||
export type AutocompleteSnippet = RangeInFileWithContents & {
|
||||
score: number;
|
||||
score?: number;
|
||||
};
|
||||
|
||||
const rx = /[\s.,\/#!$%\^&\*;:{}=\-_`~()\[\]]/g;
|
||||
function getSymbolsForSnippet(snippet: string): Set<string> {
|
||||
export function getSymbolsForSnippet(snippet: string): Set<string> {
|
||||
const symbols = snippet
|
||||
.split(rx)
|
||||
.map((s) => s.trim())
|
||||
|
|
@ -42,11 +42,12 @@ export function jaccardSimilarity(a: string, b: string): number {
|
|||
* Rank code snippets to be used in tab-autocomplete prompt. Returns a sorted version of the snippet array.
|
||||
*/
|
||||
export function rankSnippets(
|
||||
ranges: RangeInFileWithContents[],
|
||||
ranges: AutocompleteSnippet[],
|
||||
windowAroundCursor: string,
|
||||
): AutocompleteSnippet[] {
|
||||
const snippets = ranges.map((snippet) => ({
|
||||
score: jaccardSimilarity(snippet.contents, windowAroundCursor),
|
||||
): Required<AutocompleteSnippet>[] {
|
||||
const snippets: Required<AutocompleteSnippet>[] = ranges.map((snippet) => ({
|
||||
score:
|
||||
snippet.score ?? jaccardSimilarity(snippet.contents, windowAroundCursor),
|
||||
...snippet,
|
||||
}));
|
||||
const uniqueSnippets = deduplicateSnippets(snippets);
|
||||
|
|
@ -57,10 +58,10 @@ export function rankSnippets(
|
|||
* Deduplicate code snippets by merging overlapping ranges into a single range.
|
||||
*/
|
||||
export function deduplicateSnippets(
|
||||
snippets: AutocompleteSnippet[],
|
||||
): AutocompleteSnippet[] {
|
||||
snippets: Required<AutocompleteSnippet>[],
|
||||
): Required<AutocompleteSnippet>[] {
|
||||
// Group by file
|
||||
const fileGroups: { [key: string]: AutocompleteSnippet[] } = {};
|
||||
const fileGroups: { [key: string]: Required<AutocompleteSnippet>[] } = {};
|
||||
for (const snippet of snippets) {
|
||||
if (!fileGroups[snippet.filepath]) {
|
||||
fileGroups[snippet.filepath] = [];
|
||||
|
|
@ -77,8 +78,8 @@ export function deduplicateSnippets(
|
|||
}
|
||||
|
||||
function mergeSnippetsByRange(
|
||||
snippets: AutocompleteSnippet[],
|
||||
): AutocompleteSnippet[] {
|
||||
snippets: Required<AutocompleteSnippet>[],
|
||||
): Required<AutocompleteSnippet>[] {
|
||||
if (snippets.length === 0) {
|
||||
return snippets;
|
||||
}
|
||||
|
|
@ -86,7 +87,7 @@ function mergeSnippetsByRange(
|
|||
const sorted = snippets.sort(
|
||||
(a, b) => a.range.start.line - b.range.start.line,
|
||||
);
|
||||
const merged: AutocompleteSnippet[] = [];
|
||||
const merged: Required<AutocompleteSnippet>[] = [];
|
||||
|
||||
while (sorted.length > 0) {
|
||||
const next = sorted.shift()!;
|
||||
|
|
@ -121,12 +122,12 @@ function mergeOverlappingRangeContents(
|
|||
* Fill the allowed space with snippets
|
||||
*/
|
||||
export function fillPromptWithSnippets(
|
||||
snippets: AutocompleteSnippet[],
|
||||
snippets: Required<AutocompleteSnippet>[],
|
||||
maxSnippetTokens: number,
|
||||
modelName: string,
|
||||
): AutocompleteSnippet[] {
|
||||
): Required<AutocompleteSnippet>[] {
|
||||
let tokensRemaining = maxSnippetTokens;
|
||||
const keptSnippets: AutocompleteSnippet[] = [];
|
||||
const keptSnippets: Required<AutocompleteSnippet>[] = [];
|
||||
for (let i = 0; i < snippets.length; i++) {
|
||||
const snippet = snippets[i];
|
||||
const tokenCount = countTokens(snippet.contents, modelName);
|
||||
|
|
@ -214,11 +215,11 @@ function rangeDifferenceByLines(orig: Range, remove: Range): Range[] {
|
|||
}
|
||||
|
||||
export function removeRangeFromSnippets(
|
||||
snippets: AutocompleteSnippet[],
|
||||
snippets: Required<AutocompleteSnippet>[],
|
||||
filepath: string,
|
||||
range: Range,
|
||||
): AutocompleteSnippet[] {
|
||||
const finalSnippets: AutocompleteSnippet[] = [];
|
||||
): Required<AutocompleteSnippet>[] {
|
||||
const finalSnippets: Required<AutocompleteSnippet>[] = [];
|
||||
for (const snippet of snippets) {
|
||||
if (snippet.filepath !== filepath) {
|
||||
finalSnippets.push(snippet);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,18 @@
|
|||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import { RangeInFile } from "../index.js";
|
||||
|
||||
export type RecentlyEditedRange = RangeInFileWithContents & {
|
||||
export type RecentlyEditedRange = RangeInFile & {
|
||||
timestamp: number;
|
||||
lines: string[];
|
||||
symbols: Set<string>;
|
||||
};
|
||||
|
||||
export function findMatchingRange(
|
||||
recentlyEditedRanges: RecentlyEditedRange[],
|
||||
linePrefix: string,
|
||||
): RecentlyEditedRange | undefined {
|
||||
return recentlyEditedRanges.find((recentlyEditedRange) => {
|
||||
return recentlyEditedRange.lines.some((line) =>
|
||||
line.startsWith(linePrefix),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { BranchAndDir, Chunk } from "..";
|
||||
import { FullTextSearchCodebaseIndex } from "../indexing/FullTextSearch";
|
||||
import { BranchAndDir, Chunk } from "../index.js";
|
||||
import { FullTextSearchCodebaseIndex } from "../indexing/FullTextSearch.js";
|
||||
|
||||
export async function fullTextRetrieve(
|
||||
prefix: string,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { RangeInFileWithContents } from "../commands/util";
|
||||
import { type AutocompleteSnippet, jaccardSimilarity } from "./ranking";
|
||||
import { RangeInFileWithContents } from "../commands/util.js";
|
||||
import { AutocompleteSnippet, jaccardSimilarity } from "./ranking.js";
|
||||
|
||||
function* slidingWindow(
|
||||
content: string,
|
||||
|
|
@ -38,7 +38,7 @@ export async function slidingWindowMatcher(
|
|||
windowSize: number,
|
||||
): Promise<AutocompleteSnippet[]> {
|
||||
// Sorted lowest similarity to highest
|
||||
const topMatches: AutocompleteSnippet[] = [];
|
||||
const topMatches: Required<AutocompleteSnippet>[] = [];
|
||||
|
||||
for (const { filepath, contents, range } of recentFiles) {
|
||||
for (const window of slidingWindow(contents, windowSize)) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Fill in the middle prompts
|
||||
|
||||
import type { CompletionOptions } from "..";
|
||||
import type { AutocompleteSnippet } from "./ranking";
|
||||
import { CompletionOptions } from "../index.js";
|
||||
import { AutocompleteSnippet } from "./ranking.js";
|
||||
|
||||
interface AutocompleteTemplate {
|
||||
template:
|
||||
|
|
@ -82,7 +82,13 @@ const deepseekFimTemplate: AutocompleteTemplate = {
|
|||
template:
|
||||
"<|fim▁begin|>{{{prefix}}}<|fim▁hole|>{{{suffix}}}<|fim▁end|>",
|
||||
completionOptions: {
|
||||
stop: ["<|fim▁begin|>", "<|fim▁hole|>", "<|fim▁end|>", "//"],
|
||||
stop: [
|
||||
"<|fim▁begin|>",
|
||||
"<|fim▁hole|>",
|
||||
"<|fim▁end|>",
|
||||
"//",
|
||||
"<|end▁of▁sentence|>",
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,58 +1,82 @@
|
|||
import type { CustomCommand, SlashCommand, SlashCommandDescription } from "..";
|
||||
import { stripImages } from "../llm/countTokens";
|
||||
import { renderTemplatedString } from "../llm/llms";
|
||||
import SlashCommands from "./slash";
|
||||
import {
|
||||
CustomCommand,
|
||||
SlashCommand,
|
||||
SlashCommandDescription,
|
||||
} from "../index.js";
|
||||
import { stripImages } from "../llm/countTokens.js";
|
||||
import { renderTemplatedString } from "../llm/llms/index.js";
|
||||
import SlashCommands from "./slash/index.js";
|
||||
|
||||
export function slashFromCustomCommand(
|
||||
customCommand: CustomCommand,
|
||||
customCommand: CustomCommand,
|
||||
): SlashCommand {
|
||||
return {
|
||||
name: customCommand.name,
|
||||
description: customCommand.description,
|
||||
run: async function* ({ input, llm, history, ide }) {
|
||||
// Remove slash command prefix from input
|
||||
let userInput = input;
|
||||
if (userInput.startsWith(`/${customCommand.name}`)) {
|
||||
userInput = userInput
|
||||
.slice(customCommand.name.length + 1, userInput.length)
|
||||
.trimStart();
|
||||
}
|
||||
return {
|
||||
name: customCommand.name,
|
||||
description: customCommand.description,
|
||||
run: async function* ({ input, llm, history, ide }) {
|
||||
// Remove slash command prefix from input
|
||||
let userInput = input;
|
||||
if (userInput.startsWith(`/${customCommand.name}`)) {
|
||||
userInput = userInput
|
||||
.slice(customCommand.name.length + 1, userInput.length)
|
||||
.trimStart();
|
||||
}
|
||||
|
||||
// Render prompt template
|
||||
const promptUserInput = await renderTemplatedString(
|
||||
customCommand.prompt,
|
||||
ide.readFile.bind(ide),
|
||||
{ input: userInput },
|
||||
);
|
||||
// Render prompt template
|
||||
const promptUserInput = await renderTemplatedString(
|
||||
customCommand.prompt,
|
||||
ide.readFile.bind(ide),
|
||||
{ input: userInput },
|
||||
);
|
||||
|
||||
const messages = [...history];
|
||||
// Find the last chat message with this slash command and replace it with the user input
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
if (
|
||||
messages[i].role === "user" &&
|
||||
stripImages(messages[i].content).startsWith(`/${customCommand.name}`)
|
||||
) {
|
||||
messages[i] = { ...messages[i], content: promptUserInput };
|
||||
break;
|
||||
}
|
||||
}
|
||||
const messages = [...history];
|
||||
// Find the last chat message with this slash command and replace it with the user input
|
||||
for (let i = messages.length - 1; i >= 0; i--) {
|
||||
const { role, content } = messages[i];
|
||||
if (role !== "user") {
|
||||
continue;
|
||||
}
|
||||
|
||||
for await (const chunk of llm.streamChat(messages)) {
|
||||
yield stripImages(chunk.content);
|
||||
}
|
||||
},
|
||||
};
|
||||
if (
|
||||
Array.isArray(content) &&
|
||||
content.some((part) =>
|
||||
part.text?.startsWith(`/${customCommand.name}`),
|
||||
)
|
||||
) {
|
||||
messages[i] = {
|
||||
...messages[i],
|
||||
content: content.map((part) => {
|
||||
return part.text?.startsWith(`/${customCommand.name}`)
|
||||
? { ...part, text: promptUserInput }
|
||||
: part;
|
||||
}),
|
||||
};
|
||||
break;
|
||||
} else if (
|
||||
typeof content === "string" &&
|
||||
content.startsWith(`/${customCommand.name}`)
|
||||
) {
|
||||
messages[i] = { ...messages[i], content: promptUserInput };
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for await (const chunk of llm.streamChat(messages)) {
|
||||
yield stripImages(chunk.content);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function slashCommandFromDescription(
|
||||
desc: SlashCommandDescription,
|
||||
desc: SlashCommandDescription,
|
||||
): SlashCommand | undefined {
|
||||
const cmd = SlashCommands.find((cmd) => cmd.name === desc.name);
|
||||
if (!cmd) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...cmd,
|
||||
params: desc.params,
|
||||
};
|
||||
const cmd = SlashCommands.find((cmd) => cmd.name === desc.name);
|
||||
if (!cmd) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
...cmd,
|
||||
params: desc.params,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import type { SlashCommand } from "../..";
|
||||
import { streamLines } from "../../diff/util";
|
||||
import { removeQuotesAndEscapes } from "../../util";
|
||||
import { streamLines } from "../../diff/util.js";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import { removeQuotesAndEscapes } from "../../util/index.js";
|
||||
|
||||
const GenerateTerminalCommand: SlashCommand = {
|
||||
name: "cmd",
|
||||
description: "Generate a shell command",
|
||||
run: async function* ({ ide, llm, input }) {
|
||||
const gen = llm.streamComplete(`The user has made a request to run a shell command. Their description of what it should do is:
|
||||
const gen =
|
||||
llm.streamComplete(`The user has made a request to run a shell command. Their description of what it should do is:
|
||||
|
||||
"${input}"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { SlashCommand } from "../..";
|
||||
import EditSlashCommand from "./edit";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import EditSlashCommand from "./edit.js";
|
||||
|
||||
const CommentSlashCommand: SlashCommand = {
|
||||
name: "comment",
|
||||
|
|
@ -7,7 +7,8 @@ const CommentSlashCommand: SlashCommand = {
|
|||
run: async function* (sdk) {
|
||||
for await (const update of EditSlashCommand.run({
|
||||
...sdk,
|
||||
input: "Write comments for this code",
|
||||
input:
|
||||
"Write comments for this code. Do not change anything about the code itself.",
|
||||
})) {
|
||||
yield update;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
import type { SlashCommand } from "../..";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import { stripImages } from "../../llm/countTokens.js";
|
||||
|
||||
const CommitMessageCommand: SlashCommand = {
|
||||
name: "commit",
|
||||
description: "Generate a commit message for current changes",
|
||||
run: async function* ({ ide, llm, input }) {
|
||||
const diff = await ide.getDiff();
|
||||
|
||||
if (!diff || diff.trim() === "") {
|
||||
yield "No changes detected. Make sure you are in a git repository with current changes.";
|
||||
return;
|
||||
}
|
||||
|
||||
const prompt = `${diff}\n\nGenerate a commit message for the above set of changes. First, give a single sentence, no more than 80 characters. Then, after 2 line breaks, give a list of no more than 5 short bullet points, each no more than 40 characters. Output nothing except for the commit message, and don't surround it in quotes.`;
|
||||
for await (const chunk of llm.streamChat([
|
||||
{ role: "user", content: prompt },
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
import type { ChatMessage, SlashCommand } from "../..";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
import { removeQuotesAndEscapes } from "../../util";
|
||||
import { ChatMessage, SlashCommand } from "../../index.js";
|
||||
import { stripImages } from "../../llm/countTokens.js";
|
||||
import { removeQuotesAndEscapes } from "../../util/index.js";
|
||||
|
||||
const PROMPT = (input: string, title: string) => `You will be asked to generate the body of a GitHub issue given a user request. You should follow these rules:
|
||||
const PROMPT = (
|
||||
input: string,
|
||||
title: string,
|
||||
) => `You will be asked to generate the body of a GitHub issue given a user request. You should follow these rules:
|
||||
- Be descriptive but do not make up details
|
||||
- If the the user request includes any code snippets that are relevant, reference them in code blocks
|
||||
- Describe step by step how to reproduce the problem
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import type { ContextItemWithId, ILLM, SlashCommand } from "../..";
|
||||
import {
|
||||
filterCodeBlockLines,
|
||||
filterEnglishLinesAtEnd,
|
||||
|
|
@ -6,14 +5,18 @@ import {
|
|||
fixCodeLlamaFirstLineIndentation,
|
||||
stopAtLines,
|
||||
streamWithNewLines,
|
||||
} from "../../autocomplete/lineStream";
|
||||
import { streamLines } from "../../diff/util";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
import { dedentAndGetCommonWhitespace, getMarkdownLanguageTagForFile } from "../../util";
|
||||
} from "../../autocomplete/lineStream.js";
|
||||
import { streamLines } from "../../diff/util.js";
|
||||
import { ContextItemWithId, ILLM, SlashCommand } from "../../index.js";
|
||||
import { stripImages } from "../../llm/countTokens.js";
|
||||
import {
|
||||
dedentAndGetCommonWhitespace,
|
||||
getMarkdownLanguageTagForFile,
|
||||
} from "../../util/index.js";
|
||||
import {
|
||||
type RangeInFileWithContents,
|
||||
contextItemToRangeInFileWithContents,
|
||||
} from "../util";
|
||||
type RangeInFileWithContents,
|
||||
} from "../util.js";
|
||||
|
||||
const PROMPT = `Take the file prefix and suffix into account, but only rewrite the code_to_edit as specified in the user_request. The code you write in modified_code_to_edit will replace the code between the code_to_edit tags. Do NOT preface your answer or write anything other than code. The </modified_code_to_edit> tag should be written to indicate the end of the modified code section. Do not ever use nested tags.
|
||||
|
||||
|
|
@ -238,6 +241,8 @@ const EditSlashCommand: SlashCommand = {
|
|||
part.text = part.text.replace("/edit", "").trimStart();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
content = input.replace("/edit", "").trimStart();
|
||||
}
|
||||
const userInput = stripImages(content).replace(
|
||||
`\`\`\`${contextItemToEdit.name}\n${contextItemToEdit.content}\n\`\`\`\n`,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { SlashCommand } from "../..";
|
||||
import { removeQuotesAndEscapes } from "../../util";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import { removeQuotesAndEscapes } from "../../util/index.js";
|
||||
|
||||
const HttpSlashCommand: SlashCommand = {
|
||||
name: "http",
|
||||
|
|
@ -26,7 +26,9 @@ const HttpSlashCommand: SlashCommand = {
|
|||
const reader = response.body.getReader();
|
||||
while (true) {
|
||||
const { done, value } = await reader.read();
|
||||
if (done) break;
|
||||
if (done) {
|
||||
break;
|
||||
}
|
||||
const decoded = new TextDecoder("utf-8").decode(value);
|
||||
yield decoded;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import GenerateTerminalCommand from "./cmd";
|
||||
import CommentSlashCommand from "./comment";
|
||||
import CommitMessageCommand from "./commit";
|
||||
import DraftIssueCommand from "./draftIssue";
|
||||
import EditSlashCommand from "./edit";
|
||||
import HttpSlashCommand from "./http";
|
||||
import ReviewMessageCommand from "./review";
|
||||
import ShareSlashCommand from "./share";
|
||||
import StackOverflowSlashCommand from "./stackOverflow";
|
||||
import GenerateTerminalCommand from "./cmd.js";
|
||||
import CommentSlashCommand from "./comment.js";
|
||||
import CommitMessageCommand from "./commit.js";
|
||||
import DraftIssueCommand from "./draftIssue.js";
|
||||
import EditSlashCommand from "./edit.js";
|
||||
import HttpSlashCommand from "./http.js";
|
||||
import ReviewMessageCommand from "./review.js";
|
||||
import ShareSlashCommand from "./share.js";
|
||||
import StackOverflowSlashCommand from "./stackOverflow.js";
|
||||
|
||||
export default [
|
||||
DraftIssueCommand,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import type { SlashCommand } from "../..";
|
||||
import type { ChatMessage } from "../..";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
import { ChatMessage, SlashCommand } from "../../index.js";
|
||||
import { stripImages } from "../../llm/countTokens.js";
|
||||
|
||||
const prompt = `
|
||||
Review the following code, focusing on Readability, Maintainability, Code Smells, Speed, and Memory Performance. Provide feedback with these guidelines:
|
||||
|
|
@ -16,7 +15,9 @@ function getLastUserHistory(history: ChatMessage[]): string {
|
|||
.reverse()
|
||||
.find((message) => message.role === "user");
|
||||
|
||||
if (!lastUserHistory) return "";
|
||||
if (!lastUserHistory) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (Array.isArray(lastUserHistory.content)) {
|
||||
return lastUserHistory.content.reduce(
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import * as fs from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import path from "path";
|
||||
import { SlashCommand } from "../..";
|
||||
import { languageForFilepath } from "../../autocomplete/constructPrompt";
|
||||
import { stripImages } from "../../llm/countTokens";
|
||||
import { languageForFilepath } from "../../autocomplete/constructPrompt.js";
|
||||
import { SlashCommand } from "../../index.js";
|
||||
import { stripImages } from "../../llm/countTokens.js";
|
||||
|
||||
// If useful elsewhere, helper funcs should move to core/util/index.ts or similar
|
||||
function getOffsetDatetime(date: Date): Date {
|
||||
|
|
@ -70,7 +70,7 @@ const ShareSlashCommand: SlashCommand = {
|
|||
outputDir = outputDir.replace(/^~/, homedir);
|
||||
} else if (
|
||||
outputDir.startsWith("./") ||
|
||||
outputDir.startsWith(`.\\`) ||
|
||||
outputDir.startsWith(".\\") ||
|
||||
outputDir === "."
|
||||
) {
|
||||
const workspaceDirs = await ide.getWorkspaceDirs();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { ChatMessageRole, FetchFunction, SlashCommand } from "../..";
|
||||
import { pruneStringFromBottom, stripImages } from "../../llm/countTokens";
|
||||
import { ChatMessageRole, FetchFunction, SlashCommand } from "../../index.js";
|
||||
import { pruneStringFromBottom, stripImages } from "../../llm/countTokens.js";
|
||||
|
||||
const SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app";
|
||||
const PROMPT = (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { ContextItemWithId } from "..";
|
||||
import { ContextItemWithId } from "../index.js";
|
||||
|
||||
export interface RangeInFileWithContents {
|
||||
filepath: string;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { ContextProviderWithParams, SerializedContinueConfig } from "..";
|
||||
import { ContextProviderWithParams, SerializedContinueConfig } from "../index.js";
|
||||
|
||||
export const defaultConfig: SerializedContinueConfig = {
|
||||
models: [
|
||||
{
|
||||
title: "GPT-4o (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "gpt-4o",
|
||||
},
|
||||
{
|
||||
title: "Claude 3 Sonnet (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "claude-3-sonnet-20240229",
|
||||
},
|
||||
{
|
||||
title: "GPT-4 Turbo (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "gpt-4-turbo",
|
||||
},
|
||||
{
|
||||
title: "GPT-3.5-Turbo (Free Trial)",
|
||||
provider: "free-trial",
|
||||
|
|
@ -51,9 +51,9 @@ export const defaultConfigJetBrains: SerializedContinueConfig = {
|
|||
model: "claude-3-sonnet-20240229",
|
||||
},
|
||||
{
|
||||
title: "GPT-4 Turbo (Free Trial)",
|
||||
title: "GPT-4o (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "gpt-4-turbo",
|
||||
model: "gpt-4o",
|
||||
},
|
||||
{
|
||||
title: "GPT-3.5-Turbo (Free Trial)",
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import type { ContinueConfig, ContinueRcJson, IDE, ILLM } from "..";
|
||||
import type { IdeSettings } from "../protocol/ideWebview";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
import {
|
||||
finalToBrowserConfig,
|
||||
loadFullConfigNode,
|
||||
type BrowserSerializedContinueConfig,
|
||||
} from "./load";
|
||||
BrowserSerializedContinueConfig,
|
||||
ContinueConfig,
|
||||
ContinueRcJson,
|
||||
IDE,
|
||||
ILLM,
|
||||
} from "../index.js";
|
||||
import { IdeSettings } from "../protocol/ideWebview.js";
|
||||
import { Telemetry } from "../util/posthog.js";
|
||||
import { finalToBrowserConfig, loadFullConfigNode } from "./load.js";
|
||||
|
||||
export class ConfigHandler {
|
||||
private savedConfig: ContinueConfig | undefined;
|
||||
|
|
@ -13,12 +15,12 @@ export class ConfigHandler {
|
|||
|
||||
constructor(
|
||||
private readonly ide: IDE,
|
||||
private ideSettingsPromise: Promise<IdeSettings>,
|
||||
private ideSettings: IdeSettings,
|
||||
private readonly writeLog: (text: string) => Promise<void>,
|
||||
private readonly onConfigUpdate: () => void,
|
||||
) {
|
||||
this.ide = ide;
|
||||
this.ideSettingsPromise = ideSettingsPromise;
|
||||
this.ideSettings = ideSettings;
|
||||
this.writeLog = writeLog;
|
||||
this.onConfigUpdate = onConfigUpdate;
|
||||
try {
|
||||
|
|
@ -29,7 +31,7 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
updateIdeSettings(ideSettings: IdeSettings) {
|
||||
this.ideSettingsPromise = Promise.resolve(ideSettings);
|
||||
this.ideSettings = ideSettings;
|
||||
this.reloadConfig();
|
||||
}
|
||||
|
||||
|
|
@ -61,21 +63,14 @@ export class ConfigHandler {
|
|||
}
|
||||
|
||||
const ideInfo = await this.ide.getIdeInfo();
|
||||
const ideSettings = await this.ideSettingsPromise;
|
||||
let remoteConfigServerUrl = undefined;
|
||||
try {
|
||||
remoteConfigServerUrl =
|
||||
typeof ideSettings.remoteConfigServerUrl !== "string" ||
|
||||
ideSettings.remoteConfigServerUrl === ""
|
||||
? undefined
|
||||
: new URL(ideSettings.remoteConfigServerUrl);
|
||||
} catch (e) {}
|
||||
const uniqueId = await this.ide.getUniqueId();
|
||||
|
||||
this.savedConfig = await loadFullConfigNode(
|
||||
this.ide.readFile.bind(this.ide),
|
||||
workspaceConfigs,
|
||||
remoteConfigServerUrl,
|
||||
this.ideSettings,
|
||||
ideInfo.ideType,
|
||||
uniqueId,
|
||||
this.writeLog,
|
||||
);
|
||||
this.savedConfig.allowAnonymousTelemetry =
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
import * as fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type {
|
||||
import * as fs from "fs";
|
||||
import path from "path";
|
||||
import {
|
||||
slashCommandFromDescription,
|
||||
slashFromCustomCommand,
|
||||
} from "../commands/index.js";
|
||||
import CustomContextProviderClass from "../context/providers/CustomContextProvider.js";
|
||||
import FileContextProvider from "../context/providers/FileContextProvider.js";
|
||||
import { contextProviderClassFromName } from "../context/providers/index.js";
|
||||
import { AllRerankers } from "../context/rerankers/index.js";
|
||||
import { LLMReranker } from "../context/rerankers/llm.js";
|
||||
import {
|
||||
BrowserSerializedContinueConfig,
|
||||
Config,
|
||||
ContextProviderWithParams,
|
||||
|
|
@ -16,24 +25,16 @@ import type {
|
|||
RerankerDescription,
|
||||
SerializedContinueConfig,
|
||||
SlashCommand,
|
||||
} from "..";
|
||||
import {
|
||||
slashCommandFromDescription,
|
||||
slashFromCustomCommand,
|
||||
} from "../commands";
|
||||
import { contextProviderClassFromName } from "../context/providers";
|
||||
import CustomContextProviderClass from "../context/providers/CustomContextProvider";
|
||||
import FileContextProvider from "../context/providers/FileContextProvider";
|
||||
import { AllRerankers } from "../context/rerankers";
|
||||
import { LLMReranker } from "../context/rerankers/llm";
|
||||
import { AllEmbeddingsProviders } from "../indexing/embeddings";
|
||||
import TransformersJsEmbeddingsProvider from "../indexing/embeddings/TransformersJsEmbeddingsProvider";
|
||||
import type { BaseLLM } from "../llm";
|
||||
import { llmFromDescription } from "../llm/llms";
|
||||
import CustomLLMClass from "../llm/llms/CustomLLM";
|
||||
import { copyOf } from "../util";
|
||||
import { fetchwithRequestOptions } from "../util/fetchWithOptions";
|
||||
import mergeJson from "../util/merge";
|
||||
} from "../index.js";
|
||||
import TransformersJsEmbeddingsProvider from "../indexing/embeddings/TransformersJsEmbeddingsProvider.js";
|
||||
import { AllEmbeddingsProviders } from "../indexing/embeddings/index.js";
|
||||
import { BaseLLM } from "../llm/index.js";
|
||||
import CustomLLMClass from "../llm/llms/CustomLLM.js";
|
||||
import { llmFromDescription } from "../llm/llms/index.js";
|
||||
import { IdeSettings } from "../protocol/ideWebview.js";
|
||||
import { fetchwithRequestOptions } from "../util/fetchWithOptions.js";
|
||||
import { copyOf } from "../util/index.js";
|
||||
import mergeJson from "../util/merge.js";
|
||||
import {
|
||||
getConfigJsPath,
|
||||
getConfigJsPathForRemote,
|
||||
|
|
@ -41,15 +42,14 @@ import {
|
|||
getConfigJsonPathForRemote,
|
||||
getConfigTsPath,
|
||||
getContinueDotEnv,
|
||||
migrate,
|
||||
} from "../util/paths";
|
||||
} from "../util/paths.js";
|
||||
import {
|
||||
defaultContextProvidersJetBrains,
|
||||
defaultContextProvidersVsCode,
|
||||
defaultSlashCommandsJetBrains,
|
||||
defaultSlashCommandsVscode,
|
||||
} from "./default";
|
||||
const { execSync } = require("node:child_process");
|
||||
} from "./default.js";
|
||||
const { execSync } = require("child_process");
|
||||
|
||||
function resolveSerializedConfig(filepath: string): SerializedContinueConfig {
|
||||
let content = fs.readFileSync(filepath, "utf8");
|
||||
|
|
@ -82,7 +82,7 @@ const configMergeKeys = {
|
|||
|
||||
function loadSerializedConfig(
|
||||
workspaceConfigs: ContinueRcJson[],
|
||||
remoteConfigServerUrl: URL | undefined,
|
||||
ideSettings: IdeSettings,
|
||||
ideType: IdeType,
|
||||
): SerializedContinueConfig {
|
||||
const configPath = getConfigJsonPath(ideType);
|
||||
|
|
@ -97,38 +97,10 @@ function loadSerializedConfig(
|
|||
config.allowAnonymousTelemetry = true;
|
||||
}
|
||||
|
||||
migrate("codeContextProvider", () => {
|
||||
if (!config.contextProviders?.filter((cp) => cp.name === "code")?.length) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "code",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8");
|
||||
});
|
||||
|
||||
migrate("docsContextProvider1", () => {
|
||||
if (!config.contextProviders?.filter((cp) => cp.name === "docs")?.length) {
|
||||
config.contextProviders = [
|
||||
...(config.contextProviders || []),
|
||||
{
|
||||
name: "docs",
|
||||
params: {},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
fs.writeFileSync(configPath, JSON.stringify(config, undefined, 2), "utf8");
|
||||
});
|
||||
|
||||
if (remoteConfigServerUrl) {
|
||||
if (ideSettings.remoteConfigServerUrl) {
|
||||
try {
|
||||
const remoteConfigJson = resolveSerializedConfig(
|
||||
getConfigJsonPathForRemote(remoteConfigServerUrl),
|
||||
getConfigJsonPathForRemote(ideSettings.remoteConfigServerUrl),
|
||||
);
|
||||
config = mergeJson(config, remoteConfigJson, "merge", configMergeKeys);
|
||||
} catch (e) {
|
||||
|
|
@ -197,6 +169,8 @@ function isContextProviderWithParams(
|
|||
async function intermediateToFinalConfig(
|
||||
config: Config,
|
||||
readFile: (filepath: string) => Promise<string>,
|
||||
ideSettings: IdeSettings,
|
||||
uniqueId: string,
|
||||
writeLog: (log: string) => Promise<void>,
|
||||
): Promise<ContinueConfig> {
|
||||
// Auto-detect models
|
||||
|
|
@ -206,11 +180,15 @@ async function intermediateToFinalConfig(
|
|||
const llm = await llmFromDescription(
|
||||
desc,
|
||||
readFile,
|
||||
uniqueId,
|
||||
ideSettings,
|
||||
writeLog,
|
||||
config.completionOptions,
|
||||
config.systemMessage,
|
||||
);
|
||||
if (!llm) continue;
|
||||
if (!llm) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (llm.model === "AUTODETECT") {
|
||||
try {
|
||||
|
|
@ -224,6 +202,8 @@ async function intermediateToFinalConfig(
|
|||
title: `${llm.title} - ${modelName}`,
|
||||
},
|
||||
readFile,
|
||||
uniqueId,
|
||||
ideSettings,
|
||||
writeLog,
|
||||
copyOf(config.completionOptions),
|
||||
config.systemMessage,
|
||||
|
|
@ -282,6 +262,8 @@ async function intermediateToFinalConfig(
|
|||
autocompleteLlm = await llmFromDescription(
|
||||
config.tabAutocompleteModel,
|
||||
readFile,
|
||||
uniqueId,
|
||||
ideSettings,
|
||||
writeLog,
|
||||
config.completionOptions,
|
||||
config.systemMessage,
|
||||
|
|
@ -387,6 +369,7 @@ function finalToBrowserConfig(
|
|||
userToken: final.userToken,
|
||||
embeddingsProvider: final.embeddingsProvider?.id,
|
||||
ui: final.ui,
|
||||
experimental: final.experimental,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -469,15 +452,12 @@ async function buildConfigTs() {
|
|||
async function loadFullConfigNode(
|
||||
readFile: (filepath: string) => Promise<string>,
|
||||
workspaceConfigs: ContinueRcJson[],
|
||||
remoteConfigServerUrl: URL | undefined,
|
||||
ideSettings: IdeSettings,
|
||||
ideType: IdeType,
|
||||
uniqueId: string,
|
||||
writeLog: (log: string) => Promise<void>,
|
||||
): Promise<ContinueConfig> {
|
||||
const serialized = loadSerializedConfig(
|
||||
workspaceConfigs,
|
||||
remoteConfigServerUrl,
|
||||
ideType,
|
||||
);
|
||||
let serialized = loadSerializedConfig(workspaceConfigs, ideSettings, ideType);
|
||||
let intermediate = serializedToIntermediateConfig(serialized);
|
||||
|
||||
const configJsContents = await buildConfigTs();
|
||||
|
|
@ -497,10 +477,10 @@ async function loadFullConfigNode(
|
|||
}
|
||||
|
||||
// Remote config.js
|
||||
if (remoteConfigServerUrl) {
|
||||
if (ideSettings.remoteConfigServerUrl) {
|
||||
try {
|
||||
const configJsPathForRemote = getConfigJsPathForRemote(
|
||||
remoteConfigServerUrl,
|
||||
ideSettings.remoteConfigServerUrl,
|
||||
);
|
||||
const module = await require(configJsPathForRemote);
|
||||
delete require.cache[require.resolve(configJsPathForRemote)];
|
||||
|
|
@ -516,6 +496,8 @@ async function loadFullConfigNode(
|
|||
const finalConfig = await intermediateToFinalConfig(
|
||||
intermediate,
|
||||
readFile,
|
||||
ideSettings,
|
||||
uniqueId,
|
||||
writeLog,
|
||||
);
|
||||
return finalConfig;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { SerializedContinueConfig } from "..";
|
||||
import { SerializedContinueConfig } from "../index.js";
|
||||
|
||||
export function setupOptimizedMode(
|
||||
config: SerializedContinueConfig,
|
||||
|
|
@ -12,9 +12,9 @@ export function setupOptimizedMode(
|
|||
model: "claude-3-sonnet-20240229",
|
||||
},
|
||||
{
|
||||
title: "GPT-4 Turbo (Free Trial)",
|
||||
title: "GPT-4o (Free Trial)",
|
||||
provider: "free-trial",
|
||||
model: "gpt-4-turbo",
|
||||
model: "gpt-4o",
|
||||
},
|
||||
{
|
||||
title: "GPT-3.5-Turbo (Free Trial)",
|
||||
|
|
|
|||
|
|
@ -526,6 +526,7 @@ declare global {
|
|||
| "gpt-3.5-turbo-0613"
|
||||
| "gpt-4-32k"
|
||||
| "gpt-4-turbo"
|
||||
| "gpt-4o"
|
||||
| "gpt-4-turbo-preview"
|
||||
| "gpt-4-vision-preview"
|
||||
// Mistral
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import type { ModelDescription } from "..";
|
||||
import { editConfigJson, getConfigJsonPath } from "../util/paths";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { ModelDescription } from "../index.js";
|
||||
import { editConfigJson, getConfigJsonPath } from "../util/paths.js";
|
||||
|
||||
function stringify(obj: any, indentation?: number): string {
|
||||
return JSON.stringify(
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type {
|
|||
ContextSubmenuItem,
|
||||
IContextProvider,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "..";
|
||||
} from "../index.js";
|
||||
export abstract class BaseContextProvider implements IContextProvider {
|
||||
options: { [key: string]: any };
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
import { CodeSnippetsCodebaseIndex } from "../../indexing/CodeSnippetsIndex";
|
||||
} from "../../index.js";
|
||||
import { CodeSnippetsCodebaseIndex } from "../../indexing/CodeSnippetsIndex.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class CodeContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
// import { getHighlightsThatFit, ILLMContextSizer } from "llm-code-highlighter/dist/index.continue";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
// import { getOutlines } from "llm-code-highlighter/dist/index.continue";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { retrieveContextItemsFromEmbeddings } from "../retrieval/retrieval";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
import { retrieveContextItemsFromEmbeddings } from "../retrieval/retrieval.js";
|
||||
|
||||
class CodebaseContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
|
||||
class CurrentFileContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import type {
|
|||
CustomContextProvider,
|
||||
IContextProvider,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
|
||||
class CustomContextProviderClass implements IContextProvider {
|
||||
custom: CustomContextProvider;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class DatabaseContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class DiffContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
import configs from "../../indexing/docs/preIndexedDocs";
|
||||
import TransformersJsEmbeddingsProvider from "../../indexing/embeddings/TransformersJsEmbeddingsProvider";
|
||||
} from "../../index.js";
|
||||
import configs from "../../indexing/docs/preIndexedDocs.js";
|
||||
import TransformersJsEmbeddingsProvider from "../../indexing/embeddings/TransformersJsEmbeddingsProvider.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class DocsContextProvider extends BaseContextProvider {
|
||||
static DEFAULT_N_RETRIEVE = 30;
|
||||
|
|
@ -24,7 +24,6 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
extras: ContextProviderExtras,
|
||||
): Promise<ContextItem[]> {
|
||||
const { retrieveDocs } = await import("../../indexing/docs/db");
|
||||
|
||||
const embeddingsProvider = new TransformersJsEmbeddingsProvider();
|
||||
const [vector] = await embeddingsProvider.embed([extras.fullInput]);
|
||||
|
||||
|
|
@ -102,6 +101,27 @@ class DocsContextProvider extends BaseContextProvider {
|
|||
id: config.startUrl,
|
||||
})),
|
||||
);
|
||||
|
||||
// Sort submenuItems such that the objects with titles which don't occur in configs occur first, and alphabetized
|
||||
submenuItems.sort((a, b) => {
|
||||
const aTitleInConfigs = !!configs.find(
|
||||
(config) => config.title === a.title,
|
||||
);
|
||||
const bTitleInConfigs = !!configs.find(
|
||||
(config) => config.title === b.title,
|
||||
);
|
||||
|
||||
// Primary criterion: Items not in configs come first
|
||||
if (!aTitleInConfigs && bTitleInConfigs) {
|
||||
return -1;
|
||||
} else if (aTitleInConfigs && !bTitleInConfigs) {
|
||||
return 1;
|
||||
} else {
|
||||
// Secondary criterion: Alphabetical order when both items are in the same category
|
||||
return a.title.localeCompare(b.title);
|
||||
}
|
||||
});
|
||||
|
||||
return submenuItems;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
import { getBasename, getLastNPathParts } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename, getLastNPathParts } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class FileContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
interface Directory {
|
||||
name: string;
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
import { getBasename, getLastNPathParts } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename, getLastNPathParts } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class FolderContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
title: "folder",
|
||||
displayTitle: "Folders",
|
||||
displayTitle: "Folder",
|
||||
description: "Type to search",
|
||||
type: "submenu",
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class GitHubIssuesContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { AxiosError, type AxiosInstance } from "axios";
|
||||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import { AxiosError, AxiosInstance } from "axios";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
interface RemoteBranchInfo {
|
||||
branch: string | null;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class GoogleContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class HttpContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { RequestOptions } from "../../..";
|
||||
import { RequestOptions } from "../../../index.js";
|
||||
const { convert: adf2md } = require("adf-to-md");
|
||||
|
||||
interface JiraClientOptions {
|
||||
|
|
@ -143,7 +143,7 @@ export class JiraClient {
|
|||
this.baseUrl +
|
||||
`/search?fields=summary&jql=${
|
||||
this.options.issueQuery ??
|
||||
`assignee = currentUser() AND resolution = Unresolved order by updated DESC`
|
||||
"assignee = currentUser() AND resolution = Unresolved order by updated DESC"
|
||||
}`,
|
||||
),
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { BaseContextProvider } from "../..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../../..";
|
||||
import { JiraClient } from "./JiraClient";
|
||||
} from "../../../index.js";
|
||||
import { BaseContextProvider } from "../../index.js";
|
||||
import { JiraClient } from "./JiraClient.js";
|
||||
|
||||
class JiraIssuesContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class LocalsProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
//os.platform()
|
||||
//os.arch()
|
||||
|
||||
import os from "node:os";
|
||||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import os from "os";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class OSContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class OpenFilesContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
ContextSubmenuItem,
|
||||
LoadSubmenuItemsArgs,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class PostgresContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
} from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class ProblemsContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class SearchContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { BaseContextProvider } from "..";
|
||||
import type {
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
|
||||
class TerminalContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Readability } from "@mozilla/readability";
|
||||
import { JSDOM } from "jsdom";
|
||||
import { NodeHtmlMarkdown } from "node-html-markdown";
|
||||
import { BaseContextProvider } from "..";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
import {
|
||||
ContextItem,
|
||||
ContextProviderDescription,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
} from "../../index.js";
|
||||
|
||||
class URLContextProvider extends BaseContextProvider {
|
||||
static description: ContextProviderDescription = {
|
||||
|
|
|
|||
|
|
@ -1,26 +1,26 @@
|
|||
import type { BaseContextProvider } from "..";
|
||||
import type { ContextProviderName } from "../..";
|
||||
import CodeContextProvider from "./CodeContextProvider";
|
||||
import CodebaseContextProvider from "./CodebaseContextProvider";
|
||||
import CurrentFileContextProvider from "./CurrentFileContextProvider";
|
||||
import DatabaseContextProvider from "./DatabaseContextProvider";
|
||||
import DiffContextProvider from "./DiffContextProvider";
|
||||
import DocsContextProvider from "./DocsContextProvider";
|
||||
import FileTreeContextProvider from "./FileTreeContextProvider";
|
||||
import FolderContextProvider from "./FolderContextProvider";
|
||||
import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider";
|
||||
import GitLabMergeRequestContextProvider from "./GitLabMergeRequestContextProvider";
|
||||
import GoogleContextProvider from "./GoogleContextProvider";
|
||||
import HttpContextProvider from "./HttpContextProvider";
|
||||
import JiraIssuesContextProvider from "./JiraIssuesContextProvider";
|
||||
import LocalsProvider from "./LocalsProvider";
|
||||
import OSContextProvider from "./OSContextProvider";
|
||||
import OpenFilesContextProvider from "./OpenFilesContextProvider";
|
||||
import PostgresContextProvider from "./PostgresContextProvider";
|
||||
import ProblemsContextProvider from "./ProblemsContextProvider";
|
||||
import SearchContextProvider from "./SearchContextProvider";
|
||||
import TerminalContextProvider from "./TerminalContextProvider";
|
||||
import URLContextProvider from "./URLContextProvider";
|
||||
import { ContextProviderName } from "../../index.js";
|
||||
import { BaseContextProvider } from "../index.js";
|
||||
import CodeContextProvider from "./CodeContextProvider.js";
|
||||
import CodebaseContextProvider from "./CodebaseContextProvider.js";
|
||||
import CurrentFileContextProvider from "./CurrentFileContextProvider.js";
|
||||
import DatabaseContextProvider from "./DatabaseContextProvider.js";
|
||||
import DiffContextProvider from "./DiffContextProvider.js";
|
||||
import DocsContextProvider from "./DocsContextProvider.js";
|
||||
import FileTreeContextProvider from "./FileTreeContextProvider.js";
|
||||
import FolderContextProvider from "./FolderContextProvider.js";
|
||||
import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider.js";
|
||||
import GitLabMergeRequestContextProvider from "./GitLabMergeRequestContextProvider.js";
|
||||
import GoogleContextProvider from "./GoogleContextProvider.js";
|
||||
import HttpContextProvider from "./HttpContextProvider.js";
|
||||
import JiraIssuesContextProvider from "./JiraIssuesContextProvider/index.js";
|
||||
import LocalsProvider from "./LocalsProvider.js";
|
||||
import OSContextProvider from "./OSContextProvider.js";
|
||||
import OpenFilesContextProvider from "./OpenFilesContextProvider.js";
|
||||
import PostgresContextProvider from "./PostgresContextProvider.js";
|
||||
import ProblemsContextProvider from "./ProblemsContextProvider.js";
|
||||
import SearchContextProvider from "./SearchContextProvider.js";
|
||||
import TerminalContextProvider from "./TerminalContextProvider.js";
|
||||
import URLContextProvider from "./URLContextProvider.js";
|
||||
|
||||
const Providers: (typeof BaseContextProvider)[] = [
|
||||
DiffContextProvider,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import fetch from "node-fetch";
|
||||
import { Chunk, Reranker } from "../..";
|
||||
import { Chunk, Reranker } from "../../index.js";
|
||||
|
||||
export class CohereReranker implements Reranker {
|
||||
name = "cohere";
|
||||
|
|
@ -18,7 +18,7 @@ export class CohereReranker implements Reranker {
|
|||
) {}
|
||||
|
||||
async rerank(query: string, chunks: Chunk[]): Promise<number[]> {
|
||||
let apiBase = this.params.apiBase ?? CohereReranker.defaultOptions.apiBase
|
||||
let apiBase = this.params.apiBase ?? CohereReranker.defaultOptions.apiBase;
|
||||
if (!apiBase.endsWith("/")) {
|
||||
apiBase += "/";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import fetch from "node-fetch";
|
||||
import type { Chunk, Reranker } from "../..";
|
||||
import { getHeaders } from "../../continueServer/stubs/headers";
|
||||
import { SERVER_URL } from "../../util/parameters";
|
||||
import { getHeaders } from "../../continueServer/stubs/headers.js";
|
||||
import { Chunk, Reranker } from "../../index.js";
|
||||
import { SERVER_URL } from "../../util/parameters.js";
|
||||
|
||||
export class FreeTrialReranker implements Reranker {
|
||||
name = "free-trial";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import { RerankerName } from "../..";
|
||||
import { CohereReranker } from "./cohere";
|
||||
import { FreeTrialReranker } from "./freeTrial";
|
||||
import { LLMReranker } from "./llm";
|
||||
import { VoyageReranker } from "./voyage";
|
||||
import { RerankerName } from "../../index.js";
|
||||
import { CohereReranker } from "./cohere.js";
|
||||
import { FreeTrialReranker } from "./freeTrial.js";
|
||||
import { LLMReranker } from "./llm.js";
|
||||
import { VoyageReranker } from "./voyage.js";
|
||||
|
||||
export const AllRerankers: { [key in RerankerName]: any } = {
|
||||
cohere: CohereReranker,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
import type { Chunk, ILLM, Reranker } from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
import { Chunk, ILLM, Reranker } from "../../index.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
|
||||
const RERANK_PROMPT = (query: string, documentId: string, document: string) => `You are an expert software developer responsible for helping detect whether the retrieved snippet of code is relevant to the query. For a given input, you need to output a single word: "Yes" or "No" indicating the retrieved snippet is relevant to the query.
|
||||
const RERANK_PROMPT = (
|
||||
query: string,
|
||||
documentId: string,
|
||||
document: string,
|
||||
) => `You are an expert software developer responsible for helping detect whether the retrieved snippet of code is relevant to the query. For a given input, you need to output a single word: "Yes" or "No" indicating the retrieved snippet is relevant to the query.
|
||||
|
||||
Query: Where is the FastAPI server?
|
||||
Snippet:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import fetch from "node-fetch";
|
||||
import { Chunk, Reranker } from "../..";
|
||||
import { Chunk, Reranker } from "../../index.js";
|
||||
|
||||
export class VoyageReranker implements Reranker {
|
||||
name = "voyage";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { BranchAndDir, Chunk } from "../..";
|
||||
import { FullTextSearchCodebaseIndex } from "../../indexing/FullTextSearch";
|
||||
import { BranchAndDir, Chunk } from "../../index.js";
|
||||
import { FullTextSearchCodebaseIndex } from "../../indexing/FullTextSearch.js";
|
||||
export async function retrieveFts(
|
||||
query: string,
|
||||
n: number,
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import type {
|
||||
import {
|
||||
BranchAndDir,
|
||||
Chunk,
|
||||
ContextItem,
|
||||
ContextProviderExtras,
|
||||
} from "../..";
|
||||
import { LanceDbIndex } from "../../indexing/LanceDbIndex";
|
||||
} from "../../index.js";
|
||||
import { LanceDbIndex } from "../../indexing/LanceDbIndex.js";
|
||||
|
||||
import { deduplicateArray, getBasename } from "../../util";
|
||||
import { RETRIEVAL_PARAMS } from "../../util/parameters";
|
||||
import { retrieveFts } from "./fullTextSearch";
|
||||
import { deduplicateArray, getBasename } from "../../util/index.js";
|
||||
import { RETRIEVAL_PARAMS } from "../../util/parameters.js";
|
||||
import { retrieveFts } from "./fullTextSearch.js";
|
||||
|
||||
function deduplicateChunks(chunks: Chunk[]): Chunk[] {
|
||||
return deduplicateArray(chunks, (a, b) => {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { Chunk } from "..";
|
||||
import { Chunk } from "../index.js";
|
||||
|
||||
export interface EmbeddingsCacheChunk {
|
||||
vector: number[];
|
||||
|
|
@ -19,6 +19,9 @@ export interface EmbeddingsCacheResponse<T extends ArtifactType> {
|
|||
}
|
||||
|
||||
export interface IContinueServerClient {
|
||||
connected: boolean;
|
||||
url: URL | undefined;
|
||||
getUserToken(): Promise<string | undefined>;
|
||||
getConfig(): Promise<{ configJson: string; configJs: string }>;
|
||||
getFromIndexCache<T extends ArtifactType>(
|
||||
keys: string[],
|
||||
|
|
|
|||
|
|
@ -2,13 +2,31 @@ import type {
|
|||
ArtifactType,
|
||||
EmbeddingsCacheResponse,
|
||||
IContinueServerClient,
|
||||
} from "../interface";
|
||||
} from "../interface.js";
|
||||
|
||||
export class ContinueServerClient implements IContinueServerClient {
|
||||
url: URL | undefined;
|
||||
|
||||
constructor(
|
||||
private readonly serverUrl: string,
|
||||
serverUrl: string | undefined,
|
||||
private readonly userToken: Promise<string | undefined>,
|
||||
) {}
|
||||
) {
|
||||
try {
|
||||
this.url =
|
||||
typeof serverUrl !== "string" || serverUrl === ""
|
||||
? undefined
|
||||
: new URL(serverUrl);
|
||||
} catch (e) {
|
||||
console.warn("Invalid Continue server url", e);
|
||||
this.url = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
getUserToken(): Promise<string | undefined> {
|
||||
return this.userToken;
|
||||
}
|
||||
|
||||
connected: boolean = false;
|
||||
|
||||
public async getConfig(): Promise<{ configJson: string; configJs: string }> {
|
||||
throw new Error("Not Implemented");
|
||||
|
|
|
|||
18
core/core.ts
18
core/core.ts
|
|
@ -266,7 +266,14 @@ export class Core {
|
|||
while (!next.done) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
next = await gen.return({ completion: "", prompt: "" });
|
||||
next = await gen.return({
|
||||
completion: "",
|
||||
prompt: "",
|
||||
completionOptions: {
|
||||
...msg.data.completionOptions,
|
||||
model: model.model,
|
||||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
yield { content: next.value.content };
|
||||
|
|
@ -295,7 +302,14 @@ export class Core {
|
|||
while (!next.done) {
|
||||
if (abortedMessageIds.has(msg.messageId)) {
|
||||
abortedMessageIds.delete(msg.messageId);
|
||||
next = await gen.return({ completion: "", prompt: "" });
|
||||
next = await gen.return({
|
||||
completion: "",
|
||||
prompt: "",
|
||||
completionOptions: {
|
||||
...msg.data.completionOptions,
|
||||
model: model.model,
|
||||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
yield { content: next.value };
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { DiffLine } from "..";
|
||||
import { type LineStream, matchLine } from "./util";
|
||||
import { DiffLine } from "../index.js";
|
||||
import { LineStream, matchLine } from "./util.js";
|
||||
|
||||
/**
|
||||
* https://blog.jcoglan.com/2017/02/12/the-myers-diff-algorithm-part-1/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { distance } from "fastest-levenshtein";
|
||||
import type { ChatMessage } from "..";
|
||||
import { stripImages } from "../llm/countTokens";
|
||||
import { ChatMessage } from "../index.js";
|
||||
import { stripImages } from "../llm/countTokens.js";
|
||||
|
||||
export type LineStream = AsyncGenerator<string>;
|
||||
|
||||
|
|
|
|||
23
core/index.d.ts
vendored
23
core/index.d.ts
vendored
|
|
@ -37,11 +37,7 @@ export interface Chunk extends ChunkWithoutID {
|
|||
export interface IndexingProgressUpdate {
|
||||
progress: number;
|
||||
desc: string;
|
||||
}
|
||||
|
||||
export interface LLMReturnValue {
|
||||
prompt: string;
|
||||
completion: string;
|
||||
status: "starting" | "indexing" | "done" | "failed" | "paused";
|
||||
}
|
||||
|
||||
export type PromptTemplate =
|
||||
|
|
@ -80,12 +76,12 @@ export interface ILLM extends LLMOptions {
|
|||
streamComplete(
|
||||
prompt: string,
|
||||
options?: LLMFullCompletionOptions,
|
||||
): AsyncGenerator<string, LLMReturnValue>;
|
||||
): AsyncGenerator<string, PromptLog>;
|
||||
|
||||
streamChat(
|
||||
messages: ChatMessage[],
|
||||
options?: LLMFullCompletionOptions,
|
||||
): AsyncGenerator<ChatMessage, LLMReturnValue>;
|
||||
): AsyncGenerator<ChatMessage, PromptLog>;
|
||||
|
||||
chat(
|
||||
messages: ChatMessage[],
|
||||
|
|
@ -258,12 +254,18 @@ export interface InputModifiers {
|
|||
noContext: boolean;
|
||||
}
|
||||
|
||||
export interface PromptLog {
|
||||
completionOptions: CompletionOptions;
|
||||
prompt: string;
|
||||
completion: string;
|
||||
}
|
||||
|
||||
export interface ChatHistoryItem {
|
||||
message: ChatMessage;
|
||||
editorState?: any;
|
||||
modifiers?: InputModifiers;
|
||||
contextItems: ContextItemWithId[];
|
||||
promptLogs?: [string, string][]; // [prompt, completion]
|
||||
promptLogs?: PromptLog[];
|
||||
}
|
||||
|
||||
export type ChatHistory = ChatHistoryItem[];
|
||||
|
|
@ -530,6 +532,7 @@ type ModelProvider =
|
|||
| "deepinfra"
|
||||
| "flowise"
|
||||
| "groq"
|
||||
| "continue-proxy"
|
||||
| "custom";
|
||||
|
||||
export type ModelName =
|
||||
|
|
@ -540,6 +543,7 @@ export type ModelName =
|
|||
| "gpt-4"
|
||||
| "gpt-3.5-turbo-0613"
|
||||
| "gpt-4-32k"
|
||||
| "gpt-4o"
|
||||
| "gpt-4-turbo"
|
||||
| "gpt-4-turbo-preview"
|
||||
| "gpt-4-vision-preview"
|
||||
|
|
@ -704,6 +708,8 @@ export interface TabAutocompleteOptions {
|
|||
useCache: boolean;
|
||||
onlyMyCode: boolean;
|
||||
useOtherFiles: boolean;
|
||||
useRecentlyEdited: boolean;
|
||||
recentLinePrefixMatchMinLength: number;
|
||||
disableInFiles?: string[];
|
||||
}
|
||||
|
||||
|
|
@ -726,6 +732,7 @@ interface ModelRoles {
|
|||
interface ExperimantalConfig {
|
||||
contextMenuPrompts?: ContextMenuConfig;
|
||||
modelRoles?: ModelRoles;
|
||||
defaultContext?: "activeFile"[];
|
||||
}
|
||||
|
||||
export interface SerializedContinueConfig {
|
||||
|
|
|
|||
|
|
@ -7,20 +7,20 @@ import type {
|
|||
IDE,
|
||||
IndexTag,
|
||||
IndexingProgressUpdate,
|
||||
} from "..";
|
||||
import { getBasename } from "../util";
|
||||
} from "../index.js";
|
||||
import { getBasename } from "../util/index.js";
|
||||
import {
|
||||
getLanguageForFile,
|
||||
getParserForFile,
|
||||
supportedLanguages,
|
||||
} from "../util/treeSitter";
|
||||
import { type DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex";
|
||||
} from "../util/treeSitter.js";
|
||||
import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex.js";
|
||||
import {
|
||||
type CodebaseIndex,
|
||||
IndexResultType,
|
||||
type MarkCompleteCallback,
|
||||
type RefreshIndexResults,
|
||||
} from "./types";
|
||||
MarkCompleteCallback,
|
||||
RefreshIndexResults,
|
||||
type CodebaseIndex,
|
||||
} from "./types.js";
|
||||
|
||||
export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
||||
artifactId = "codeSnippets";
|
||||
|
|
@ -138,6 +138,7 @@ export class CodeSnippetsCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
desc: `Indexing ${compute.path}`,
|
||||
progress: i / results.compute.length,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([compute], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,18 @@
|
|||
import type { BranchAndDir, Chunk, IndexTag, IndexingProgressUpdate } from "..";
|
||||
import { RETRIEVAL_PARAMS } from "../util/parameters";
|
||||
import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex";
|
||||
import { type DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex";
|
||||
import {
|
||||
type CodebaseIndex,
|
||||
BranchAndDir,
|
||||
Chunk,
|
||||
IndexTag,
|
||||
IndexingProgressUpdate,
|
||||
} from "../index.js";
|
||||
import { RETRIEVAL_PARAMS } from "../util/parameters.js";
|
||||
import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex.js";
|
||||
import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex.js";
|
||||
import {
|
||||
IndexResultType,
|
||||
type MarkCompleteCallback,
|
||||
type RefreshIndexResults,
|
||||
} from "./types";
|
||||
MarkCompleteCallback,
|
||||
RefreshIndexResults,
|
||||
type CodebaseIndex,
|
||||
} from "./types.js";
|
||||
|
||||
export class FullTextSearchCodebaseIndex implements CodebaseIndex {
|
||||
artifactId = "sqliteFts";
|
||||
|
|
@ -61,6 +66,7 @@ export class FullTextSearchCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
progress: i / results.compute.length,
|
||||
desc: `Indexing ${item.path}`,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([item], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,25 +1,25 @@
|
|||
// NOTE: vectordb requirement must be listed in extensions/vscode to avoid error
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import type { Table } from "vectordb";
|
||||
import type {
|
||||
import { Table } from "vectordb";
|
||||
import { IContinueServerClient } from "../continueServer/interface.js";
|
||||
import {
|
||||
BranchAndDir,
|
||||
Chunk,
|
||||
EmbeddingsProvider,
|
||||
IndexTag,
|
||||
IndexingProgressUpdate,
|
||||
} from "..";
|
||||
import type { ContinueServerClient } from "../continueServer/stubs/client";
|
||||
import { MAX_CHUNK_SIZE } from "../llm/constants";
|
||||
import { getBasename } from "../util";
|
||||
import { getLanceDbPath } from "../util/paths";
|
||||
import { chunkDocument } from "./chunk/chunk";
|
||||
import { SqliteDb, tagToString, type DatabaseConnection } from "./refreshIndex";
|
||||
} from "../index.js";
|
||||
import { MAX_CHUNK_SIZE } from "../llm/constants.js";
|
||||
import { getBasename } from "../util/index.js";
|
||||
import { getLanceDbPath } from "../util/paths.js";
|
||||
import { chunkDocument } from "./chunk/chunk.js";
|
||||
import { DatabaseConnection, SqliteDb, tagToString } from "./refreshIndex.js";
|
||||
import {
|
||||
CodebaseIndex,
|
||||
IndexResultType,
|
||||
type CodebaseIndex,
|
||||
type PathAndCacheKey,
|
||||
type RefreshIndexResults,
|
||||
} from "./types";
|
||||
PathAndCacheKey,
|
||||
RefreshIndexResults,
|
||||
} from "./types.js";
|
||||
|
||||
// LanceDB converts to lowercase, so names must all be lowercase
|
||||
interface LanceDbRow {
|
||||
|
|
@ -40,7 +40,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
constructor(
|
||||
private readonly embeddingsProvider: EmbeddingsProvider,
|
||||
private readonly readFile: (filepath: string) => Promise<string>,
|
||||
private readonly continueServerClient?: ContinueServerClient,
|
||||
private readonly continueServerClient?: IContinueServerClient,
|
||||
) {}
|
||||
|
||||
private tableNameForTag(tag: IndexTag) {
|
||||
|
|
@ -176,7 +176,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
};
|
||||
|
||||
// Check remote cache
|
||||
if (this.continueServerClient !== undefined) {
|
||||
if (this.continueServerClient?.connected) {
|
||||
try {
|
||||
const keys = results.compute.map(({ cacheKey }) => cacheKey);
|
||||
const resp = await this.continueServerClient.getFromIndexCache(
|
||||
|
|
@ -250,7 +250,7 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
data.contents,
|
||||
);
|
||||
|
||||
yield { progress, desc };
|
||||
yield { progress, desc, status: "indexing" };
|
||||
} else {
|
||||
await addComputedLanceDbRows(update, computedRows);
|
||||
computedRows = [];
|
||||
|
|
@ -304,7 +304,11 @@ export class LanceDbIndex implements CodebaseIndex {
|
|||
}
|
||||
|
||||
markComplete(results.del, IndexResultType.Delete);
|
||||
yield { progress: 1, desc: "Completed Calculating Embeddings" };
|
||||
yield {
|
||||
progress: 1,
|
||||
desc: "Completed Calculating Embeddings",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
|
||||
private async _retrieveForTag(
|
||||
|
|
|
|||
|
|
@ -1,19 +1,15 @@
|
|||
import type { Chunk, IndexTag, IndexingProgressUpdate } from "../..";
|
||||
import type { ContinueServerClient } from "../../continueServer/stubs/client";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants";
|
||||
import { getBasename } from "../../util";
|
||||
import { IContinueServerClient } from "../../continueServer/interface.js";
|
||||
import { Chunk, IndexTag, IndexingProgressUpdate } from "../../index.js";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants.js";
|
||||
import { getBasename } from "../../util/index.js";
|
||||
import { DatabaseConnection, SqliteDb, tagToString } from "../refreshIndex.js";
|
||||
import {
|
||||
type DatabaseConnection,
|
||||
SqliteDb,
|
||||
tagToString,
|
||||
} from "../refreshIndex";
|
||||
import {
|
||||
type CodebaseIndex,
|
||||
IndexResultType,
|
||||
type MarkCompleteCallback,
|
||||
type RefreshIndexResults,
|
||||
} from "../types";
|
||||
import { chunkDocument } from "./chunk";
|
||||
MarkCompleteCallback,
|
||||
RefreshIndexResults,
|
||||
type CodebaseIndex,
|
||||
} from "../types.js";
|
||||
import { chunkDocument } from "./chunk.js";
|
||||
|
||||
export class ChunkCodebaseIndex implements CodebaseIndex {
|
||||
static artifactId = "chunks";
|
||||
|
|
@ -21,7 +17,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
|
||||
constructor(
|
||||
private readonly readFile: (filepath: string) => Promise<string>,
|
||||
private readonly continueServerClient?: ContinueServerClient,
|
||||
private readonly continueServerClient: IContinueServerClient,
|
||||
) {
|
||||
this.readFile = readFile;
|
||||
}
|
||||
|
|
@ -75,7 +71,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
}
|
||||
|
||||
// Check the remote cache
|
||||
if (this.continueServerClient !== undefined) {
|
||||
if (this.continueServerClient.connected) {
|
||||
try {
|
||||
const keys = results.compute.map(({ cacheKey }) => cacheKey);
|
||||
const resp = await this.continueServerClient.getFromIndexCache(
|
||||
|
|
@ -117,6 +113,7 @@ export class ChunkCodebaseIndex implements CodebaseIndex {
|
|||
yield {
|
||||
progress: i / results.compute.length,
|
||||
desc: `Chunking ${getBasename(item.path)}`,
|
||||
status: "indexing",
|
||||
};
|
||||
markComplete([item], IndexResultType.Compute);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { ChunkWithoutID } from "../..";
|
||||
import { countTokens } from "../../llm/countTokens";
|
||||
import { ChunkWithoutID } from "../../index.js";
|
||||
import { countTokens } from "../../llm/countTokens.js";
|
||||
|
||||
export function* basicChunker(
|
||||
contents: string,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import type { 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 } from "./code";
|
||||
import { Chunk, ChunkWithoutID } from "../../index.js";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants.js";
|
||||
import { countTokens } from "../../llm/countTokens.js";
|
||||
import { supportedLanguages } from "../../util/treeSitter.js";
|
||||
import { basicChunker } from "./basic.js";
|
||||
import { codeChunker } from "./code.js";
|
||||
|
||||
async function* chunkDocumentWithoutId(
|
||||
filepath: string,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import type { SyntaxNode } from "web-tree-sitter";
|
||||
import type { ChunkWithoutID } from "../..";
|
||||
import { countTokens } from "../../llm/countTokens";
|
||||
import { getParserForFile } from "../../util/treeSitter";
|
||||
import { SyntaxNode } from "web-tree-sitter";
|
||||
import { ChunkWithoutID } from "../../index.js";
|
||||
import { countTokens } from "../../llm/countTokens.js";
|
||||
import { getParserForFile } from "../../util/treeSitter.js";
|
||||
|
||||
function collapsedReplacement(node: SyntaxNode): string {
|
||||
if (node.type === "statement_block") {
|
||||
|
|
@ -94,6 +94,14 @@ function collapseChildren(
|
|||
return code;
|
||||
}
|
||||
|
||||
export const FUNCTION_BLOCK_NODE_TYPES = ["block", "statement_block"];
|
||||
export const FUNCTION_DECLARATION_NODE_TYPEs = [
|
||||
"method_definition",
|
||||
"function_definition",
|
||||
"function_item",
|
||||
"function_declaration",
|
||||
];
|
||||
|
||||
function constructClassDefinitionChunk(
|
||||
node: SyntaxNode,
|
||||
code: string,
|
||||
|
|
@ -103,8 +111,8 @@ function constructClassDefinitionChunk(
|
|||
node,
|
||||
code,
|
||||
["block", "class_body", "declaration_list"],
|
||||
["method_definition", "function_definition", "function_item"],
|
||||
["block", "statement_block"],
|
||||
FUNCTION_DECLARATION_NODE_TYPEs,
|
||||
FUNCTION_BLOCK_NODE_TYPES,
|
||||
maxChunkSize,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { ChunkWithoutID } from "../..";
|
||||
import { countTokens } from "../../llm/countTokens";
|
||||
import { basicChunker } from "./basic";
|
||||
import { ChunkWithoutID } from "../../index.js";
|
||||
import { countTokens } from "../../llm/countTokens.js";
|
||||
import { basicChunker } from "./basic.js";
|
||||
|
||||
export function cleanFragment(
|
||||
fragment: string | undefined,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { Readability } from "@mozilla/readability";
|
||||
import { JSDOM } from "jsdom";
|
||||
import type { Chunk } from "../..";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants";
|
||||
import { cleanFragment, cleanHeader } from "../chunk/markdown";
|
||||
import type { PageData } from "./crawl";
|
||||
import { Chunk } from "../../index.js";
|
||||
import { MAX_CHUNK_SIZE } from "../../llm/constants.js";
|
||||
import { cleanFragment, cleanHeader } from "../chunk/markdown.js";
|
||||
import { PageData } from "./crawl.js";
|
||||
|
||||
export type ArticleComponent = {
|
||||
title: string;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { type Database, open } from "sqlite";
|
||||
import { open, type Database } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
import type { Chunk } from "../..";
|
||||
import { getDocsSqlitePath, getLanceDbPath } from "../../util/paths";
|
||||
import { Chunk } from "../../index.js";
|
||||
import { getDocsSqlitePath, getLanceDbPath } from "../../util/paths.js";
|
||||
|
||||
import { downloadPreIndexedDocs } from "./preIndexed";
|
||||
import { default as configs } from "./preIndexedDocs";
|
||||
import { downloadPreIndexedDocs } from "./preIndexed.js";
|
||||
import { default as configs } from "./preIndexedDocs.js";
|
||||
|
||||
const DOCS_TABLE_NAME = "docs";
|
||||
|
||||
|
|
@ -69,7 +69,9 @@ export async function retrieveDocs(
|
|||
const tableNames = await lance.tableNames();
|
||||
if (!tableNames.includes(DOCS_TABLE_NAME)) {
|
||||
const downloaded = await downloadDocs();
|
||||
if (downloaded) return downloaded;
|
||||
if (downloaded) {
|
||||
return downloaded;
|
||||
}
|
||||
}
|
||||
|
||||
const table = await lance.openTable(DOCS_TABLE_NAME);
|
||||
|
|
@ -83,7 +85,9 @@ export async function retrieveDocs(
|
|||
|
||||
if ((!docs || docs.length === 0) && !nested) {
|
||||
const downloaded = await downloadDocs();
|
||||
if (downloaded) return downloaded;
|
||||
if (downloaded) {
|
||||
return downloaded;
|
||||
}
|
||||
}
|
||||
|
||||
return docs.map((doc) => ({
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
import type { Chunk, EmbeddingsProvider, IndexingProgressUpdate } from "../..";
|
||||
import {
|
||||
Chunk,
|
||||
EmbeddingsProvider,
|
||||
IndexingProgressUpdate,
|
||||
} from "../../index.js";
|
||||
|
||||
import { type Article, chunkArticle, pageToArticle } from "./article";
|
||||
import { crawlPage } from "./crawl";
|
||||
import { addDocs, hasDoc } from "./db";
|
||||
import { Article, chunkArticle, pageToArticle } from "./article.js";
|
||||
import { crawlPage } from "./crawl.js";
|
||||
import { addDocs, hasDoc } from "./db.js";
|
||||
|
||||
export async function* indexDocs(
|
||||
title: string,
|
||||
|
|
@ -13,6 +17,7 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Already indexed",
|
||||
status: "done",
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
@ -20,19 +25,23 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 0,
|
||||
desc: "Finding subpages",
|
||||
status: "indexing",
|
||||
};
|
||||
|
||||
const articles: Article[] = [];
|
||||
|
||||
for await (const page of crawlPage(baseUrl)) {
|
||||
const article = pageToArticle(page);
|
||||
if (!article) continue;
|
||||
if (!article) {
|
||||
continue;
|
||||
}
|
||||
|
||||
articles.push(article);
|
||||
|
||||
yield {
|
||||
progress: 0,
|
||||
desc: `Finding subpages (${page.path})`,
|
||||
status: "indexing",
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -43,6 +52,7 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: Math.max(1, Math.floor(100 / (articles.length + 1))),
|
||||
desc: `${article.subpath}`,
|
||||
status: "indexing",
|
||||
};
|
||||
|
||||
const subpathEmbeddings = await embeddingsProvider.embed(
|
||||
|
|
@ -61,5 +71,6 @@ export async function* indexDocs(
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Done",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import type { Chunk } from "../..";
|
||||
import { addDocs } from "./db";
|
||||
import { Chunk } from "../../index.js";
|
||||
import { addDocs } from "./db.js";
|
||||
|
||||
const request = require("request");
|
||||
|
||||
|
|
|
|||
|
|
@ -226,6 +226,11 @@ const configs: SiteIndexingConfig[] = [
|
|||
startUrl: "https://developer.wordpress.org/reference/",
|
||||
rootUrl: "https://developer.wordpress.org/reference/",
|
||||
},
|
||||
{
|
||||
title: "PySide6",
|
||||
startUrl: "https://doc.qt.io/qtforpython-6/quickstart.html",
|
||||
rootUrl: "https://doc.qt.io/qtforpython-6/api.html",
|
||||
},
|
||||
];
|
||||
|
||||
export default configs;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { EmbedOptions, EmbeddingsProvider, FetchFunction } from "../..";
|
||||
import { EmbedOptions, EmbeddingsProvider, FetchFunction } from "../../index.js";
|
||||
|
||||
class BaseEmbeddingsProvider implements EmbeddingsProvider {
|
||||
options: EmbedOptions;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Response } from "node-fetch";
|
||||
import { EmbedOptions } from "../..";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import { EmbedOptions } from "../../index.js";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
class CohereEmbeddingsProvider extends BaseEmbeddingsProvider {
|
||||
static maxBatchSize = 96;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import type { EmbedOptions } from "../..";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import { EmbedOptions } from "../../index.js";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
class DeepInfraEmbeddingsProvider extends BaseEmbeddingsProvider {
|
||||
static defaultOptions: Partial<EmbedOptions> | undefined = {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { Response } from "node-fetch";
|
||||
import { EmbedOptions } from "../..";
|
||||
import { getHeaders } from "../../continueServer/stubs/headers";
|
||||
import { SERVER_URL } from "../../util/parameters";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import { EmbedOptions } from "../../index.js";
|
||||
import { getHeaders } from "../../continueServer/stubs/headers.js";
|
||||
import { SERVER_URL } from "../../util/parameters.js";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
class FreeTrialEmbeddingsProvider extends BaseEmbeddingsProvider {
|
||||
static maxBatchSize = 128;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { EmbedOptions, FetchFunction } from "../..";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import { EmbedOptions, FetchFunction } from "../../index.js";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
async function embedOne(
|
||||
chunk: string,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Response } from "node-fetch";
|
||||
import { EmbedOptions } from "../..";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import { EmbedOptions } from "../../index.js";
|
||||
import { withExponentialBackoff } from "../../util/withExponentialBackoff.js";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
class OpenAIEmbeddingsProvider extends BaseEmbeddingsProvider {
|
||||
// https://platform.openai.com/docs/api-reference/embeddings/create is 2048
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
// @ts-ignore
|
||||
import {
|
||||
PipelineType,
|
||||
env,
|
||||
pipeline,
|
||||
type PipelineType,
|
||||
} from "../../vendor/node_modules/@xenova/transformers";
|
||||
} from "../../vendor/modules/@xenova/transformers/src/transformers.js";
|
||||
|
||||
import path from "node:path";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider";
|
||||
import path from "path";
|
||||
import BaseEmbeddingsProvider from "./BaseEmbeddingsProvider.js";
|
||||
|
||||
env.allowLocalModels = true;
|
||||
env.allowRemoteModels = false;
|
||||
|
|
@ -34,8 +35,11 @@ class EmbeddingsPipeline {
|
|||
export class TransformersJsEmbeddingsProvider extends BaseEmbeddingsProvider {
|
||||
static MaxGroupSize = 4;
|
||||
|
||||
constructor() {
|
||||
super({ model: EmbeddingsPipeline.model }, () => Promise.resolve(null));
|
||||
constructor(modelPath?: string) {
|
||||
super({ model: "all-MiniLM-L2-v6" }, () => Promise.resolve(null));
|
||||
if (modelPath) {
|
||||
env.localModelPath = modelPath;
|
||||
}
|
||||
}
|
||||
|
||||
get id(): string {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { EmbeddingsProviderName } from "../..";
|
||||
import CohereEmbeddingsProvider from "./CohereEmbeddingsProvider";
|
||||
import FreeTrialEmbeddingsProvider from "./FreeTrialEmbeddingsProvider";
|
||||
import OllamaEmbeddingsProvider from "./OllamaEmbeddingsProvider";
|
||||
import OpenAIEmbeddingsProvider from "./OpenAIEmbeddingsProvider";
|
||||
import TransformersJsEmbeddingsProvider from "./TransformersJsEmbeddingsProvider";
|
||||
import { EmbeddingsProviderName } from "../../index.js";
|
||||
import CohereEmbeddingsProvider from "./CohereEmbeddingsProvider.js";
|
||||
import FreeTrialEmbeddingsProvider from "./FreeTrialEmbeddingsProvider.js";
|
||||
import OllamaEmbeddingsProvider from "./OllamaEmbeddingsProvider.js";
|
||||
import OpenAIEmbeddingsProvider from "./OpenAIEmbeddingsProvider.js";
|
||||
import TransformersJsEmbeddingsProvider from "./TransformersJsEmbeddingsProvider.js";
|
||||
|
||||
export const AllEmbeddingsProviders: {
|
||||
[key in EmbeddingsProviderName]: any;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import type { IDE, IndexTag, IndexingProgressUpdate } from "..";
|
||||
import type { ConfigHandler } from "../config/handler";
|
||||
import { ContinueServerClient } from "../continueServer/stubs/client";
|
||||
import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex";
|
||||
import { FullTextSearchCodebaseIndex } from "./FullTextSearch";
|
||||
import { LanceDbIndex } from "./LanceDbIndex";
|
||||
import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex";
|
||||
import { getComputeDeleteAddRemove } from "./refreshIndex";
|
||||
import type { CodebaseIndex } from "./types";
|
||||
import { ConfigHandler } from "../config/handler.js";
|
||||
import { IContinueServerClient } from "../continueServer/interface.js";
|
||||
import { IDE, IndexTag, IndexingProgressUpdate } from "../index.js";
|
||||
import { CodeSnippetsCodebaseIndex } from "./CodeSnippetsIndex.js";
|
||||
import { FullTextSearchCodebaseIndex } from "./FullTextSearch.js";
|
||||
import { LanceDbIndex } from "./LanceDbIndex.js";
|
||||
import { ChunkCodebaseIndex } from "./chunk/ChunkCodebaseIndex.js";
|
||||
import { getComputeDeleteAddRemove } from "./refreshIndex.js";
|
||||
import { CodebaseIndex } from "./types.js";
|
||||
|
||||
export class PauseToken {
|
||||
constructor(private _paused: boolean) {}
|
||||
|
|
@ -21,21 +21,12 @@ export class PauseToken {
|
|||
}
|
||||
|
||||
export class CodebaseIndexer {
|
||||
private continueServerClient?: ContinueServerClient;
|
||||
constructor(
|
||||
private readonly configHandler: ConfigHandler,
|
||||
private readonly ide: IDE,
|
||||
private readonly pauseToken: PauseToken,
|
||||
private readonly continueServerUrl: string | undefined,
|
||||
private readonly userToken: string | undefined,
|
||||
) {
|
||||
if (this.continueServerUrl) {
|
||||
this.continueServerClient = new ContinueServerClient(
|
||||
this.continueServerUrl,
|
||||
Promise.resolve(this.userToken),
|
||||
);
|
||||
}
|
||||
}
|
||||
private readonly continueServerClient: IContinueServerClient,
|
||||
) {}
|
||||
|
||||
private async getIndexesToBuild(): Promise<CodebaseIndex[]> {
|
||||
const config = await this.configHandler.loadConfig();
|
||||
|
|
@ -81,6 +72,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: 0,
|
||||
desc: "Starting indexing...",
|
||||
status: "starting",
|
||||
};
|
||||
|
||||
for (const directory of workspaceDirs) {
|
||||
|
|
@ -119,6 +111,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: 1,
|
||||
desc: "Indexing cancelled",
|
||||
status: "failed",
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
|
@ -132,6 +125,7 @@ export class CodebaseIndexer {
|
|||
(completedIndexes + progress) / indexesToBuild.length) /
|
||||
workspaceDirs.length,
|
||||
desc,
|
||||
status: "indexing",
|
||||
};
|
||||
}
|
||||
completedIndexes++;
|
||||
|
|
@ -139,7 +133,8 @@ export class CodebaseIndexer {
|
|||
progress:
|
||||
(completedDirs + completedIndexes / indexesToBuild.length) /
|
||||
workspaceDirs.length,
|
||||
desc: `Completed indexing ${codebaseIndex.artifactId}`,
|
||||
desc: "Completed indexing " + codebaseIndex.artifactId,
|
||||
status: "indexing",
|
||||
};
|
||||
} catch (e) {
|
||||
console.warn(
|
||||
|
|
@ -152,6 +147,7 @@ export class CodebaseIndexer {
|
|||
yield {
|
||||
progress: completedDirs / workspaceDirs.length,
|
||||
desc: "Indexing Complete",
|
||||
status: "done",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import crypto from "node:crypto";
|
||||
import * as fs from "node:fs";
|
||||
import { type Database, open } from "sqlite";
|
||||
import { open, type Database } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
import type { IndexTag, IndexingProgressUpdate } from "..";
|
||||
import { getIndexSqlitePath } from "../util/paths";
|
||||
import type {
|
||||
import { IndexTag, IndexingProgressUpdate } from "../index.js";
|
||||
import { getIndexSqlitePath } from "../util/paths.js";
|
||||
import {
|
||||
CodebaseIndex,
|
||||
IndexResultType,
|
||||
LastModifiedMap,
|
||||
MarkCompleteCallback,
|
||||
PathAndCacheKey,
|
||||
RefreshIndexResults,
|
||||
} from "./types";
|
||||
} from "./types.js";
|
||||
|
||||
export type DatabaseConnection = Database<sqlite3.Database>;
|
||||
|
||||
|
|
@ -356,7 +356,7 @@ export class GlobalCacheCodeBaseIndex implements CodebaseIndex {
|
|||
return this.deleteOrRemoveTag(cacheKey, tag);
|
||||
}),
|
||||
]);
|
||||
yield { progress: 1, desc: "Done updating global cache" };
|
||||
yield { progress: 1, desc: "Done updating global cache", status: "done" };
|
||||
}
|
||||
|
||||
private async computeOrAddTag(
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue