✨ switch between autocomplete models
This commit is contained in:
parent
d6a3b48a60
commit
894e1a3ffb
15 changed files with 199 additions and 54 deletions
|
|
@ -293,26 +293,36 @@ async function intermediateToFinalConfig(
|
|||
}
|
||||
|
||||
// Tab autocomplete model
|
||||
let autocompleteLlm: BaseLLM | undefined = undefined;
|
||||
let tabAutocompleteModels: BaseLLM[] = [];
|
||||
if (config.tabAutocompleteModel) {
|
||||
if (isModelDescription(config.tabAutocompleteModel)) {
|
||||
autocompleteLlm = await llmFromDescription(
|
||||
config.tabAutocompleteModel,
|
||||
ide.readFile.bind(ide),
|
||||
uniqueId,
|
||||
ideSettings,
|
||||
writeLog,
|
||||
config.completionOptions,
|
||||
config.systemMessage,
|
||||
);
|
||||
tabAutocompleteModels = (
|
||||
await Promise.all(
|
||||
(Array.isArray(config.tabAutocompleteModel)
|
||||
? config.tabAutocompleteModel
|
||||
: [config.tabAutocompleteModel]
|
||||
).map(async (desc) => {
|
||||
if (isModelDescription(desc)) {
|
||||
const llm = await llmFromDescription(
|
||||
desc,
|
||||
ide.readFile.bind(ide),
|
||||
uniqueId,
|
||||
ideSettings,
|
||||
writeLog,
|
||||
config.completionOptions,
|
||||
config.systemMessage,
|
||||
);
|
||||
|
||||
if (autocompleteLlm?.providerName === "free-trial") {
|
||||
const ghAuthToken = await ide.getGitHubAuthToken();
|
||||
(autocompleteLlm as FreeTrial).setupGhAuthToken(ghAuthToken);
|
||||
}
|
||||
} else {
|
||||
autocompleteLlm = new CustomLLMClass(config.tabAutocompleteModel);
|
||||
}
|
||||
if (llm?.providerName === "free-trial") {
|
||||
const ghAuthToken = await ide.getGitHubAuthToken();
|
||||
(llm as FreeTrial).setupGhAuthToken(ghAuthToken);
|
||||
}
|
||||
return llm;
|
||||
} else {
|
||||
return new CustomLLMClass(desc);
|
||||
}
|
||||
}),
|
||||
)
|
||||
).filter((x) => x !== undefined) as BaseLLM[];
|
||||
}
|
||||
|
||||
// Context providers
|
||||
|
|
@ -381,7 +391,7 @@ async function intermediateToFinalConfig(
|
|||
contextProviders,
|
||||
models,
|
||||
embeddingsProvider: config.embeddingsProvider as any,
|
||||
tabAutocompleteModel: autocompleteLlm,
|
||||
tabAutocompleteModels,
|
||||
reranker: config.reranker as any,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
34
core/core.ts
34
core/core.ts
|
|
@ -1,12 +1,10 @@
|
|||
import { v4 as uuidv4 } from "uuid";
|
||||
import type {
|
||||
ContextItemId,
|
||||
IDE,
|
||||
IndexingProgressUpdate,
|
||||
SiteIndexingConfig,
|
||||
} from ".";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import type { IMessenger, Message } from "./util/messenger";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
import { CompletionProvider } from "./autocomplete/completionProvider.js";
|
||||
import { ConfigHandler } from "./config/handler.js";
|
||||
import {
|
||||
|
|
@ -22,11 +20,13 @@ import { indexDocs } from "./indexing/docs/index.js";
|
|||
import TransformersJsEmbeddingsProvider from "./indexing/embeddings/TransformersJsEmbeddingsProvider.js";
|
||||
import { CodebaseIndexer, PauseToken } from "./indexing/indexCodebase.js";
|
||||
import Ollama from "./llm/llms/Ollama.js";
|
||||
import type { FromCoreProtocol, ToCoreProtocol } from "./protocol";
|
||||
import { GlobalContext } from "./util/GlobalContext.js";
|
||||
import { logDevData } from "./util/devdata.js";
|
||||
import { DevDataSqliteDb } from "./util/devdataSqlite.js";
|
||||
import { fetchwithRequestOptions } from "./util/fetchWithOptions.js";
|
||||
import historyManager from "./util/history.js";
|
||||
import type { IMessenger, Message } from "./util/messenger";
|
||||
import { editConfigJson, getConfigJsonPath } from "./util/paths.js";
|
||||
import { Telemetry } from "./util/posthog.js";
|
||||
import { streamDiffLines } from "./util/verticalEdit.js";
|
||||
|
|
@ -38,6 +38,7 @@ export class Core {
|
|||
completionProvider: CompletionProvider;
|
||||
continueServerClientPromise: Promise<ContinueServerClient>;
|
||||
indexingState: IndexingProgressUpdate;
|
||||
private globalContext = new GlobalContext();
|
||||
|
||||
private abortedMessageIds: Set<string> = new Set();
|
||||
|
||||
|
|
@ -78,7 +79,7 @@ export class Core {
|
|||
|
||||
// Codebase Indexer and ContinueServerClient depend on IdeSettings
|
||||
const indexingPauseToken = new PauseToken(
|
||||
new GlobalContext().get("indexingPaused") === true,
|
||||
this.globalContext.get("indexingPaused") === true,
|
||||
);
|
||||
let codebaseIndexerResolve: (_: any) => void | undefined;
|
||||
this.codebaseIndexerPromise = new Promise(
|
||||
|
|
@ -112,7 +113,12 @@ export class Core {
|
|||
|
||||
const getLlm = async () => {
|
||||
const config = await this.configHandler.loadConfig();
|
||||
return config.tabAutocompleteModel;
|
||||
const selected = this.globalContext.get("selectedTabAutocompleteModel");
|
||||
return (
|
||||
config.tabAutocompleteModels?.find(
|
||||
(model) => model.title === selected,
|
||||
) ?? config.tabAutocompleteModels?.[0]
|
||||
);
|
||||
};
|
||||
this.completionProvider = new CompletionProvider(
|
||||
this.configHandler,
|
||||
|
|
@ -134,6 +140,11 @@ export class Core {
|
|||
this.selectedModelTitle = msg.data;
|
||||
});
|
||||
|
||||
on("update/selectTabAutocompleteModel", async (msg) => {
|
||||
this.globalContext.update("selectedTabAutocompleteModel", msg.data);
|
||||
this.configHandler.reloadConfig();
|
||||
});
|
||||
|
||||
// Special
|
||||
on("abort", (msg) => {
|
||||
this.abortedMessageIds.add(msg.messageId);
|
||||
|
|
@ -223,6 +234,7 @@ export class Core {
|
|||
rootUrl: msg.data.rootUrl,
|
||||
title: msg.data.title,
|
||||
maxDepth: msg.data.maxDepth,
|
||||
faviconUrl: new URL("/favicon.ico", msg.data.rootUrl).toString(),
|
||||
};
|
||||
|
||||
for await (const _ of indexDocs(
|
||||
|
|
@ -498,12 +510,12 @@ export class Core {
|
|||
mode === "local"
|
||||
? setupLocalMode
|
||||
: mode === "freeTrial"
|
||||
? setupFreeTrialMode
|
||||
: mode === "localAfterFreeTrial"
|
||||
? setupLocalAfterFreeTrial
|
||||
: mode === "apiKeys"
|
||||
? setupApiKeysMode
|
||||
: setupOptimizedExistingUserMode,
|
||||
? setupFreeTrialMode
|
||||
: mode === "localAfterFreeTrial"
|
||||
? setupLocalAfterFreeTrial
|
||||
: mode === "apiKeys"
|
||||
? setupApiKeysMode
|
||||
: setupOptimizedExistingUserMode,
|
||||
);
|
||||
this.configHandler.reloadConfig();
|
||||
});
|
||||
|
|
|
|||
11
core/index.d.ts
vendored
11
core/index.d.ts
vendored
|
|
@ -160,6 +160,7 @@ export interface ContextSubmenuItem {
|
|||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
iconUrl?: string;
|
||||
}
|
||||
|
||||
export interface SiteIndexingConfig {
|
||||
|
|
@ -167,6 +168,7 @@ export interface SiteIndexingConfig {
|
|||
rootUrl: string;
|
||||
title: string;
|
||||
maxDepth?: number;
|
||||
faviconUrl: string;
|
||||
}
|
||||
|
||||
export interface IContextProvider {
|
||||
|
|
@ -782,7 +784,7 @@ export interface SerializedContinueConfig {
|
|||
disableSessionTitles?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider?: EmbeddingsProviderDescription;
|
||||
tabAutocompleteModel?: ModelDescription;
|
||||
tabAutocompleteModel?: ModelDescription | ModelDescription[];
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
ui?: ContinueUIConfig;
|
||||
reranker?: RerankerDescription;
|
||||
|
|
@ -824,7 +826,10 @@ export interface Config {
|
|||
/** The provider used to calculate embeddings. If left empty, Continue will use transformers.js to calculate the embeddings with all-MiniLM-L6-v2 */
|
||||
embeddingsProvider?: EmbeddingsProviderDescription | EmbeddingsProvider;
|
||||
/** The model that Continue will use for tab autocompletions. */
|
||||
tabAutocompleteModel?: CustomLLM | ModelDescription;
|
||||
tabAutocompleteModel?:
|
||||
| CustomLLM
|
||||
| ModelDescription
|
||||
| (CustomLLM | ModelDescription)[];
|
||||
/** Options for tab autocomplete */
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
/** UI styles customization */
|
||||
|
|
@ -847,7 +852,7 @@ export interface ContinueConfig {
|
|||
disableIndexing?: boolean;
|
||||
userToken?: string;
|
||||
embeddingsProvider: EmbeddingsProvider;
|
||||
tabAutocompleteModel?: ILLM;
|
||||
tabAutocompleteModels?: ILLM[];
|
||||
tabAutocompleteOptions?: Partial<TabAutocompleteOptions>;
|
||||
ui?: ContinueUIConfig;
|
||||
reranker?: Reranker;
|
||||
|
|
|
|||
|
|
@ -27,8 +27,8 @@ export interface ListHistoryOptions {
|
|||
}
|
||||
|
||||
export type ToCoreFromIdeOrWebviewProtocol = {
|
||||
// New
|
||||
"update/modelChange": [string, void];
|
||||
"update/selectTabAutocompleteModel": [string, void];
|
||||
|
||||
// Special
|
||||
ping: [string, string];
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { getGlobalContextFilePath } from "./paths.js";
|
|||
|
||||
export type GlobalContextType = {
|
||||
indexingPaused: boolean;
|
||||
selectedTabAutocompleteModel: string;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
|||
12
docs/static/schemas/config.json
vendored
12
docs/static/schemas/config.json
vendored
|
|
@ -1999,7 +1999,17 @@
|
|||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteOptions": {
|
||||
"title": "TabAutocompleteOptions",
|
||||
|
|
|
|||
|
|
@ -1999,7 +1999,17 @@
|
|||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteOptions": {
|
||||
"title": "TabAutocompleteOptions",
|
||||
|
|
|
|||
|
|
@ -1999,7 +1999,17 @@
|
|||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteOptions": {
|
||||
"title": "TabAutocompleteOptions",
|
||||
|
|
|
|||
|
|
@ -2248,7 +2248,17 @@
|
|||
"provider": "ollama",
|
||||
"model": "deepseek-coder:1.3b-base"
|
||||
},
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
"oneOf": [
|
||||
{
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
},
|
||||
{
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/ModelDescription"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"tabAutocompleteOptions": {
|
||||
"title": "TabAutocompleteOptions",
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ export function setupStatusBar(
|
|||
? "$(loading~spin) Continue"
|
||||
: statusBarItemText(enabled);
|
||||
statusBarItem.tooltip = statusBarItemTooltip(enabled);
|
||||
statusBarItem.command = "continue.toggleTabAutocompleteEnabled";
|
||||
statusBarItem.command = "continue.openTabAutocompleteConfigMenu";
|
||||
|
||||
statusBarItem.show();
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { ContextMenuConfig, IDE } from "core";
|
|||
import { CompletionProvider } from "core/autocomplete/completionProvider";
|
||||
import { ConfigHandler } from "core/config/handler";
|
||||
import { fetchwithRequestOptions } from "core/util/fetchWithOptions";
|
||||
import { GlobalContext } from "core/util/GlobalContext";
|
||||
import { getConfigJsonPath } from "core/util/paths";
|
||||
import { ContinueGUIWebviewViewProvider } from "./debugPanel";
|
||||
import { DiffManager } from "./diff/horizontal";
|
||||
|
|
@ -532,6 +533,63 @@ const commandsMap: (
|
|||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
},
|
||||
"continue.openTabAutocompleteConfigMenu": async () => {
|
||||
const config = vscode.workspace.getConfiguration("continue");
|
||||
const enabled = config.get("enableTabAutocomplete");
|
||||
const quickPick = vscode.window.createQuickPick();
|
||||
const selected = new GlobalContext().get("selectedTabAutocompleteModel");
|
||||
const autocompleteModelTitles = ((
|
||||
await configHandler.loadConfig()
|
||||
).tabAutocompleteModels
|
||||
?.map((model) => model.title)
|
||||
.filter((t) => t !== undefined) || []) as string[];
|
||||
quickPick.items = [
|
||||
{
|
||||
label: enabled
|
||||
? "$(check) Disable autocomplete"
|
||||
: "$(circle-slash) Enable autocomplete",
|
||||
},
|
||||
{
|
||||
label: "$(gear) Configure autocomplete options",
|
||||
},
|
||||
{
|
||||
kind: vscode.QuickPickItemKind.Separator,
|
||||
label: "Switch model",
|
||||
},
|
||||
...autocompleteModelTitles.map((title) => ({
|
||||
label: title === selected ? `$(check) ${title}` : title,
|
||||
description: title === selected ? "Currently selected" : undefined,
|
||||
})),
|
||||
];
|
||||
quickPick.onDidAccept(() => {
|
||||
const selectedOption = quickPick.selectedItems[0].label;
|
||||
if (selectedOption === "$(circle-slash) Enable autocomplete") {
|
||||
config.update(
|
||||
"enableTabAutocomplete",
|
||||
true,
|
||||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
} else if (selectedOption === "$(check) Disable autocomplete") {
|
||||
config.update(
|
||||
"enableTabAutocomplete",
|
||||
false,
|
||||
vscode.ConfigurationTarget.Global,
|
||||
);
|
||||
} else if (
|
||||
selectedOption === "$(gear) Configure autocomplete options"
|
||||
) {
|
||||
ide.openFile(getConfigJsonPath());
|
||||
} else if (autocompleteModelTitles.includes(selectedOption)) {
|
||||
new GlobalContext().update(
|
||||
"selectedTabAutocompleteModel",
|
||||
selectedOption,
|
||||
);
|
||||
configHandler.reloadConfig();
|
||||
}
|
||||
quickPick.dispose();
|
||||
});
|
||||
quickPick.show();
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -165,13 +165,15 @@ export class VsCodeExtension {
|
|||
// from outside the window are also caught
|
||||
fs.watchFile(getConfigJsonPath(), { interval: 1000 }, (stats) => {
|
||||
this.configHandler.reloadConfig();
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
});
|
||||
fs.watchFile(getConfigTsPath(), { interval: 1000 }, (stats) => {
|
||||
this.configHandler.reloadConfig();
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
});
|
||||
|
||||
this.configHandler.onConfigUpdate(
|
||||
this.tabAutocompleteModel.clearLlm.bind(this.tabAutocompleteModel),
|
||||
);
|
||||
|
||||
vscode.workspace.onDidSaveTextDocument((event) => {
|
||||
// Listen for file changes in the workspace
|
||||
const filepath = event.uri.fsPath;
|
||||
|
|
@ -181,7 +183,6 @@ export class VsCodeExtension {
|
|||
filepath.endsWith(".prompt")
|
||||
) {
|
||||
this.configHandler.reloadConfig();
|
||||
this.tabAutocompleteModel.clearLlm();
|
||||
} else if (
|
||||
filepath.endsWith(".continueignore") ||
|
||||
filepath.endsWith(".gitignore")
|
||||
|
|
|
|||
|
|
@ -83,10 +83,17 @@ class VsCodeIde implements IDE {
|
|||
|
||||
// Remove free trial models
|
||||
editConfigJson((config) => {
|
||||
const tabAutocompleteModel =
|
||||
let tabAutocompleteModel = undefined;
|
||||
if (Array.isArray(config.tabAutocompleteModel)) {
|
||||
tabAutocompleteModel = config.tabAutocompleteModel.filter(
|
||||
(model) => model.provider !== "free-trial",
|
||||
);
|
||||
} else if (
|
||||
config.tabAutocompleteModel?.provider === "free-trial"
|
||||
? undefined
|
||||
: config.tabAutocompleteModel;
|
||||
) {
|
||||
tabAutocompleteModel = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
...config,
|
||||
models: config.models.filter(
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import type { ILLM } from "core";
|
||||
import type { ConfigHandler } from "core/config/handler";
|
||||
import Ollama from "core/llm/llms/Ollama";
|
||||
import { GlobalContext } from "core/util/GlobalContext";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
export class TabAutocompleteModel {
|
||||
private _llm: ILLM | undefined;
|
||||
private defaultTag = "starcoder2:3b";
|
||||
private defaultTagName = "Starcoder2 3b";
|
||||
private globalContext: GlobalContext = new GlobalContext();
|
||||
|
||||
private shownOllamaWarning = false;
|
||||
private shownDeepseekWarning = false;
|
||||
|
|
@ -81,8 +83,22 @@ export class TabAutocompleteModel {
|
|||
async get() {
|
||||
if (!this._llm) {
|
||||
const config = await this.configHandler.loadConfig();
|
||||
if (config.tabAutocompleteModel) {
|
||||
this._llm = config.tabAutocompleteModel;
|
||||
if (config.tabAutocompleteModels?.length) {
|
||||
const selected = this.globalContext.get("selectedTabAutocompleteModel");
|
||||
if (selected) {
|
||||
this._llm =
|
||||
config.tabAutocompleteModels?.find(
|
||||
(model) => model.title === selected,
|
||||
) ?? config.tabAutocompleteModels?.[0];
|
||||
} else {
|
||||
if (config.tabAutocompleteModels[0].title) {
|
||||
this.globalContext.update(
|
||||
"selectedTabAutocompleteModel",
|
||||
config.tabAutocompleteModels[0].title,
|
||||
);
|
||||
}
|
||||
this._llm = config.tabAutocompleteModels[0];
|
||||
}
|
||||
} else {
|
||||
this._llm = await this.getDefaultTabAutocompleteModel();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,13 +15,8 @@ const GridDiv = styled.div`
|
|||
`;
|
||||
|
||||
export const ftl = () => {
|
||||
const ftc = parseInt(localStorage.getItem("ftc"));
|
||||
if (ftc && ftc > 52) {
|
||||
return 100;
|
||||
} else if (ftc && ftc > 27) {
|
||||
return 50;
|
||||
}
|
||||
return 25;
|
||||
// const ftc = parseInt(localStorage.getItem("ftc"));
|
||||
return 50;
|
||||
};
|
||||
|
||||
function FTCDialog() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue