* ✨ tab autocomplete attempt 1 * 🚧 WIP autocomplete * 🚧 wip * 🔧 config for tab autocomplete * ⚡️ caching for autocomplete * 🚧 external snippet formatting * 🎨 stuff * stuff * ⚡️ debouncing and other improvements * ⚡️ use LSP to get definition during function call * 💄 status bar for Continue tab-autocomplete * 🐛 small status bar fix * 📝 basic docs for tab-autocomplete * 📝 h2 in docs * 🚸 Explain how to download Ollama and Deepseek Coder * 📝 autocomplete troubleshooting
133 lines
3.9 KiB
TypeScript
133 lines
3.9 KiB
TypeScript
import {
|
|
Config,
|
|
ContextProviderWithParams,
|
|
ContinueConfig,
|
|
CustomContextProvider,
|
|
CustomLLM,
|
|
EmbeddingsProviderDescription,
|
|
IContextProvider,
|
|
ModelDescription,
|
|
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 { AllEmbeddingsProviders } from "../indexing/embeddings";
|
|
import TransformersJsEmbeddingsProvider from "../indexing/embeddings/TransformersJsEmbeddingsProvider";
|
|
import { BaseLLM } from "../llm";
|
|
import { llmFromDescription } from "../llm/llms";
|
|
import CustomLLMClass from "../llm/llms/CustomLLM";
|
|
|
|
function serializedToIntermediateConfig(
|
|
initial: SerializedContinueConfig
|
|
): Config {
|
|
const slashCommands: SlashCommand[] = [];
|
|
for (const command of initial.slashCommands || []) {
|
|
const newCommand = slashCommandFromDescription(command);
|
|
if (newCommand) {
|
|
slashCommands.push(newCommand);
|
|
}
|
|
}
|
|
for (const command of initial.customCommands || []) {
|
|
slashCommands.push(slashFromCustomCommand(command));
|
|
}
|
|
|
|
const config: Config = {
|
|
...initial,
|
|
slashCommands,
|
|
contextProviders: initial.contextProviders || [],
|
|
};
|
|
|
|
return config;
|
|
}
|
|
|
|
function isModelDescription(
|
|
llm: ModelDescription | CustomLLM
|
|
): llm is ModelDescription {
|
|
return (llm as ModelDescription).title !== undefined;
|
|
}
|
|
|
|
function isContextProviderWithParams(
|
|
contextProvider: CustomContextProvider | ContextProviderWithParams
|
|
): contextProvider is ContextProviderWithParams {
|
|
return (contextProvider as ContextProviderWithParams).name !== undefined;
|
|
}
|
|
|
|
/** Only difference between intermediate and final configs is the `models` array */
|
|
async function intermediateToFinalConfig(
|
|
config: Config,
|
|
readFile: (filepath: string) => Promise<string>
|
|
): Promise<ContinueConfig> {
|
|
const models: BaseLLM[] = [];
|
|
for (const desc of config.models) {
|
|
let llm: BaseLLM | undefined;
|
|
if (isModelDescription(desc)) {
|
|
llm = await llmFromDescription(
|
|
desc,
|
|
readFile,
|
|
config.completionOptions,
|
|
config.systemMessage
|
|
);
|
|
} else {
|
|
llm = new CustomLLMClass(desc);
|
|
}
|
|
if (!llm) continue;
|
|
models.push(llm);
|
|
}
|
|
|
|
let autocompleteLlm: BaseLLM | undefined = undefined;
|
|
if (config.tabAutocompleteModel) {
|
|
if (isModelDescription(config.tabAutocompleteModel)) {
|
|
autocompleteLlm = await llmFromDescription(
|
|
config.tabAutocompleteModel,
|
|
readFile,
|
|
config.completionOptions,
|
|
config.systemMessage
|
|
);
|
|
} else {
|
|
autocompleteLlm = new CustomLLMClass(config.tabAutocompleteModel);
|
|
}
|
|
}
|
|
|
|
const contextProviders: IContextProvider[] = [new FileContextProvider({})];
|
|
for (const provider of config.contextProviders || []) {
|
|
if (isContextProviderWithParams(provider)) {
|
|
const cls = contextProviderClassFromName(provider.name) as any;
|
|
if (!cls) {
|
|
console.warn(`Unknown context provider ${provider.name}`);
|
|
continue;
|
|
}
|
|
contextProviders.push(new cls(provider.params));
|
|
} else {
|
|
contextProviders.push(new CustomContextProviderClass(provider));
|
|
}
|
|
}
|
|
|
|
if (
|
|
(config.embeddingsProvider as EmbeddingsProviderDescription | undefined)
|
|
?.provider
|
|
) {
|
|
const { provider, ...options } =
|
|
config.embeddingsProvider as EmbeddingsProviderDescription;
|
|
config.embeddingsProvider = new AllEmbeddingsProviders[provider](options);
|
|
}
|
|
|
|
if (!config.embeddingsProvider) {
|
|
config.embeddingsProvider = new TransformersJsEmbeddingsProvider();
|
|
}
|
|
|
|
return {
|
|
...config,
|
|
contextProviders,
|
|
models,
|
|
embeddingsProvider: config.embeddingsProvider as any,
|
|
tabAutocompleteModel: autocompleteLlm,
|
|
};
|
|
}
|
|
|
|
export { intermediateToFinalConfig, serializedToIntermediateConfig };
|