more refactoring
This commit is contained in:
parent
3e1eca6c88
commit
176c50210d
20 changed files with 57 additions and 134 deletions
|
|
@ -8,16 +8,16 @@ import { postprocessCompletion } from "./postprocessing/index.js";
|
|||
// @prettier-ignore
|
||||
import { TRIAL_FIM_MODEL } from "../config/onboarding.js";
|
||||
import OpenAI from "../llm/llms/OpenAI.js";
|
||||
import { AutocompleteDebouncer } from "./AutocompleteDebouncer.js";
|
||||
import { AutocompleteLoggingService } from "./AutocompleteLoggingService.js";
|
||||
import AutocompleteLruCache from "./AutocompleteLruCache.js";
|
||||
import { ContextRetrievalService } from "./context/ContextRetrievalService.js";
|
||||
import { BracketMatchingService } from "./filtering/BracketMatchingService.js";
|
||||
import { CompletionStreamer } from "./generation/CompletionStreamer.js";
|
||||
import { HelperVars } from "./HelperVars.js";
|
||||
import { shouldPrefilter } from "./prefiltering/index.js";
|
||||
import { renderPrompt } from "./templating/index.js";
|
||||
import { AutocompleteInput, AutocompleteOutcome } from "./types.js";
|
||||
import { AutocompleteDebouncer } from "./util/AutocompleteDebouncer.js";
|
||||
import { AutocompleteLoggingService } from "./util/AutocompleteLoggingService.js";
|
||||
import AutocompleteLruCache from "./util/AutocompleteLruCache.js";
|
||||
import { HelperVars } from "./util/HelperVars.js";
|
||||
import { AutocompleteInput, AutocompleteOutcome } from "./util/types.js";
|
||||
|
||||
const autocompleteCache = AutocompleteLruCache.get();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
# Autocomplete
|
||||
|
||||
The autocomplete pipeline:
|
||||
|
||||
## 1. Triggering
|
||||
|
||||
### Debouncing
|
||||
|
||||
## 2. Context gathering
|
||||
|
||||
## 3. Prompt construction
|
||||
|
||||
This is fairly trivial, we just use the correct template/endpoint for the model. Any templates are defined in [`templates.ts`](./templates.ts).
|
||||
|
||||
## 4. Caching
|
||||
|
||||
## 4. Generation
|
||||
|
||||
### Reusing previous requests
|
||||
|
||||
## 4. Classification
|
||||
|
||||
Is it multi-line or single-line?
|
||||
|
||||
## 4. Filtering
|
||||
|
||||
## 5. Postprocessing
|
||||
|
||||
## 6. Telemetry
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo";
|
||||
import { HelperVars } from "../HelperVars";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
||||
function isMidlineCompletion(prefix: string, suffix: string): boolean {
|
||||
return !suffix.startsWith("\n");
|
||||
|
|
@ -14,7 +14,7 @@ function shouldCompleteMultilineBasedOnLanguage(
|
|||
return langMultilineDecision;
|
||||
}
|
||||
|
||||
export function decideMultilineEarly(
|
||||
export function shouldCompleteMultiline(
|
||||
helper: HelperVars,
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
|
|
@ -28,6 +28,11 @@ export function decideMultilineEarly(
|
|||
break;
|
||||
}
|
||||
|
||||
// Always single-line if an intellisense option is selected
|
||||
if (helper.input.selectedCompletionInfo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Don't complete multi-line if you are mid-line
|
||||
if (isMidlineCompletion(helper.fullPrefix, helper.fullSuffix)) {
|
||||
return false;
|
||||
|
|
@ -48,9 +53,5 @@ export function decideMultilineEarly(
|
|||
return true;
|
||||
}
|
||||
|
||||
if (helper.input.selectedCompletionInfo) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ import {
|
|||
removeRangeFromSnippets,
|
||||
type AutocompleteSnippet,
|
||||
} from "./context/ranking/index.js";
|
||||
import { HelperVars } from "./HelperVars.js";
|
||||
import { HelperVars } from "./util/HelperVars.js";
|
||||
|
||||
function prunePrefixSuffix(helper: HelperVars) {
|
||||
// Construct basic prefix
|
||||
|
|
|
|||
|
|
@ -1,10 +1,21 @@
|
|||
import { IDE } from "../..";
|
||||
import { HelperVars } from "../HelperVars";
|
||||
import { findMatchingRange } from "../recentlyEdited";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
import { RecentlyEditedRange } from "../util/types";
|
||||
import { ImportDefinitionsService } from "./ImportDefinitionsService";
|
||||
import { AutocompleteSnippet, getSymbolsForSnippet } from "./ranking";
|
||||
import { RootPathContextService } from "./RootPathContextService";
|
||||
|
||||
export function findMatchingRange(
|
||||
recentlyEditedRanges: RecentlyEditedRange[],
|
||||
linePrefix: string,
|
||||
): RecentlyEditedRange | undefined {
|
||||
return recentlyEditedRanges.find((recentlyEditedRange) => {
|
||||
return recentlyEditedRange.lines.some((line) =>
|
||||
line.startsWith(linePrefix),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export class ContextRetrievalService {
|
||||
private importDefinitionsService: ImportDefinitionsService;
|
||||
private rootPathContextService: RootPathContextService;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { RangeInFileWithContents } from "../../../commands/util.js";
|
||||
import { Range } from "../../../index.js";
|
||||
import { countTokens } from "../../../llm/countTokens.js";
|
||||
import { HelperVars } from "../../HelperVars.js";
|
||||
import { HelperVars } from "../../util/HelperVars.js";
|
||||
|
||||
export type AutocompleteSnippet = RangeInFileWithContents & {
|
||||
score?: number;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import path from "node:path";
|
|||
import Mock from "../../../llm/llms/Mock";
|
||||
import { testConfigHandler, testIde } from "../../../test/util/fixtures";
|
||||
import { CompletionProvider } from "../../CompletionProvider";
|
||||
import { AutocompleteInput } from "../../types";
|
||||
import { AutocompleteInput } from "../../util/types";
|
||||
|
||||
const FIM_DELIMITER = "<|fim|>";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { CompletionOptions, ILLM } from "../..";
|
||||
import { StreamTransformPipeline } from "../filtering/streamTransforms/StreamTransformPipeline";
|
||||
import { HelperVars } from "../HelperVars";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
import { GeneratorReuseManager } from "./GeneratorReuseManager";
|
||||
|
||||
export class CompletionStreamer {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import path from "node:path";
|
|||
import { IDE } from "../..";
|
||||
import { getBasename } from "../../util";
|
||||
import { getConfigJsonPath } from "../../util/paths";
|
||||
import { HelperVars } from "../HelperVars";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
|
||||
async function isDisabledForFile(
|
||||
currentFilepath: string,
|
||||
|
|
|
|||
|
|
@ -1,18 +0,0 @@
|
|||
import { RangeInFile } from "../index.js";
|
||||
|
||||
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),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ import { IDE } from "../..";
|
|||
import { getRangeInString } from "../../util/ranges";
|
||||
import { languageForFilepath } from "../constants/AutocompleteLanguageInfo";
|
||||
|
||||
import { AutocompleteInput } from "../types";
|
||||
import { AutocompleteInput } from "../util/types";
|
||||
|
||||
/**
|
||||
* We have to handle a few edge cases in getting the entire prefix/suffix for the current file.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import { CompletionOptions } from "../..";
|
||||
import { getBasename, getLastNPathParts } from "../../util";
|
||||
import { decideMultilineEarly as shouldCompleteMultiline } from "../classification/shouldCompleteMultiline";
|
||||
import { shouldCompleteMultiline } from "../classification/shouldCompleteMultiline";
|
||||
import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo";
|
||||
import { AutocompleteSnippet } from "../context/ranking";
|
||||
import { HelperVars } from "../HelperVars";
|
||||
import { HelperVars } from "../util/HelperVars";
|
||||
import { getTemplateForModel } from "./AutocompleteTemplate";
|
||||
import { getStopTokens } from "./getStopTokens";
|
||||
|
||||
|
|
@ -60,6 +60,7 @@ function renderStringTemplate(
|
|||
});
|
||||
return prompt;
|
||||
}
|
||||
|
||||
export function renderPrompt(
|
||||
prefix: string,
|
||||
suffix: string,
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
##### Prompt #####
|
||||
class Calculator {
|
||||
constructor() {
|
||||
this.result = 0;
|
||||
}
|
||||
|
||||
add(number) {
|
||||
this.result += number;
|
||||
return this;
|
||||
}
|
||||
|
||||
subtract(number) {
|
||||
this.result -= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
multiply(number) {
|
||||
this.result *= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
divide(number) {
|
||||
if (number === 0) {
|
||||
throw new Error("Cannot divide by zero");
|
||||
}
|
||||
|
||||
<FIM>
|
||||
|
||||
this.result /= number;
|
||||
return this;
|
||||
}
|
||||
|
||||
getResult() {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.result = 0;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
==========================================================================
|
||||
==========================================================================
|
||||
Completion:
|
||||
|
||||
this.result /= number;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
|
|
@ -3,7 +3,7 @@ import path from "node:path";
|
|||
import Mock from "../../llm/llms/Mock";
|
||||
import { testConfigHandler, testIde } from "../../test/util/fixtures";
|
||||
import { CompletionProvider } from "../CompletionProvider";
|
||||
import { AutocompleteInput } from "../types";
|
||||
import { AutocompleteInput } from "../util/types";
|
||||
|
||||
const FIM_DELIMITER = "<|fim|>";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { logDevData } from "../util/devdata";
|
||||
import { COUNT_COMPLETION_REJECTED_AFTER } from "../util/parameters";
|
||||
import { Telemetry } from "../util/posthog";
|
||||
import { logDevData } from "../../util/devdata";
|
||||
import { COUNT_COMPLETION_REJECTED_AFTER } from "../../util/parameters";
|
||||
import { Telemetry } from "../../util/posthog";
|
||||
import { AutocompleteOutcome } from "./types";
|
||||
|
||||
export class AutocompleteLoggingService {
|
||||
|
|
@ -1,14 +1,17 @@
|
|||
import { Mutex } from "async-mutex";
|
||||
import { open } from "sqlite";
|
||||
import sqlite3 from "sqlite3";
|
||||
import { DatabaseConnection, truncateSqliteLikePattern } from "../indexing/refreshIndex.js";
|
||||
import { getTabAutocompleteCacheSqlitePath } from "../util/paths.js";
|
||||
import {
|
||||
DatabaseConnection,
|
||||
truncateSqliteLikePattern,
|
||||
} from "../../indexing/refreshIndex.js";
|
||||
import { getTabAutocompleteCacheSqlitePath } from "../../util/paths.js";
|
||||
|
||||
export class AutocompleteLruCache {
|
||||
private static capacity = 1000;
|
||||
private mutex = new Mutex();
|
||||
|
||||
constructor(private db: DatabaseConnection) { }
|
||||
constructor(private db: DatabaseConnection) {}
|
||||
|
||||
static async get(): Promise<AutocompleteLruCache> {
|
||||
const db = await open({
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
import { IDE, TabAutocompleteOptions } from "..";
|
||||
import { IDE, TabAutocompleteOptions } from "../..";
|
||||
import {
|
||||
AutocompleteLanguageInfo,
|
||||
languageForFilepath,
|
||||
} from "./constants/AutocompleteLanguageInfo";
|
||||
import { constructInitialPrefixSuffix } from "./templating/constructPrefixSuffix";
|
||||
} from "../constants/AutocompleteLanguageInfo";
|
||||
import { constructInitialPrefixSuffix } from "../templating/constructPrefixSuffix";
|
||||
import { AstPath, getAst, getTreePathAtCursor } from "./ast";
|
||||
import { AutocompleteInput } from "./types";
|
||||
import { AstPath, getAst, getTreePathAtCursor } from "./util/ast";
|
||||
|
||||
/**
|
||||
* A collection of variables that are often accessed throughout the autocomplete pipeline
|
||||
|
|
@ -1,6 +1,11 @@
|
|||
import { Position, Range, TabAutocompleteOptions } from "..";
|
||||
import { RangeInFileWithContents } from "../commands/util";
|
||||
import { RecentlyEditedRange } from "./recentlyEdited";
|
||||
import { Position, Range, RangeInFile, TabAutocompleteOptions } from "../..";
|
||||
import { RangeInFileWithContents } from "../../commands/util";
|
||||
|
||||
export type RecentlyEditedRange = RangeInFile & {
|
||||
timestamp: number;
|
||||
lines: string[];
|
||||
symbols: Set<string>;
|
||||
};
|
||||
|
||||
export interface AutocompleteInput {
|
||||
completionId: string;
|
||||
|
|
@ -15,7 +15,7 @@ import type {
|
|||
SessionInfo,
|
||||
SiteIndexingConfig,
|
||||
} from "../";
|
||||
import { AutocompleteInput } from "../autocomplete/types";
|
||||
import { AutocompleteInput } from "../autocomplete/util/types";
|
||||
import { ProfileDescription } from "../config/ConfigHandler";
|
||||
|
||||
export type ProtocolGeneratorType<T> = AsyncGenerator<{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue