🚧 only pass serialized config to the browser
This commit is contained in:
parent
95c0a59ce7
commit
b42e7d64fb
20 changed files with 410 additions and 375 deletions
|
|
@ -2,6 +2,7 @@ import * as fs from "fs";
|
|||
import {
|
||||
BaseCompletionOptions,
|
||||
Config,
|
||||
ContextProviderDescription,
|
||||
ContextProviderWithParams,
|
||||
ContinueConfig,
|
||||
CustomContextProvider,
|
||||
|
|
@ -26,6 +27,7 @@ import TransformersJsEmbeddingsProvider from "../indexing/embeddings/Transformer
|
|||
import { BaseLLM } from "../llm";
|
||||
import { llmFromDescription } from "../llm/llms";
|
||||
import CustomLLMClass from "../llm/llms/CustomLLM";
|
||||
import mergeJson from "../util/merge";
|
||||
import {
|
||||
getConfigJsPath,
|
||||
getConfigJsonPath,
|
||||
|
|
@ -218,7 +220,7 @@ interface BrowserSerializedContinueConfig {
|
|||
systemMessage?: string;
|
||||
completionOptions?: BaseCompletionOptions;
|
||||
slashCommands?: SlashCommandDescription[];
|
||||
contextProviders?: ContextProviderWithParams[];
|
||||
contextProviders?: ContextProviderDescription[];
|
||||
disableIndexing?: boolean;
|
||||
disableSessionTitles?: boolean;
|
||||
userToken?: string;
|
||||
|
|
@ -245,7 +247,11 @@ function finalToBrowserConfig(
|
|||
})),
|
||||
systemMessage: final.systemMessage,
|
||||
completionOptions: final.completionOptions,
|
||||
slashCommands: final.slashCommands?.map((m) => m.description),
|
||||
slashCommands: final.slashCommands?.map((m) => ({
|
||||
name: m.name,
|
||||
description: m.description,
|
||||
options: m.params,
|
||||
})),
|
||||
contextProviders: final.contextProviders?.map((c) => c.description),
|
||||
disableIndexing: final.disableIndexing,
|
||||
disableSessionTitles: final.disableSessionTitles,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Chunk, ContextItem, ContextProviderExtras, ILLM } from "..";
|
|||
import { FullTextSearchCodebaseIndex } from "../indexing/FullTextSearch";
|
||||
import { ChunkCodebaseIndex } from "../indexing/chunk/ChunkCodebaseIndex";
|
||||
import { IndexTag } from "../indexing/types";
|
||||
import { llmCanGenerateInParallel } from "../llm";
|
||||
import { llmCanGenerateInParallel } from "../llm/autodetect";
|
||||
import { getBasename } from "../util";
|
||||
|
||||
const RERANK_PROMPT = (
|
||||
|
|
@ -111,7 +111,7 @@ export async function retrieveContextItemsFromEmbeddings(
|
|||
|
||||
const nFinal = options?.nFinal || 10;
|
||||
const useReranking =
|
||||
llmCanGenerateInParallel(extras.llm) &&
|
||||
llmCanGenerateInParallel(extras.llm.providerName, extras.llm.model) &&
|
||||
(options?.useReranking === undefined ? false : options?.useReranking);
|
||||
const nRetrieve = useReranking === false ? nFinal : options?.nRetrieve || 20;
|
||||
|
||||
|
|
|
|||
252
core/llm/autodetect.ts
Normal file
252
core/llm/autodetect.ts
Normal file
|
|
@ -0,0 +1,252 @@
|
|||
import { ModelProvider, TemplateType } from "..";
|
||||
import {
|
||||
anthropicTemplateMessages,
|
||||
chatmlTemplateMessages,
|
||||
codeLlama70bTemplateMessages,
|
||||
deepseekTemplateMessages,
|
||||
llama2TemplateMessages,
|
||||
llavaTemplateMessages,
|
||||
neuralChatTemplateMessages,
|
||||
openchatTemplateMessages,
|
||||
phi2TemplateMessages,
|
||||
phindTemplateMessages,
|
||||
templateAlpacaMessages,
|
||||
xWinCoderTemplateMessages,
|
||||
zephyrTemplateMessages,
|
||||
} from "./templates/chat";
|
||||
import {
|
||||
alpacaEditPrompt,
|
||||
codeLlama70bEditPrompt,
|
||||
codellamaEditPrompt,
|
||||
deepseekEditPrompt,
|
||||
mistralEditPrompt,
|
||||
neuralChatEditPrompt,
|
||||
openchatEditPrompt,
|
||||
phindEditPrompt,
|
||||
simplestEditPrompt,
|
||||
simplifiedEditPrompt,
|
||||
xWinCoderEditPrompt,
|
||||
zephyrEditPrompt,
|
||||
} from "./templates/edit";
|
||||
|
||||
const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [
|
||||
"lmstudio",
|
||||
"openai",
|
||||
"ollama",
|
||||
"together",
|
||||
];
|
||||
|
||||
const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
|
||||
"openai",
|
||||
"ollama",
|
||||
"google-palm",
|
||||
"free-trial",
|
||||
];
|
||||
|
||||
function modelSupportsImages(provider: ModelProvider, model: string): boolean {
|
||||
if (!PROVIDER_SUPPORTS_IMAGES.includes(provider)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (model.includes("llava")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (["gpt-4-vision-preview"].includes(model)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
model === "gemini-ultra" &&
|
||||
(provider === "google-palm" || provider === "free-trial")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
const PARALLEL_PROVIDERS: ModelProvider[] = [
|
||||
"anthropic",
|
||||
"bedrock",
|
||||
"deepinfra",
|
||||
"gemini",
|
||||
"google-palm",
|
||||
"huggingface-inference-api",
|
||||
"huggingface-tgi",
|
||||
"mistral",
|
||||
"free-trial",
|
||||
"replicate",
|
||||
"together",
|
||||
];
|
||||
|
||||
function llmCanGenerateInParallel(
|
||||
provider: ModelProvider,
|
||||
model: string
|
||||
): boolean {
|
||||
if (provider === "openai") {
|
||||
return model.includes("gpt");
|
||||
}
|
||||
|
||||
return PARALLEL_PROVIDERS.includes(provider);
|
||||
}
|
||||
|
||||
function autodetectTemplateType(model: string): TemplateType | undefined {
|
||||
const lower = model.toLowerCase();
|
||||
|
||||
if (lower.includes("codellama") && lower.includes("70b")) {
|
||||
return "codellama-70b";
|
||||
}
|
||||
|
||||
if (
|
||||
lower.includes("gpt") ||
|
||||
lower.includes("chat-bison") ||
|
||||
lower.includes("pplx") ||
|
||||
lower.includes("gemini")
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (lower.includes("llava")) {
|
||||
return "llava";
|
||||
}
|
||||
|
||||
if (lower.includes("xwin")) {
|
||||
return "xwin-coder";
|
||||
}
|
||||
|
||||
if (lower.includes("dolphin")) {
|
||||
return "chatml";
|
||||
}
|
||||
|
||||
if (lower.includes("phi2")) {
|
||||
return "phi2";
|
||||
}
|
||||
|
||||
if (lower.includes("phind")) {
|
||||
return "phind";
|
||||
}
|
||||
|
||||
if (lower.includes("llama")) {
|
||||
return "llama2";
|
||||
}
|
||||
|
||||
if (lower.includes("zephyr")) {
|
||||
return "zephyr";
|
||||
}
|
||||
|
||||
if (lower.includes("claude")) {
|
||||
return "anthropic";
|
||||
}
|
||||
|
||||
if (lower.includes("alpaca") || lower.includes("wizard")) {
|
||||
return "alpaca";
|
||||
}
|
||||
|
||||
if (lower.includes("mistral")) {
|
||||
return "llama2";
|
||||
}
|
||||
|
||||
if (lower.includes("deepseek")) {
|
||||
return "deepseek";
|
||||
}
|
||||
|
||||
if (lower.includes("ninja") || lower.includes("openchat")) {
|
||||
return "openchat";
|
||||
}
|
||||
|
||||
if (lower.includes("neural-chat")) {
|
||||
return "neural-chat";
|
||||
}
|
||||
|
||||
return "chatml";
|
||||
}
|
||||
|
||||
function autodetectTemplateFunction(
|
||||
model: string,
|
||||
provider: ModelProvider,
|
||||
explicitTemplate: TemplateType | undefined = undefined
|
||||
) {
|
||||
if (
|
||||
explicitTemplate === undefined &&
|
||||
PROVIDER_HANDLES_TEMPLATING.includes(provider)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const templateType = explicitTemplate || autodetectTemplateType(model);
|
||||
|
||||
if (templateType) {
|
||||
const mapping: Record<TemplateType, any> = {
|
||||
llama2: llama2TemplateMessages,
|
||||
alpaca: templateAlpacaMessages,
|
||||
phi2: phi2TemplateMessages,
|
||||
phind: phindTemplateMessages,
|
||||
zephyr: zephyrTemplateMessages,
|
||||
anthropic: anthropicTemplateMessages,
|
||||
chatml: chatmlTemplateMessages,
|
||||
deepseek: deepseekTemplateMessages,
|
||||
openchat: openchatTemplateMessages,
|
||||
"xwin-coder": xWinCoderTemplateMessages,
|
||||
"neural-chat": neuralChatTemplateMessages,
|
||||
llava: llavaTemplateMessages,
|
||||
"codellama-70b": codeLlama70bTemplateMessages,
|
||||
none: null,
|
||||
};
|
||||
|
||||
return mapping[templateType];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function autodetectPromptTemplates(
|
||||
model: string,
|
||||
explicitTemplate: TemplateType | undefined = undefined
|
||||
) {
|
||||
const templateType = explicitTemplate || autodetectTemplateType(model);
|
||||
const templates: Record<string, any> = {};
|
||||
|
||||
let editTemplate = null;
|
||||
|
||||
if (templateType === "phind") {
|
||||
editTemplate = phindEditPrompt;
|
||||
} else if (templateType === "phi2") {
|
||||
editTemplate = simplifiedEditPrompt;
|
||||
} else if (templateType === "zephyr") {
|
||||
editTemplate = zephyrEditPrompt;
|
||||
} else if (templateType === "llama2") {
|
||||
if (model.includes("mistral")) {
|
||||
editTemplate = mistralEditPrompt;
|
||||
} else {
|
||||
editTemplate = codellamaEditPrompt;
|
||||
}
|
||||
} else if (templateType === "alpaca") {
|
||||
editTemplate = alpacaEditPrompt;
|
||||
} else if (templateType === "deepseek") {
|
||||
editTemplate = deepseekEditPrompt;
|
||||
} else if (templateType === "openchat") {
|
||||
editTemplate = openchatEditPrompt;
|
||||
} else if (templateType === "xwin-coder") {
|
||||
editTemplate = xWinCoderEditPrompt;
|
||||
} else if (templateType === "neural-chat") {
|
||||
editTemplate = neuralChatEditPrompt;
|
||||
} else if (templateType === "codellama-70b") {
|
||||
editTemplate = codeLlama70bEditPrompt;
|
||||
} else if (templateType) {
|
||||
editTemplate = simplestEditPrompt;
|
||||
}
|
||||
|
||||
if (editTemplate !== null) {
|
||||
templates["edit"] = editTemplate;
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
export {
|
||||
autodetectPromptTemplates,
|
||||
autodetectTemplateFunction,
|
||||
autodetectTemplateType,
|
||||
llmCanGenerateInParallel,
|
||||
modelSupportsImages,
|
||||
};
|
||||
|
|
@ -12,6 +12,12 @@ import {
|
|||
TemplateType,
|
||||
} from "..";
|
||||
import mergeJson from "../util/merge";
|
||||
import {
|
||||
autodetectPromptTemplates,
|
||||
autodetectTemplateFunction,
|
||||
autodetectTemplateType,
|
||||
modelSupportsImages,
|
||||
} from "./autodetect";
|
||||
import {
|
||||
CONTEXT_LENGTH_FOR_MODEL,
|
||||
DEFAULT_ARGS,
|
||||
|
|
@ -23,251 +29,8 @@ import {
|
|||
countTokens,
|
||||
pruneRawPromptFromTop,
|
||||
} from "./countTokens";
|
||||
import {
|
||||
anthropicTemplateMessages,
|
||||
chatmlTemplateMessages,
|
||||
codeLlama70bTemplateMessages,
|
||||
deepseekTemplateMessages,
|
||||
llama2TemplateMessages,
|
||||
llavaTemplateMessages,
|
||||
neuralChatTemplateMessages,
|
||||
openchatTemplateMessages,
|
||||
phi2TemplateMessages,
|
||||
phindTemplateMessages,
|
||||
templateAlpacaMessages,
|
||||
xWinCoderTemplateMessages,
|
||||
zephyrTemplateMessages,
|
||||
} from "./templates/chat";
|
||||
import {
|
||||
alpacaEditPrompt,
|
||||
codeLlama70bEditPrompt,
|
||||
codellamaEditPrompt,
|
||||
deepseekEditPrompt,
|
||||
mistralEditPrompt,
|
||||
neuralChatEditPrompt,
|
||||
openchatEditPrompt,
|
||||
phindEditPrompt,
|
||||
simplestEditPrompt,
|
||||
simplifiedEditPrompt,
|
||||
xWinCoderEditPrompt,
|
||||
zephyrEditPrompt,
|
||||
} from "./templates/edit";
|
||||
import CompletionOptionsForModels from "./templates/options";
|
||||
|
||||
const PROVIDER_HANDLES_TEMPLATING: ModelProvider[] = [
|
||||
"lmstudio",
|
||||
"openai",
|
||||
"ollama",
|
||||
"together",
|
||||
];
|
||||
|
||||
const PROVIDER_SUPPORTS_IMAGES: ModelProvider[] = [
|
||||
"openai",
|
||||
"ollama",
|
||||
"google-palm",
|
||||
"free-trial",
|
||||
];
|
||||
|
||||
export function modelSupportsImages(
|
||||
provider: ModelProvider,
|
||||
model: string
|
||||
): boolean {
|
||||
if (!PROVIDER_SUPPORTS_IMAGES.includes(provider)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (model.includes("llava")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (["gpt-4-vision-preview"].includes(model)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
model === "gemini-ultra" &&
|
||||
(provider === "google-palm" || provider === "free-trial")
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
const PARALLEL_PROVIDERS: ModelProvider[] = [
|
||||
"anthropic",
|
||||
"bedrock",
|
||||
"deepinfra",
|
||||
"gemini",
|
||||
"google-palm",
|
||||
"huggingface-inference-api",
|
||||
"huggingface-tgi",
|
||||
"mistral",
|
||||
"free-trial",
|
||||
"replicate",
|
||||
"together",
|
||||
];
|
||||
|
||||
export function llmCanGenerateInParallel(llm: ILLM): boolean {
|
||||
if (llm.providerName === "openai") {
|
||||
return llm.model.includes("gpt");
|
||||
}
|
||||
|
||||
return PARALLEL_PROVIDERS.includes(llm.providerName);
|
||||
}
|
||||
|
||||
function autodetectTemplateType(model: string): TemplateType | undefined {
|
||||
const lower = model.toLowerCase();
|
||||
|
||||
if (lower.includes("codellama") && lower.includes("70b")) {
|
||||
return "codellama-70b";
|
||||
}
|
||||
|
||||
if (
|
||||
lower.includes("gpt") ||
|
||||
lower.includes("chat-bison") ||
|
||||
lower.includes("pplx") ||
|
||||
lower.includes("gemini")
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (lower.includes("llava")) {
|
||||
return "llava";
|
||||
}
|
||||
|
||||
if (lower.includes("xwin")) {
|
||||
return "xwin-coder";
|
||||
}
|
||||
|
||||
if (lower.includes("dolphin")) {
|
||||
return "chatml";
|
||||
}
|
||||
|
||||
if (lower.includes("phi2")) {
|
||||
return "phi2";
|
||||
}
|
||||
|
||||
if (lower.includes("phind")) {
|
||||
return "phind";
|
||||
}
|
||||
|
||||
if (lower.includes("llama")) {
|
||||
return "llama2";
|
||||
}
|
||||
|
||||
if (lower.includes("zephyr")) {
|
||||
return "zephyr";
|
||||
}
|
||||
|
||||
if (lower.includes("claude")) {
|
||||
return "anthropic";
|
||||
}
|
||||
|
||||
if (lower.includes("alpaca") || lower.includes("wizard")) {
|
||||
return "alpaca";
|
||||
}
|
||||
|
||||
if (lower.includes("mistral")) {
|
||||
return "llama2";
|
||||
}
|
||||
|
||||
if (lower.includes("deepseek")) {
|
||||
return "deepseek";
|
||||
}
|
||||
|
||||
if (lower.includes("ninja") || lower.includes("openchat")) {
|
||||
return "openchat";
|
||||
}
|
||||
|
||||
if (lower.includes("neural-chat")) {
|
||||
return "neural-chat";
|
||||
}
|
||||
|
||||
return "chatml";
|
||||
}
|
||||
|
||||
function autodetectTemplateFunction(
|
||||
model: string,
|
||||
provider: ModelProvider,
|
||||
explicitTemplate: TemplateType | undefined = undefined
|
||||
) {
|
||||
if (
|
||||
explicitTemplate === undefined &&
|
||||
PROVIDER_HANDLES_TEMPLATING.includes(provider)
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const templateType = explicitTemplate || autodetectTemplateType(model);
|
||||
|
||||
if (templateType) {
|
||||
const mapping: Record<TemplateType, any> = {
|
||||
llama2: llama2TemplateMessages,
|
||||
alpaca: templateAlpacaMessages,
|
||||
phi2: phi2TemplateMessages,
|
||||
phind: phindTemplateMessages,
|
||||
zephyr: zephyrTemplateMessages,
|
||||
anthropic: anthropicTemplateMessages,
|
||||
chatml: chatmlTemplateMessages,
|
||||
deepseek: deepseekTemplateMessages,
|
||||
openchat: openchatTemplateMessages,
|
||||
"xwin-coder": xWinCoderTemplateMessages,
|
||||
"neural-chat": neuralChatTemplateMessages,
|
||||
llava: llavaTemplateMessages,
|
||||
"codellama-70b": codeLlama70bTemplateMessages,
|
||||
none: null,
|
||||
};
|
||||
|
||||
return mapping[templateType];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function autodetectPromptTemplates(
|
||||
model: string,
|
||||
explicitTemplate: TemplateType | undefined = undefined
|
||||
) {
|
||||
const templateType = explicitTemplate || autodetectTemplateType(model);
|
||||
const templates: Record<string, any> = {};
|
||||
|
||||
let editTemplate = null;
|
||||
|
||||
if (templateType === "phind") {
|
||||
editTemplate = phindEditPrompt;
|
||||
} else if (templateType === "phi2") {
|
||||
editTemplate = simplifiedEditPrompt;
|
||||
} else if (templateType === "zephyr") {
|
||||
editTemplate = zephyrEditPrompt;
|
||||
} else if (templateType === "llama2") {
|
||||
if (model.includes("mistral")) {
|
||||
editTemplate = mistralEditPrompt;
|
||||
} else {
|
||||
editTemplate = codellamaEditPrompt;
|
||||
}
|
||||
} else if (templateType === "alpaca") {
|
||||
editTemplate = alpacaEditPrompt;
|
||||
} else if (templateType === "deepseek") {
|
||||
editTemplate = deepseekEditPrompt;
|
||||
} else if (templateType === "openchat") {
|
||||
editTemplate = openchatEditPrompt;
|
||||
} else if (templateType === "xwin-coder") {
|
||||
editTemplate = xWinCoderEditPrompt;
|
||||
} else if (templateType === "neural-chat") {
|
||||
editTemplate = neuralChatEditPrompt;
|
||||
} else if (templateType === "codellama-70b") {
|
||||
editTemplate = codeLlama70bEditPrompt;
|
||||
} else if (templateType) {
|
||||
editTemplate = simplestEditPrompt;
|
||||
}
|
||||
|
||||
if (editTemplate !== null) {
|
||||
templates["edit"] = editTemplate;
|
||||
}
|
||||
|
||||
return templates;
|
||||
}
|
||||
|
||||
export abstract class BaseLLM implements ILLM {
|
||||
static providerName: ModelProvider;
|
||||
static defaultOptions: Partial<LLMOptions> | undefined = undefined;
|
||||
|
|
|
|||
2
extensions/vscode/package-lock.json
generated
2
extensions/vscode/package-lock.json
generated
|
|
@ -79,12 +79,14 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"dotenv": "^16.3.1",
|
||||
"fastest-levenshtein": "^1.0.16",
|
||||
"handlebars": "^4.7.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
"openai": "^4.20.1",
|
||||
"replicate": "^0.23.0",
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import {
|
|||
} from "core/config/load";
|
||||
import { LanceDbIndex } from "core/indexing/LanceDbIndex";
|
||||
import { IndexTag } from "core/indexing/types";
|
||||
import mergeJson from "core/util/merge";
|
||||
import { verticalPerLineDiffManager } from "./diff/verticalPerLine/manager";
|
||||
import { configHandler } from "./loadConfig";
|
||||
import { traverseDirectory } from "./util/traverseDirectory";
|
||||
|
|
|
|||
|
|
@ -1,12 +1,19 @@
|
|||
import { ContinueConfig, ILLM } from "core";
|
||||
import { ContinueConfig, ILLM, SerializedContinueConfig } from "core";
|
||||
import defaultConfig from "core/config/default";
|
||||
import { loadFullConfigNode } from "core/config/load";
|
||||
import {
|
||||
finalToBrowserConfig,
|
||||
intermediateToFinalConfig,
|
||||
loadFullConfigNode,
|
||||
serializedToIntermediateConfig,
|
||||
} from "core/config/load";
|
||||
import { getConfigJsonPath } from "core/util/paths";
|
||||
import { https } from "follow-redirects";
|
||||
import * as fs from "fs";
|
||||
import fetch from "node-fetch";
|
||||
import * as path from "path";
|
||||
import * as vscode from "vscode";
|
||||
import { webviewRequest } from "./debugPanel";
|
||||
import { ideProtocolClient } from "./activation/activate";
|
||||
import { debugPanelWebview, webviewRequest } from "./debugPanel";
|
||||
const tls = require("tls");
|
||||
|
||||
const outputChannel = vscode.window.createOutputChannel(
|
||||
|
|
@ -20,15 +27,42 @@ class VsCodeConfigHandler {
|
|||
this.savedConfig = undefined;
|
||||
}
|
||||
|
||||
private async _getWorkspaceConfigs() {
|
||||
const workspaceDirs = await ideProtocolClient.getWorkspaceDirectories();
|
||||
const configs: Partial<SerializedContinueConfig>[] = [];
|
||||
for (const workspaceDir of workspaceDirs) {
|
||||
const files = await vscode.workspace.fs.readDirectory(
|
||||
vscode.Uri.file(workspaceDir)
|
||||
);
|
||||
for (const [filename, type] of files) {
|
||||
if (type === vscode.FileType.File && filename === ".continurc.json") {
|
||||
const contents = await ideProtocolClient.readFile(
|
||||
path.join(workspaceDir, filename)
|
||||
);
|
||||
configs.push(JSON.parse(contents));
|
||||
}
|
||||
}
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
async loadConfig(): Promise<ContinueConfig> {
|
||||
try {
|
||||
if (this.savedConfig) {
|
||||
return this.savedConfig;
|
||||
}
|
||||
this.savedConfig = await loadFullConfigNode(ideProtocolClient.readFile);
|
||||
this.savedConfig = await loadFullConfigNode(
|
||||
ideProtocolClient.readFile,
|
||||
await this._getWorkspaceConfigs()
|
||||
);
|
||||
this.savedConfig.allowAnonymousTelemetry =
|
||||
this.savedConfig.allowAnonymousTelemetry &&
|
||||
vscode.workspace.getConfiguration("continue").get("telemetryEnabled");
|
||||
|
||||
// Update the sidebar panel
|
||||
const browserConfig = finalToBrowserConfig(this.savedConfig);
|
||||
debugPanelWebview?.postMessage({ type: "configUpdate", browserConfig });
|
||||
|
||||
return this.savedConfig;
|
||||
} catch (e) {
|
||||
vscode.window
|
||||
|
|
@ -45,7 +79,10 @@ class VsCodeConfigHandler {
|
|||
});
|
||||
}
|
||||
});
|
||||
return defaultConfig;
|
||||
return intermediateToFinalConfig(
|
||||
serializedToIntermediateConfig(defaultConfig),
|
||||
ideProtocolClient.readFile
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2269,12 +2269,14 @@ core-util-is@~1.0.0, core-util-is@1.0.2:
|
|||
resolved "file:../../core"
|
||||
dependencies:
|
||||
"@octokit/rest" "^20.0.2"
|
||||
"@types/node-fetch" "^2.6.11"
|
||||
"@xenova/transformers" "^2.14.0"
|
||||
cheerio "^1.0.0-rc.12"
|
||||
dotenv "^16.3.1"
|
||||
fastest-levenshtein "^1.0.16"
|
||||
handlebars "^4.7.8"
|
||||
js-tiktoken "^1.0.8"
|
||||
node-fetch "^3.3.2"
|
||||
node-html-markdown "^1.3.0"
|
||||
openai "^4.20.1"
|
||||
replicate "^0.23.0"
|
||||
|
|
|
|||
4
gui/package-lock.json
generated
4
gui/package-lock.json
generated
|
|
@ -75,12 +75,14 @@
|
|||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@octokit/rest": "^20.0.2",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"dotenv": "^16.3.1",
|
||||
"fastest-levenshtein": "^1.0.16",
|
||||
"handlebars": "^4.7.8",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
"openai": "^4.20.1",
|
||||
"replicate": "^0.23.0",
|
||||
|
|
@ -8663,6 +8665,7 @@
|
|||
"@types/jest": "^29.5.11",
|
||||
"@types/jquery": "^3.5.29",
|
||||
"@types/mustache": "^4.2.5",
|
||||
"@types/node-fetch": "^2.6.11",
|
||||
"@types/uuid": "^9.0.7",
|
||||
"@xenova/transformers": "^2.14.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
|
|
@ -8672,6 +8675,7 @@
|
|||
"handlebars": "^4.7.8",
|
||||
"jest": "^29.7.0",
|
||||
"js-tiktoken": "^1.0.8",
|
||||
"node-fetch": "^3.3.2",
|
||||
"node-html-markdown": "^1.3.0",
|
||||
"openai": "^4.20.1",
|
||||
"replicate": "^0.23.0",
|
||||
|
|
|
|||
|
|
@ -230,7 +230,7 @@ const Layout = () => {
|
|||
)} */}
|
||||
<ModelSelect />
|
||||
{indexingProgress >= 1 && // Would take up too much space together with indexing progress
|
||||
defaultModel?.providerName === "free-trial" &&
|
||||
defaultModel?.provider === "free-trial" &&
|
||||
defaultModel?.apiKey === "" &&
|
||||
(location.pathname === "/settings" ||
|
||||
parseInt(localStorage.getItem("ftc") || "0") >= 125) && (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { PhotoIcon as OutlinePhotoIcon } from "@heroicons/react/24/outline";
|
||||
import { PhotoIcon as SolidPhotoIcon } from "@heroicons/react/24/solid";
|
||||
import { modelSupportsImages } from "core/llm/autodetect";
|
||||
import { useRef, useState } from "react";
|
||||
import { useSelector } from "react-redux";
|
||||
import styled from "styled-components";
|
||||
|
|
@ -86,44 +87,45 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
>
|
||||
+ Add Context
|
||||
</span>
|
||||
{defaultModel?.supportsImages() && (
|
||||
<span
|
||||
className="ml-1.5 mt-0.5"
|
||||
onMouseLeave={() => setFileSelectHovered(false)}
|
||||
onMouseEnter={() => setFileSelectHovered(true)}
|
||||
>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
style={{ display: "none" }}
|
||||
accept=".jpg,.jpeg,.png,.gif,.svg,.webp"
|
||||
onChange={(e) => {
|
||||
for (const file of e.target.files) {
|
||||
props.onImageFileSelected(file);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
{fileSelectHovered ? (
|
||||
<SolidPhotoIcon
|
||||
width="1.4em"
|
||||
height="1.4em"
|
||||
color={lightGray}
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
{defaultModel &&
|
||||
modelSupportsImages(defaultModel.provider, defaultModel.model) && (
|
||||
<span
|
||||
className="ml-1.5 mt-0.5"
|
||||
onMouseLeave={() => setFileSelectHovered(false)}
|
||||
onMouseEnter={() => setFileSelectHovered(true)}
|
||||
>
|
||||
<input
|
||||
type="file"
|
||||
ref={fileInputRef}
|
||||
style={{ display: "none" }}
|
||||
accept=".jpg,.jpeg,.png,.gif,.svg,.webp"
|
||||
onChange={(e) => {
|
||||
for (const file of e.target.files) {
|
||||
props.onImageFileSelected(file);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<OutlinePhotoIcon
|
||||
width="1.4em"
|
||||
height="1.4em"
|
||||
color={lightGray}
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
{fileSelectHovered ? (
|
||||
<SolidPhotoIcon
|
||||
width="1.4em"
|
||||
height="1.4em"
|
||||
color={lightGray}
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<OutlinePhotoIcon
|
||||
width="1.4em"
|
||||
height="1.4em"
|
||||
color={lightGray}
|
||||
onClick={(e) => {
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
</span>
|
||||
<span
|
||||
style={{
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ import Paragraph from "@tiptap/extension-paragraph";
|
|||
import Placeholder from "@tiptap/extension-placeholder";
|
||||
import Text from "@tiptap/extension-text";
|
||||
import { Editor, EditorContent, JSONContent, useEditor } from "@tiptap/react";
|
||||
import { ContextItemWithId, IContextProvider, RangeInFile } from "core";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
ContextProviderDescription,
|
||||
RangeInFile,
|
||||
} from "core";
|
||||
import { getBasename } from "core/util";
|
||||
import { useContext, useEffect, useRef, useState } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
|
|
@ -112,7 +116,7 @@ function getDataUrlForFile(file: File, img): string {
|
|||
}
|
||||
|
||||
interface TipTapEditorProps {
|
||||
availableContextProviders: IContextProvider[];
|
||||
availableContextProviders: ContextProviderDescription[];
|
||||
availableSlashCommands: ComboBoxItem[];
|
||||
isMainInput: boolean;
|
||||
onEnter: (editorState: JSONContent) => void;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
import { JSONContent } from "@tiptap/react";
|
||||
import {
|
||||
ContextItemWithId,
|
||||
EmbeddingsProvider,
|
||||
IContextProvider,
|
||||
ILLM,
|
||||
MessageContent,
|
||||
MessagePart,
|
||||
RangeInFile,
|
||||
|
|
@ -28,10 +25,7 @@ interface MentionAttrs {
|
|||
*/
|
||||
|
||||
async function resolveEditorContent(
|
||||
editorState: JSONContent,
|
||||
contextProviders: IContextProvider[],
|
||||
llm: ILLM,
|
||||
embeddingsProvider?: EmbeddingsProvider
|
||||
editorState: JSONContent
|
||||
): Promise<[ContextItemWithId[], MessageContent]> {
|
||||
let parts: MessagePart[] = [];
|
||||
let contextItemAttrs: MentionAttrs[] = [];
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
ChatMessage,
|
||||
LLMReturnValue,
|
||||
MessageContent,
|
||||
SlashCommand,
|
||||
SlashCommandDescription,
|
||||
} from "core";
|
||||
import { ideStreamRequest, llmStreamChat } from "core/ide/messaging";
|
||||
import { constructMessages } from "core/llm/constructMessages";
|
||||
|
|
@ -41,13 +41,8 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
const contextItems = useSelector(
|
||||
(state: RootStore) => state.state.contextItems
|
||||
);
|
||||
const embeddingsProvider = useSelector(
|
||||
(state: RootStore) => state.state.config.embeddingsProvider
|
||||
);
|
||||
|
||||
const history = useSelector((store: RootStore) => store.state.history);
|
||||
const contextProviders = useSelector(
|
||||
(store: RootStore) => store.state.config.contextProviders || []
|
||||
);
|
||||
const active = useSelector((store: RootStore) => store.state.active);
|
||||
const activeRef = useRef(active);
|
||||
useEffect(() => {
|
||||
|
|
@ -77,8 +72,8 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
|
||||
const getSlashCommandForInput = (
|
||||
input: MessageContent
|
||||
): [SlashCommand, string] | undefined => {
|
||||
let slashCommand: SlashCommand | undefined;
|
||||
): [SlashCommandDescription, string] | undefined => {
|
||||
let slashCommand: SlashCommandDescription | undefined;
|
||||
let slashCommandName: string | undefined;
|
||||
|
||||
let lastText =
|
||||
|
|
@ -102,7 +97,7 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
|
||||
async function _streamSlashCommand(
|
||||
messages: ChatMessage[],
|
||||
slashCommand: SlashCommand,
|
||||
slashCommand: SlashCommandDescription,
|
||||
input: string,
|
||||
historyIndex: number
|
||||
) {
|
||||
|
|
@ -142,12 +137,7 @@ function useChatHandler(dispatch: Dispatch) {
|
|||
}
|
||||
|
||||
// Resolve context providers and construct new history
|
||||
const [contextItems, content] = await resolveEditorContent(
|
||||
editorState,
|
||||
contextProviders,
|
||||
defaultModel,
|
||||
embeddingsProvider
|
||||
);
|
||||
const [contextItems, content] = await resolveEditorContent(editorState);
|
||||
const message: ChatMessage = {
|
||||
role: "user",
|
||||
content,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
import { PersistedSessionInfo, SessionInfo } from "core";
|
||||
import { ideRequest, llmStreamChat } from "core/ide/messaging";
|
||||
import { llmCanGenerateInParallel } from "core/llm";
|
||||
import { llmCanGenerateInParallel } from "core/llm/autodetect";
|
||||
import { stripImages } from "core/llm/countTokens";
|
||||
import { useSelector } from "react-redux";
|
||||
import { defaultModelSelector } from "../redux/selectors/modelSelectors";
|
||||
|
|
@ -41,7 +41,7 @@ function useHistory(dispatch: Dispatch) {
|
|||
if (
|
||||
false && // Causing maxTokens to be set to 20 for main requests sometimes, so disabling until resolved
|
||||
!disableSessionTitles &&
|
||||
llmCanGenerateInParallel(defaultModel)
|
||||
llmCanGenerateInParallel(defaultModel.provider, defaultModel.model)
|
||||
) {
|
||||
let fullContent = "";
|
||||
for await (const { content } of llmStreamChat(
|
||||
|
|
|
|||
|
|
@ -1,12 +1,8 @@
|
|||
import { Dispatch } from "@reduxjs/toolkit";
|
||||
import { useEffect } from "react";
|
||||
import { setServerStatusMessage } from "../redux/slices/miscSlice";
|
||||
import { errorPopup, isJetBrains, postToIde } from "../util/ide";
|
||||
import { isJetBrains, postToIde } from "../util/ide";
|
||||
|
||||
import {
|
||||
intermediateToFinalConfig,
|
||||
serializedToIntermediateConfig,
|
||||
} from "core/config/load";
|
||||
import { ExtensionIde } from "core/ide/index";
|
||||
import { useSelector } from "react-redux";
|
||||
import { VSC_THEME_COLOR_VARS } from "../components";
|
||||
|
|
@ -17,37 +13,7 @@ import useChatHandler from "./useChatHandler";
|
|||
|
||||
function useSetup(dispatch: Dispatch<any>) {
|
||||
const loadConfig = async () => {
|
||||
try {
|
||||
const ide = new ExtensionIde();
|
||||
let serialized = await ide.getSerializedConfig();
|
||||
let intermediate = serializedToIntermediateConfig(serialized);
|
||||
|
||||
const configJsUrl = await ide.getConfigJsUrl();
|
||||
if (configJsUrl) {
|
||||
try {
|
||||
// Try config.ts first
|
||||
const module = await import(configJsUrl);
|
||||
if (!module.modifyConfig) {
|
||||
throw new Error(
|
||||
"config.ts does not export a modifyConfig function."
|
||||
);
|
||||
}
|
||||
intermediate = module.modifyConfig(intermediate);
|
||||
} catch (e) {
|
||||
console.log("Error loading config.ts: ", e);
|
||||
errorPopup(e.message);
|
||||
}
|
||||
}
|
||||
const finalConfig = await intermediateToFinalConfig(
|
||||
intermediate,
|
||||
async (filepath) => {
|
||||
return new ExtensionIde().readFile(filepath);
|
||||
}
|
||||
);
|
||||
|
||||
// Fall back to config.json
|
||||
dispatch(setConfig(finalConfig));
|
||||
} catch (e) {}
|
||||
dispatch(setConfig(await new ExtensionIde().getSerializedConfig()));
|
||||
};
|
||||
|
||||
// Load config from the IDE
|
||||
|
|
|
|||
|
|
@ -24,9 +24,9 @@ function useSubmenuContextProviders() {
|
|||
|
||||
const contextProviderDescriptions = useSelector(
|
||||
(state: RootStore) =>
|
||||
state.state.config.contextProviders
|
||||
?.map((provider) => provider.description)
|
||||
.filter((desc) => desc.type === "submenu") || []
|
||||
state.state.config.contextProviders.filter(
|
||||
(desc) => desc.type === "submenu"
|
||||
) || []
|
||||
);
|
||||
|
||||
const [loaded, setLoaded] = useState(false);
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ function GUI(props: GUIProps) {
|
|||
const sendInput = useCallback(
|
||||
(editorState: JSONContent) => {
|
||||
if (
|
||||
defaultModel.providerName === "free-trial" &&
|
||||
defaultModel?.provider === "free-trial" &&
|
||||
defaultModel?.apiKey === ""
|
||||
) {
|
||||
const ftc = localStorage.getItem("ftc");
|
||||
|
|
|
|||
|
|
@ -5,15 +5,9 @@ import {
|
|||
ChatMessage,
|
||||
ContextItemId,
|
||||
ContextItemWithId,
|
||||
ContinueConfig,
|
||||
PersistedSessionInfo,
|
||||
} from "core";
|
||||
import GenerateTerminalCommand from "core/commands/slash/cmd";
|
||||
import CommentSlashCommand from "core/commands/slash/comment";
|
||||
import EditSlashCommand from "core/commands/slash/edit";
|
||||
import ShareSlashCommand from "core/commands/slash/share";
|
||||
import TransformersJsEmbeddingsProvider from "core/indexing/embeddings/TransformersJsEmbeddingsProvider";
|
||||
import FreeTrial from "core/llm/llms/FreeTrial";
|
||||
import { BrowserSerializedContinueConfig } from "core/config/load";
|
||||
import { v4 } from "uuid";
|
||||
import { RootStore } from "../store";
|
||||
|
||||
|
|
@ -93,20 +87,36 @@ const initialState: RootStore["state"] = {
|
|||
active: false,
|
||||
config: {
|
||||
models: [
|
||||
new FreeTrial({ model: "gpt-4", title: "GPT-4 (Free Trial)" }),
|
||||
new FreeTrial({
|
||||
model: "gpt-3.5-turbo",
|
||||
{
|
||||
title: "GPT-4 (Free Trial)",
|
||||
model: "gpt-4",
|
||||
provider: "free-trial",
|
||||
},
|
||||
{
|
||||
title: "GPT-3.5-Turbo (Free Trial)",
|
||||
}),
|
||||
model: "gpt-3.5-turbo",
|
||||
provider: "free-trial",
|
||||
},
|
||||
],
|
||||
slashCommands: [
|
||||
EditSlashCommand,
|
||||
CommentSlashCommand,
|
||||
ShareSlashCommand,
|
||||
GenerateTerminalCommand,
|
||||
{
|
||||
name: "edit",
|
||||
description: "Edit selected code",
|
||||
},
|
||||
{
|
||||
name: "comment",
|
||||
description: "Write comments for the selected code",
|
||||
},
|
||||
{
|
||||
name: "share",
|
||||
description: "Download and share this session",
|
||||
},
|
||||
{
|
||||
name: "cmd",
|
||||
description: "Generate a shell command",
|
||||
},
|
||||
],
|
||||
contextProviders: [],
|
||||
embeddingsProvider: new TransformersJsEmbeddingsProvider(),
|
||||
},
|
||||
title: "New Session",
|
||||
sessionId: v4(),
|
||||
|
|
@ -117,7 +127,10 @@ export const stateSlice = createSlice({
|
|||
name: "state",
|
||||
initialState,
|
||||
reducers: {
|
||||
setConfig: (state, { payload }: { payload: ContinueConfig }) => {
|
||||
setConfig: (
|
||||
state,
|
||||
{ payload }: { payload: BrowserSerializedContinueConfig }
|
||||
) => {
|
||||
const config = payload;
|
||||
const defaultModelTitle = config.models.find(
|
||||
(model) => model.title === state.defaultModelTitle
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import {
|
|||
ContinueConfig,
|
||||
SlashCommandDescription,
|
||||
} from "core";
|
||||
import { BrowserSerializedContinueConfig } from "core/config/load";
|
||||
import { createTransform, persistReducer, persistStore } from "redux-persist";
|
||||
import { createFilter } from "redux-persist-transform-filter";
|
||||
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
|
||||
|
|
@ -27,7 +28,7 @@ export interface RootStore {
|
|||
history: ChatHistory;
|
||||
contextItems: ContextItemWithId[];
|
||||
active: boolean;
|
||||
config: ContinueConfig;
|
||||
config: BrowserSerializedContinueConfig;
|
||||
title: string;
|
||||
sessionId: string;
|
||||
defaultModelTitle: string;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue