From e1ed7ed0a2f2b68efd4090ce6e7f4d9794f2f111 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 14 Dec 2023 12:47:01 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20config.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/commands/index.ts | 21 +- core/commands/slash/cmd.ts | 2 +- core/commands/slash/comment.ts | 2 +- core/commands/slash/draftIssue.ts | 3 +- core/commands/slash/edit.ts | 6 +- core/commands/slash/share.ts | 2 +- core/commands/slash/stackOverflow.ts | 3 +- core/config/default.ts | 2 +- core/config/index.d.ts | 207 -------- core/config/load.ts | 92 +++- core/context/index.ts | 13 +- .../providers/CustomContextProvider.ts | 30 ++ core/context/providers/DiffContextProvider.ts | 6 +- core/context/providers/FileContextProvider.ts | 6 +- .../providers/FileTreeContextProvider.ts | 6 +- .../providers/GitHubIssuesContextProvider.ts | 7 +- .../providers/GoogleContextProvider.ts | 7 +- .../providers/TerminalContextProvider.ts | 6 +- core/context/providers/URLContextProvider.ts | 6 +- core/context/providers/index.ts | 8 +- core/ide/filesystem.ts | 3 +- core/ide/index.ts | 4 +- core/ide/types.d.ts | 24 - core/index.d.ts | 455 ++++++++++++++++++ core/llm/constructMessages.ts | 2 +- core/llm/countTokens.ts | 2 +- core/llm/index.ts | 63 +-- core/llm/llms/Anthropic.ts | 7 +- core/llm/llms/CustomLLM.ts | 55 +++ core/llm/llms/FreeTrial.ts | 7 +- core/llm/llms/Gemini.ts | 12 +- core/llm/llms/GooglePalm.ts | 12 +- core/llm/llms/GooglePalmProxy.ts | 12 +- core/llm/llms/HuggingFaceInferenceAPI.ts | 7 +- core/llm/llms/HuggingFaceTGI.ts | 7 +- core/llm/llms/LMStudio.ts | 3 +- core/llm/llms/LlamaCpp.ts | 7 +- core/llm/llms/Llamafile.ts | 2 +- core/llm/llms/Mistral.ts | 3 +- core/llm/llms/Ollama.ts | 7 +- core/llm/llms/OpenAI.ts | 13 +- core/llm/llms/Replicate.ts | 12 +- core/llm/llms/TextGenWebUI.ts | 7 +- core/llm/llms/Together.ts | 7 +- core/llm/llms/index.ts | 6 +- core/llm/templates/chat.ts | 8 +- core/llm/types.d.ts | 50 -- core/types.d.ts | 39 -- core/util/index.ts | 2 +- core/util/paths.ts | 2 +- extensions/vscode/esbuild.mjs | 2 +- extensions/vscode/src/activation/activate.ts | 9 - extensions/vscode/src/continueIdeClient.ts | 6 +- extensions/vscode/src/debugPanel.ts | 3 +- extensions/vscode/src/history.ts | 2 +- extensions/vscode/src/ideProtocol.ts | 28 +- .../dialogs/AddContextGroupDialog.tsx | 2 +- gui/src/components/gui/ErrorStepContainer.tsx | 2 +- gui/src/components/gui/StepContainer.tsx | 2 +- gui/src/components/gui/TimelineItem.tsx | 2 +- gui/src/components/mainInput/ComboBox.tsx | 2 +- gui/src/components/mainInput/PillButton.tsx | 2 +- .../markdown/CodeSnippetPreview.tsx | 19 +- gui/src/hooks/useChatHandler.ts | 3 +- gui/src/hooks/useContextProviders.ts | 2 +- gui/src/hooks/useHistory.tsx | 2 +- gui/src/hooks/useSetup.ts | 44 +- gui/src/pages/history.tsx | 2 +- gui/src/pages/settings.tsx | 2 +- gui/src/redux/slices/serverStateReducer.ts | 17 +- gui/src/redux/slices/stateSlice.ts | 19 +- gui/src/redux/store.ts | 12 +- gui/src/util/modelData.ts | 2 +- 73 files changed, 832 insertions(+), 629 deletions(-) delete mode 100644 core/config/index.d.ts create mode 100644 core/context/providers/CustomContextProvider.ts delete mode 100644 core/ide/types.d.ts create mode 100644 core/index.d.ts create mode 100644 core/llm/llms/CustomLLM.ts delete mode 100644 core/llm/types.d.ts delete mode 100644 core/types.d.ts diff --git a/core/commands/index.ts b/core/commands/index.ts index 8f2a27053..a547aa2ff 100644 --- a/core/commands/index.ts +++ b/core/commands/index.ts @@ -1,24 +1,5 @@ -import { CustomCommand, SlashCommandDescription } from "../config"; -import { IDE } from "../ide/types"; -import { LLM } from "../llm"; -import { ChatMessage, ContextItem } from "../llm/types"; +import { CustomCommand, SlashCommand, SlashCommandDescription } from ".."; import SlashCommands from "./slash"; -export interface ContinueSDK { - ide: IDE; - llm: LLM; - addContextItem: (item: ContextItem) => void; - history: ChatMessage[]; - input: string; - params?: any; - contextItems: ContextItem[]; -} - -export interface SlashCommand { - name: string; - description: string; - params?: { [key: string]: any }; - run: (sdk: ContinueSDK) => AsyncGenerator; -} export function slashFromCustomCommand( customCommand: CustomCommand diff --git a/core/commands/slash/cmd.ts b/core/commands/slash/cmd.ts index 3f256f3dd..44c27357d 100644 --- a/core/commands/slash/cmd.ts +++ b/core/commands/slash/cmd.ts @@ -1,4 +1,4 @@ -import { SlashCommand } from ".."; +import { SlashCommand } from "../.."; import { removeQuotesAndEscapes } from "../../util"; const GenerateTerminalCommand: SlashCommand = { diff --git a/core/commands/slash/comment.ts b/core/commands/slash/comment.ts index 4cbf8146c..8430fdea8 100644 --- a/core/commands/slash/comment.ts +++ b/core/commands/slash/comment.ts @@ -1,4 +1,4 @@ -import { SlashCommand } from ".."; +import { SlashCommand } from "../.."; import EditSlashCommand from "./edit"; const CommentSlashCommand: SlashCommand = { diff --git a/core/commands/slash/draftIssue.ts b/core/commands/slash/draftIssue.ts index 9177c9ebd..a706c44d2 100644 --- a/core/commands/slash/draftIssue.ts +++ b/core/commands/slash/draftIssue.ts @@ -1,5 +1,4 @@ -import { SlashCommand } from ".."; -import { ChatMessage } from "../../llm/types"; +import { ChatMessage, SlashCommand } from "../.."; import { removeQuotesAndEscapes } from "../../util"; const PROMPT = ( diff --git a/core/commands/slash/edit.ts b/core/commands/slash/edit.ts index f188ced17..82d955feb 100644 --- a/core/commands/slash/edit.ts +++ b/core/commands/slash/edit.ts @@ -1,6 +1,4 @@ -import { SlashCommand } from ".."; -import { LLM } from "../../llm"; -import { ContextItem } from "../../llm/types"; +import { ContextItem, ILLM, SlashCommand } from "../.."; import { dedentAndGetCommonWhitespace, renderPromptTemplate } from "../../util"; interface RangeInFileWithContents { @@ -50,7 +48,7 @@ Main task: export async function getPromptParts( rif: RangeInFileWithContents, fullFileContents: string, - model: LLM, + model: ILLM, input: string ) { let maxTokens = Math.floor(model.contextLength / 2); diff --git a/core/commands/slash/share.ts b/core/commands/slash/share.ts index ca9942810..33cd8fe68 100644 --- a/core/commands/slash/share.ts +++ b/core/commands/slash/share.ts @@ -1,4 +1,4 @@ -import { SlashCommand } from ".."; +import { SlashCommand } from "../.."; const ShareSlashCommand: SlashCommand = { name: "share", diff --git a/core/commands/slash/stackOverflow.ts b/core/commands/slash/stackOverflow.ts index a8362b555..fbe7c687c 100644 --- a/core/commands/slash/stackOverflow.ts +++ b/core/commands/slash/stackOverflow.ts @@ -1,6 +1,5 @@ -import { SlashCommand } from ".."; +import { ChatMessageRole, SlashCommand } from "../.."; import { pruneStringFromBottom } from "../../llm/countTokens"; -import { ChatMessageRole } from "../../llm/types"; const SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app"; const PROMPT = ( diff --git a/core/config/default.ts b/core/config/default.ts index 67e0f1ec1..796225d81 100644 --- a/core/config/default.ts +++ b/core/config/default.ts @@ -1,4 +1,4 @@ -import { SerializedContinueConfig } from "."; +import { SerializedContinueConfig } from ".."; const defaultConfig: SerializedContinueConfig = { models: [ diff --git a/core/config/index.d.ts b/core/config/index.d.ts deleted file mode 100644 index 12c5c5df6..000000000 --- a/core/config/index.d.ts +++ /dev/null @@ -1,207 +0,0 @@ -/* - -These are the types for the JSON config file, config.json. - -**/ - -import { SlashCommand } from "../commands/index"; -import { ContextProvider } from "../context"; -import { LLM } from "../llm"; - -type StepName = - | "AnswerQuestionChroma" - | "GenerateShellCommandStep" - | "EditHighlightedCodeStep" - | "ShareSessionStep" - | "CommentCodeStep" - | "ClearHistoryStep" - | "StackOverflowStep" - | "OpenConfigStep" - | "GenerateShellCommandStep" - | "DraftIssueStep"; - -type ContextProviderName = - | "diff" - | "github" - | "terminal" - | "open" - | "google" - | "search" - | "url" - | "tree"; - -type TemplateType = - | "llama2" - | "alpaca" - | "zephyr" - | "phind" - | "anthropic" - | "chatml" - | "deepseek"; - -type ModelProvider = - | "openai" - | "openai-free-trial" - | "openai-aiohttp" - | "anthropic" - | "together" - | "ollama" - | "huggingface-tgi" - | "huggingface-inference-api" - | "llama.cpp" - | "replicate" - | "text-gen-webui" - | "google-palm" - | "google-palm-real" - | "lmstudio" - | "llamafile" - | "gemini" - | "mistral"; - -export type ModelName = - // OpenAI - | "gpt-3.5-turbo" - | "gpt-3.5-turbo-16k" - | "gpt-4" - | "gpt-3.5-turbo-0613" - | "gpt-4-32k" - | "gpt-4-1106-preview" - // Open Source - | "mistral-7b" - | "mistral-8x7b" - | "llama2-7b" - | "llama2-13b" - | "codellama-7b" - | "codellama-13b" - | "codellama-34b" - | "phind-codellama-34b" - | "wizardcoder-7b" - | "wizardcoder-13b" - | "wizardcoder-34b" - | "zephyr-7b" - | "codeup-13b" - | "deepseek-1b" - | "deepseek-7b" - | "deepseek-33b" - // Anthropic - | "claude-2" - // Google PaLM - | "chat-bison-001" - // Gemini - | "gemini-pro"; - -interface RequestOptions { - timeout?: number; - verifySsl?: boolean; - caBundlePath: string; - proxy?: string; - headers?: Record; -} - -interface StepWithParams { - name: StepName; - params: { [key: string]: any }; -} - -interface ContextProviderWithParams { - name: ContextProviderName; - params: { [key: string]: any }; -} - -interface SlashCommandDescription { - name: string; - description: string; - step: StepName | string; - params?: { [key: string]: any }; -} - -interface CustomCommand { - name: string; - prompt: string; - description: string; -} -interface RetrievalSettings { - nRetrieve?: number; - nFinal?: number; - useReranking: boolean; - rerankGroupSize: number; - ignoreFiles: string[]; - openaiApiKey?: string; - apiBase?: string; - apiType?: string; - apiVersion?: string; - organizationId?: string; -} - -interface BaseCompletionOptions { - temperature?: number; - topP?: number; - topK?: number; - presencePenalty?: number; - frequencyPenalty?: number; - stop?: string[]; - maxTokens: number; -} - -interface ModelDescription { - title: string; - provider: ModelProvider; - model: string; - apiKey?: string; - apiBase?: string; - contextLength?: number; - template?: TemplateType; - completionOptions?: BaseCompletionOptions; - systemMessage?: string; - requestOptions?: RequestOptions; -} - -interface ModelRoles { - default: string; - chat?: string; - edit?: string; - summarize?: string; -} - -interface SerializedContinueConfig { - disallowedSteps?: string[]; - allowAnonymousTelemetry?: boolean; - models: ModelDescription[]; - modelRoles: ModelRoles; - systemMessage?: string; - completionOptions?: BaseCompletionOptions; - slashCommands?: SlashCommandDescription[]; - customCommands?: CustomCommand[]; - contextProviders?: ContextProviderWithParams[]; - retrievalSettings?: RetrievalSettings; - disableIndexing?: boolean; -} - -interface ContinueConfig { - allowAnonymousTelemetry?: boolean; - models: LLM[]; - systemMessage?: string; - completionOptions?: BaseCompletionOptions; - slashCommands?: SlashCommand[]; - contextProviders?: ContextProvider[]; - retrievalSettings?: RetrievalSettings; - disableIndexing?: boolean; -} - -export { - BaseCompletionOptions, - ContextProviderName, - ContextProviderWithParams, - ContinueConfig, - CustomCommand, - ModelDescription, - ModelProvider, - ModelRoles, - RequestOptions, - RetrievalSettings, - SerializedContinueConfig, - SlashCommandDescription, - StepName, - StepWithParams, - TemplateType, -}; diff --git a/core/config/load.ts b/core/config/load.ts index 31e94aa91..22815e143 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -1,25 +1,28 @@ -import { ContinueConfig, SerializedContinueConfig } from "."; import { + Config, + ContextProviderWithParams, + ContinueConfig, + CustomContextProvider, + CustomLLM, + IContextProvider, + ModelDescription, + SerializedContinueConfig, SlashCommand, +} from ".."; +import { slashCommandFromDescription, slashFromCustomCommand, } from "../commands"; -import { ContextProvider } from "../context"; import { contextProviderClassFromName } from "../context/providers"; +import CustomContextProviderClass from "../context/providers/CustomContextProvider"; import FileContextProvider from "../context/providers/FileContextProvider"; -import { LLM } from "../llm"; +import { BaseLLM } from "../llm"; import { llmFromDescription } from "../llm/llms"; +import CustomLLMClass from "../llm/llms/CustomLLM"; -function loadSerializedConfig( +function serializedToIntermediateConfig( initial: SerializedContinueConfig -): ContinueConfig { - const models: LLM[] = []; - for (const desc of initial.models) { - const llm = llmFromDescription(desc, initial.completionOptions); - if (!llm) continue; - models.push(llm); - } - +): Config { const slashCommands: SlashCommand[] = []; for (const command of initial.slashCommands || []) { const newCommand = slashCommandFromDescription(command); @@ -31,23 +34,13 @@ function loadSerializedConfig( slashCommands.push(slashFromCustomCommand(command)); } - const contextProviders: ContextProvider[] = [new FileContextProvider({})]; - for (const provider of initial.contextProviders || []) { - const cls = contextProviderClassFromName(provider.name) as any; - if (!cls) { - console.warn(`Unknown context provider ${provider.name}`); - continue; - } - contextProviders.push(new cls(provider.params)); - } - - const config: ContinueConfig = { + const config: Config = { allowAnonymousTelemetry: initial.allowAnonymousTelemetry, - models, + models: initial.models, systemMessage: initial.systemMessage, completionOptions: initial.completionOptions, slashCommands, - contextProviders, + contextProviders: initial.contextProviders || [], retrievalSettings: initial.retrievalSettings, disableIndexing: initial.disableIndexing, }; @@ -55,4 +48,51 @@ function loadSerializedConfig( return config; } -export { loadSerializedConfig }; +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 */ +function intermediateToFinalConfig(config: Config): ContinueConfig { + const models: BaseLLM[] = []; + for (const desc of config.models) { + let llm: BaseLLM | undefined; + if (isModelDescription(desc)) { + llm = llmFromDescription(desc, config.completionOptions); + } else { + llm = new CustomLLMClass(desc); + } + if (!llm) continue; + models.push(llm); + } + + 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)); + } + } + + return { + ...config, + contextProviders, + models, + }; +} + +export { intermediateToFinalConfig, serializedToIntermediateConfig }; diff --git a/core/context/index.ts b/core/context/index.ts index dff6a563b..8ec77ef4e 100644 --- a/core/context/index.ts +++ b/core/context/index.ts @@ -1,15 +1,8 @@ -import { ContextItem } from "../llm/types"; +import { ContextItem, ContextProviderDescription, IContextProvider } from ".."; -export interface ContextProviderDescription { - title: string; - displayTitle: string; - description: string; - dynamic: boolean; - requiresQuery: boolean; -} - -export abstract class ContextProvider { +export abstract class BaseContextProvider implements IContextProvider { options: Object; + constructor(options: Object) { this.options = options; } diff --git a/core/context/providers/CustomContextProvider.ts b/core/context/providers/CustomContextProvider.ts new file mode 100644 index 000000000..0f742e498 --- /dev/null +++ b/core/context/providers/CustomContextProvider.ts @@ -0,0 +1,30 @@ +import { + ContextItem, + ContextProviderDescription, + CustomContextProvider, + IContextProvider, +} from "../.."; + +class CustomContextProviderClass implements IContextProvider { + custom: CustomContextProvider; + constructor(custom: CustomContextProvider) { + this.custom = custom; + } + + get description(): ContextProviderDescription { + return { + title: this.custom.title, + displayTitle: this.custom.displayTitle || this.custom.title, + description: this.custom.description || "", + dynamic: true, + requiresQuery: false, + }; + } + + async getContextItems(query: string): Promise { + return await this.custom.getContextItems(query); + } + async load(): Promise {} +} + +export default CustomContextProviderClass; diff --git a/core/context/providers/DiffContextProvider.ts b/core/context/providers/DiffContextProvider.ts index efcfbaff9..f0cd517f1 100644 --- a/core/context/providers/DiffContextProvider.ts +++ b/core/context/providers/DiffContextProvider.ts @@ -1,9 +1,9 @@ import { v4 } from "uuid"; -import { ContextProvider, ContextProviderDescription } from ".."; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; -class DiffContextProvider extends ContextProvider { +class DiffContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "diff", displayTitle: "Git Diff", diff --git a/core/context/providers/FileContextProvider.ts b/core/context/providers/FileContextProvider.ts index dd364e872..df0397300 100644 --- a/core/context/providers/FileContextProvider.ts +++ b/core/context/providers/FileContextProvider.ts @@ -1,8 +1,8 @@ -import { ContextProvider, ContextProviderDescription } from ".."; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; -class FileContextProvider extends ContextProvider { +class FileContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "file", displayTitle: "Files", diff --git a/core/context/providers/FileTreeContextProvider.ts b/core/context/providers/FileTreeContextProvider.ts index 118993f7a..076aac20d 100644 --- a/core/context/providers/FileTreeContextProvider.ts +++ b/core/context/providers/FileTreeContextProvider.ts @@ -1,6 +1,6 @@ -import { ContextProvider, ContextProviderDescription } from ".."; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; interface Directory { name: string; @@ -31,7 +31,7 @@ function formatFileTree(tree: Directory, indentation: string = ""): string { return result; } -class FileTreeContextProvider extends ContextProvider { +class FileTreeContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "tree", displayTitle: "File Tree", diff --git a/core/context/providers/GitHubIssuesContextProvider.ts b/core/context/providers/GitHubIssuesContextProvider.ts index ef0e1b383..8c28ae30e 100644 --- a/core/context/providers/GitHubIssuesContextProvider.ts +++ b/core/context/providers/GitHubIssuesContextProvider.ts @@ -1,8 +1,7 @@ -import { ContextProvider, ContextProviderDescription } from ".."; -import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; -class GitHubIssuesContextProvider extends ContextProvider { +class GitHubIssuesContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "github", displayTitle: "GitHub Issues", diff --git a/core/context/providers/GoogleContextProvider.ts b/core/context/providers/GoogleContextProvider.ts index f75bf7927..cf35d26c4 100644 --- a/core/context/providers/GoogleContextProvider.ts +++ b/core/context/providers/GoogleContextProvider.ts @@ -1,8 +1,7 @@ -import { ContextProvider, ContextProviderDescription } from ".."; -import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; -class GoogleContextProvider extends ContextProvider { +class GoogleContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "google", displayTitle: "Google", diff --git a/core/context/providers/TerminalContextProvider.ts b/core/context/providers/TerminalContextProvider.ts index fe4431dff..1dee4914b 100644 --- a/core/context/providers/TerminalContextProvider.ts +++ b/core/context/providers/TerminalContextProvider.ts @@ -1,9 +1,9 @@ import { v4 } from "uuid"; -import { ContextProvider, ContextProviderDescription } from ".."; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; import { ExtensionIde } from "../../ide"; -import { ContextItem } from "../../llm/types"; -class TerminalContextProvider extends ContextProvider { +class TerminalContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "terminal", displayTitle: "Terminal", diff --git a/core/context/providers/URLContextProvider.ts b/core/context/providers/URLContextProvider.ts index e1309c443..c78dcf08f 100644 --- a/core/context/providers/URLContextProvider.ts +++ b/core/context/providers/URLContextProvider.ts @@ -1,7 +1,7 @@ -import { ContextProvider, ContextProviderDescription } from ".."; -import { ContextItem } from "../../llm/types"; +import { BaseContextProvider } from ".."; +import { ContextItem, ContextProviderDescription } from "../.."; -class URLContextProvider extends ContextProvider { +class URLContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { title: "url", displayTitle: "URL", diff --git a/core/context/providers/index.ts b/core/context/providers/index.ts index daf96a2b1..05cb97a25 100644 --- a/core/context/providers/index.ts +++ b/core/context/providers/index.ts @@ -1,5 +1,5 @@ -import { ContextProvider } from ".."; -import { ContextProviderName } from "../../config"; +import { BaseContextProvider } from ".."; +import { ContextProviderName } from "../.."; import DiffContextProvider from "./DiffContextProvider"; import FileTreeContextProvider from "./FileTreeContextProvider"; import GitHubIssuesContextProvider from "./GitHubIssuesContextProvider"; @@ -7,7 +7,7 @@ import GoogleContextProvider from "./GoogleContextProvider"; import TerminalContextProvider from "./TerminalContextProvider"; import URLContextProvider from "./URLContextProvider"; -const Providers: (typeof ContextProvider)[] = [ +const Providers: (typeof BaseContextProvider)[] = [ DiffContextProvider, FileTreeContextProvider, GitHubIssuesContextProvider, @@ -18,7 +18,7 @@ const Providers: (typeof ContextProvider)[] = [ export function contextProviderClassFromName( name: ContextProviderName -): typeof ContextProvider | undefined { +): typeof BaseContextProvider | undefined { const cls = Providers.find((cls) => cls.description.title === name); if (!cls) { diff --git a/core/ide/filesystem.ts b/core/ide/filesystem.ts index 7adcf666e..c40f5b285 100644 --- a/core/ide/filesystem.ts +++ b/core/ide/filesystem.ts @@ -1,11 +1,10 @@ import * as fs from "fs"; -import { SerializedContinueConfig } from "../config"; +import { IDE, SerializedContinueConfig } from ".."; import { getConfigJsonPath, getConfigTsPath, getContinueGlobalPath, } from "../util/paths"; -import { IDE } from "./types"; class FileSystemIde implements IDE { async getSerializedConfig(): Promise { diff --git a/core/ide/index.ts b/core/ide/index.ts index f9a2b02c4..e145f2de1 100644 --- a/core/ide/index.ts +++ b/core/ide/index.ts @@ -1,10 +1,10 @@ +import { IDE, SerializedContinueConfig } from "../index"; import { ideRequest } from "./messaging"; -import { IDE } from "./types"; async function r(messageType: string, options: any = {}) { return await ideRequest(messageType, options); } export class ExtensionIde implements IDE { - async getSerializedConfig() { + async getSerializedConfig(): Promise { return await r("getSerializedConfig"); } diff --git a/core/ide/types.d.ts b/core/ide/types.d.ts deleted file mode 100644 index 6d1fb5b2f..000000000 --- a/core/ide/types.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { SerializedContinueConfig } from "../config"; - -interface IDE { - getSerializedConfig(): Promise; - getConfigJsUrl(): Promise; - getDiff(): Promise; - getTerminalContents(): Promise; - listWorkspaceContents(): Promise; - getWorkspaceDir(): Promise; - writeFile(path: string, contents: string): Promise; - showVirtualFile(title: string, contents: string): Promise; - getContinueDir(): Promise; - openFile(path: string): Promise; - runCommand(command: string): Promise; - saveFile(filepath: string): Promise; - readFile(filepath: string): Promise; - showDiff( - filepath: string, - newContents: string, - stepIndex: number - ): Promise; -} - -export { IDE }; diff --git a/core/index.d.ts b/core/index.d.ts new file mode 100644 index 000000000..45c849f7e --- /dev/null +++ b/core/index.d.ts @@ -0,0 +1,455 @@ +export interface ILLM extends LLMOptions { + get providerName(): ModelProvider; + + uniqueId: string; + model: string; + + title?: string; + systemMessage?: string; + contextLength: number; + completionOptions: CompletionOptions; + requestOptions?: RequestOptions; + promptTemplates?: Record; + templateMessages?: (messages: ChatMessage[]) => string; + writeLog?: (str: string) => Promise; + llmRequestHook?: (model: string, prompt: string) => any; + apiKey?: string; + apiBase?: string; + + engine?: string; + apiVersion?: string; + apiType?: string; + region?: string; + projectId?: string; + + complete(prompt: string, options?: LLMFullCompletionOptions): Promise; + + streamComplete( + prompt: string, + options?: LLMFullCompletionOptions + ): AsyncGenerator; + + streamChat( + messages: ChatMessage[], + options?: LLMFullCompletionOptions + ): AsyncGenerator; + + countTokens(text: string): number; +} + +export interface ContextProviderDescription { + title: string; + displayTitle: string; + description: string; + dynamic: boolean; + requiresQuery: boolean; +} + +export interface CustomContextProvider { + title: string; + displayTitle?: string; + description?: string; + getContextItems(query: string): Promise; +} + +export interface IContextProvider { + get description(): ContextProviderDescription; + + getContextItems(query: string): Promise; +} + +export interface PersistedSessionInfo { + history: ChatHistory; + title: string; + workspaceDirectory: string; + sessionId: string; +} + +export interface SessionInfo { + sessionId: string; + title: string; + dateCreated: string; + workspaceDirectory: string; +} + +export interface RangeInFile { + filepath: string; + range: Range; +} + +export interface Range { + start: Position; + end: Position; +} +export interface Position { + line: number; + character: number; +} +export interface FileEdit { + filepath: string; + range: Range; + replacement: string; +} + +export interface ContinueError { + title: string; + message: string; +} + +export interface CompletionOptions { + model: string; + + maxTokens: number; + temperature?: number; + topP?: number; + topK?: number; + presencePenalty?: number; + frequencyPenalty?: number; + stop?: string[]; +} + +export type ChatMessageRole = "user" | "assistant" | "system"; + +export interface ChatMessage { + role: ChatMessageRole; + content: string; +} + +export interface ContextItemId { + providerTitle: string; + itemId: string; +} + +export interface ContextItem { + content: string; + name: string; + description: string; + id: ContextItemId; + editing?: boolean; + editable?: boolean; +} + +export interface ChatHistoryItem { + message: ChatMessage; + contextItems: ContextItem[]; + promptLogs?: [string, string][]; // [prompt, completion] +} + +export type ChatHistory = ChatHistoryItem[]; + +// LLM + +export interface LLMFullCompletionOptions { + raw?: boolean; + log?: boolean; + + model?: string; + + temperature?: number; + topP?: number; + topK?: number; + presencePenalty?: number; + frequencyPenalty?: number; + stop?: string[]; + maxTokens?: number; +} +export interface LLMOptions { + model: string; + + title?: string; + uniqueId?: string; + systemMessage?: string; + contextLength?: number; + completionOptions?: CompletionOptions; + requestOptions?: RequestOptions; + promptTemplates?: Record; + templateMessages?: (messages: ChatMessage[]) => string; + writeLog?: (str: string) => Promise; + llmRequestHook?: (model: string, prompt: string) => any; + apiKey?: string; + apiBase?: string; + + // Azure options + engine?: string; + apiVersion?: string; + apiType?: string; + + // GCP Options + region?: string; + projectId?: string; +} +type RequireAtLeastOne = Pick< + T, + Exclude +> & + { + [K in Keys]-?: Required> & Partial>>; + }[Keys]; + +export interface CustomLLMWithOptionals { + options?: LLMOptions; + streamCompletion?: ( + prompt: string, + options: CompletionOptions + ) => AsyncGenerator; + streamChat?: ( + messages: ChatMessage[], + options: CompletionOptions + ) => AsyncGenerator; +} + +/** + * The LLM interface requires you to specify either `streamCompletion` or `streamChat` (or both). + */ +export type CustomLLM = RequireAtLeastOne< + CustomLLMWithOptionals, + "streamCompletion" | "streamChat" +>; + +// IDE + +export interface IDE { + getSerializedConfig(): Promise; + getConfigJsUrl(): Promise; + getDiff(): Promise; + getTerminalContents(): Promise; + listWorkspaceContents(): Promise; + getWorkspaceDir(): Promise; + writeFile(path: string, contents: string): Promise; + showVirtualFile(title: string, contents: string): Promise; + getContinueDir(): Promise; + openFile(path: string): Promise; + runCommand(command: string): Promise; + saveFile(filepath: string): Promise; + readFile(filepath: string): Promise; + showDiff( + filepath: string, + newContents: string, + stepIndex: number + ): Promise; +} + +// Slash Commands + +export interface ContinueSDK { + ide: IDE; + llm: ILLM; + addContextItem: (item: ContextItem) => void; + history: ChatMessage[]; + input: string; + params?: any; + contextItems: ContextItem[]; +} + +export interface SlashCommand { + name: string; + description: string; + params?: { [key: string]: any }; + run: (sdk: ContinueSDK) => AsyncGenerator; +} + +// Config + +type StepName = + | "AnswerQuestionChroma" + | "GenerateShellCommandStep" + | "EditHighlightedCodeStep" + | "ShareSessionStep" + | "CommentCodeStep" + | "ClearHistoryStep" + | "StackOverflowStep" + | "OpenConfigStep" + | "GenerateShellCommandStep" + | "DraftIssueStep"; + +type ContextProviderName = + | "diff" + | "github" + | "terminal" + | "open" + | "google" + | "search" + | "url" + | "tree"; + +type TemplateType = + | "llama2" + | "alpaca" + | "zephyr" + | "phind" + | "anthropic" + | "chatml" + | "deepseek"; + +type ModelProvider = + | "openai" + | "openai-free-trial" + | "openai-aiohttp" + | "anthropic" + | "together" + | "ollama" + | "huggingface-tgi" + | "huggingface-inference-api" + | "llama.cpp" + | "replicate" + | "text-gen-webui" + | "google-palm" + | "google-palm-real" + | "lmstudio" + | "llamafile" + | "gemini" + | "mistral"; + +export type ModelName = + // OpenAI + | "gpt-3.5-turbo" + | "gpt-3.5-turbo-16k" + | "gpt-4" + | "gpt-3.5-turbo-0613" + | "gpt-4-32k" + | "gpt-4-1106-preview" + // Open Source + | "mistral-7b" + | "mistral-8x7b" + | "llama2-7b" + | "llama2-13b" + | "codellama-7b" + | "codellama-13b" + | "codellama-34b" + | "phind-codellama-34b" + | "wizardcoder-7b" + | "wizardcoder-13b" + | "wizardcoder-34b" + | "zephyr-7b" + | "codeup-13b" + | "deepseek-1b" + | "deepseek-7b" + | "deepseek-33b" + // Anthropic + | "claude-2" + // Google PaLM + | "chat-bison-001" + // Gemini + | "gemini-pro"; + +export interface RequestOptions { + timeout?: number; + verifySsl?: boolean; + caBundlePath: string; + proxy?: string; + headers?: Record; +} + +export interface StepWithParams { + name: StepName; + params: { [key: string]: any }; +} + +export interface ContextProviderWithParams { + name: ContextProviderName; + params: { [key: string]: any }; +} + +export interface SlashCommandDescription { + name: string; + description: string; + step: StepName | string; + params?: { [key: string]: any }; +} + +export interface CustomCommand { + name: string; + prompt: string; + description: string; +} +export interface RetrievalSettings { + nRetrieve?: number; + nFinal?: number; + useReranking: boolean; + rerankGroupSize: number; + ignoreFiles: string[]; + openaiApiKey?: string; + apiBase?: string; + apiType?: string; + apiVersion?: string; + organizationId?: string; +} + +interface BaseCompletionOptions { + temperature?: number; + topP?: number; + topK?: number; + presencePenalty?: number; + frequencyPenalty?: number; + stop?: string[]; + maxTokens: number; +} + +export interface ModelDescription { + title: string; + provider: ModelProvider; + model: string; + apiKey?: string; + apiBase?: string; + contextLength?: number; + template?: TemplateType; + completionOptions?: BaseCompletionOptions; + systemMessage?: string; + requestOptions?: RequestOptions; +} + +export interface ModelRoles { + default: string; + chat?: string; + edit?: string; + summarize?: string; +} + +export interface SerializedContinueConfig { + disallowedSteps?: string[]; + allowAnonymousTelemetry?: boolean; + models: ModelDescription[]; + modelRoles: ModelRoles; + systemMessage?: string; + completionOptions?: BaseCompletionOptions; + slashCommands?: SlashCommandDescription[]; + customCommands?: CustomCommand[]; + contextProviders?: ContextProviderWithParams[]; + retrievalSettings?: RetrievalSettings; + disableIndexing?: boolean; +} + +export interface Config { + /** If set to true, Continue will collect anonymous usage data to improve the product. If set to false, we will collect nothing. Read here to learn more: https://continue.dev/docs/telemetry */ + allowAnonymousTelemetry?: boolean; + /** Each entry in this array will originally be a ModelDescription, the same object from your config.json, but you may add CustomLLMs. + * A CustomLLM requires you only to define an AsyncGenerator that calls the LLM and yields string updates. You can choose to define either `streamCompletion` or `streamChat` (or both). + * Continue will do the rest of the work to construct prompt templates, handle context items, prune context, etc. + */ + models: (CustomLLM | ModelDescription)[]; + /** A system message to be followed by all of your models */ + systemMessage?: string; + /** The default completion options for all models */ + completionOptions?: BaseCompletionOptions; + /** The list of slash commands that will be available in the sidebar */ + slashCommands?: SlashCommand[]; + /** Each entry in this array will originally be a ContextProviderWithParams, the same object from your config.json, but you may add CustomContextProviders. + * A CustomContextProvider requires you only to define a title and getContextItems function. When you type '@title ', Continue will call `getContextItems(query)`. + */ + contextProviders?: (CustomContextProvider | ContextProviderWithParams)[]; + /** Settings related to the /codebase retrieval feature */ + retrievalSettings?: RetrievalSettings; + /** If set to true, Continue will not index your codebase for retrieval */ + disableIndexing?: boolean; +} + +export interface ContinueConfig { + allowAnonymousTelemetry?: boolean; + models: ILLM[]; + systemMessage?: string; + completionOptions?: BaseCompletionOptions; + slashCommands?: SlashCommand[]; + contextProviders?: IContextProvider[]; + retrievalSettings?: RetrievalSettings; + disableIndexing?: boolean; +} diff --git a/core/llm/constructMessages.ts b/core/llm/constructMessages.ts index bd14802f1..0074ccb5e 100644 --- a/core/llm/constructMessages.ts +++ b/core/llm/constructMessages.ts @@ -1,4 +1,4 @@ -import { ChatHistory, ChatMessage } from "./types"; +import { ChatHistory, ChatMessage } from ".."; export function constructMessages(history: ChatHistory): ChatMessage[] { const msgs: ChatMessage[] = []; diff --git a/core/llm/countTokens.ts b/core/llm/countTokens.ts index aafbeb425..4f2f24eb9 100644 --- a/core/llm/countTokens.ts +++ b/core/llm/countTokens.ts @@ -3,8 +3,8 @@ import { Tiktoken, TiktokenModel, } from "js-tiktoken"; +import { ChatMessage } from ".."; import { TOKEN_BUFFER_FOR_SAFETY } from "./constants"; -import { ChatMessage } from "./types"; function renderTemplatedString(template: string): string { // TODO diff --git a/core/llm/index.ts b/core/llm/index.ts index d04ea82f0..09c662ec2 100644 --- a/core/llm/index.ts +++ b/core/llm/index.ts @@ -1,4 +1,13 @@ -import { ModelProvider, RequestOptions, TemplateType } from "../config"; +import { + ChatMessage, + CompletionOptions, + ILLM, + LLMFullCompletionOptions, + LLMOptions, + ModelProvider, + RequestOptions, + TemplateType, +} from ".."; import { CONTEXT_LENGTH_FOR_MODEL, DEFAULT_ARGS } from "./constants"; import { compileChatMessages, @@ -22,7 +31,6 @@ import { simplestEditPrompt, zephyrEditPrompt, } from "./templates/edit"; -import { ChatMessage, CompletionOptions } from "./types"; function autodetectTemplateType(model: string): TemplateType | undefined { const lower = model.toLowerCase(); @@ -120,53 +128,12 @@ function autodetectPromptTemplates( return templates; } -export interface LLMOptions { - model: string; - - title?: string; - uniqueId?: string; - systemMessage?: string; - contextLength?: number; - completionOptions?: CompletionOptions; - requestOptions?: RequestOptions; - promptTemplates?: Record; - templateMessages?: (messages: ChatMessage[]) => string; - writeLog?: (str: string) => Promise; - llmRequestHook?: (model: string, prompt: string) => any; - apiKey?: string; - apiBase?: string; - - // Azure options - engine?: string; - apiVersion?: string; - apiType?: string; - - // GCP Options - region?: string; - projectId?: string; -} - -interface LLMFullCompletionOptions { - raw?: boolean; - log?: boolean; - - model?: string; - - temperature?: number; - topP?: number; - topK?: number; - presencePenalty?: number; - frequencyPenalty?: number; - stop?: string[]; - maxTokens?: number; -} - -export abstract class LLM implements LLMOptions { +export abstract class BaseLLM implements ILLM { static providerName: ModelProvider; - static defaultOptions: Partial | undefined; + static defaultOptions: Partial | undefined = undefined; get providerName(): ModelProvider { - return (this.constructor as typeof LLM).providerName; + return (this.constructor as typeof BaseLLM).providerName; } uniqueId: string; @@ -193,8 +160,8 @@ export abstract class LLM implements LLMOptions { constructor(options: LLMOptions) { // Set default options options = { - title: (this.constructor as typeof LLM).providerName, - ...(this.constructor as typeof LLM).defaultOptions, + title: (this.constructor as typeof BaseLLM).providerName, + ...(this.constructor as typeof BaseLLM).defaultOptions, ...options, }; diff --git a/core/llm/llms/Anthropic.ts b/core/llm/llms/Anthropic.ts index 6716e01d7..0cca96996 100644 --- a/core/llm/llms/Anthropic.ts +++ b/core/llm/llms/Anthropic.ts @@ -1,11 +1,10 @@ // import AnthropicClient from "@anthropic-ai/sdk"; // import { CompletionCreateParamsBase } from "@anthropic-ai/sdk/resources/completions"; -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; import { anthropicTemplateMessages } from "../templates/chat"; -import { CompletionOptions } from "../types"; -class Anthropic extends LLM { +class Anthropic extends BaseLLM { static providerName: ModelProvider = "anthropic"; static defaultOptions: Partial = { model: "claude-2", diff --git a/core/llm/llms/CustomLLM.ts b/core/llm/llms/CustomLLM.ts new file mode 100644 index 000000000..55ae18894 --- /dev/null +++ b/core/llm/llms/CustomLLM.ts @@ -0,0 +1,55 @@ +import { BaseLLM } from ".."; +import { ChatMessage, CompletionOptions, CustomLLM } from "../.."; + +class CustomLLMClass extends BaseLLM { + private customStreamCompletion?: ( + prompt: string, + options: CompletionOptions + ) => AsyncGenerator; + + private customStreamChat?: ( + messages: ChatMessage[], + options: CompletionOptions + ) => AsyncGenerator; + + constructor(custom: CustomLLM) { + super(custom.options || { model: "custom" }); + this.customStreamCompletion = custom.streamCompletion; + this.customStreamChat = custom.streamChat; + } + + protected async *_streamChat( + messages: ChatMessage[], + options: CompletionOptions + ): AsyncGenerator { + if (this.customStreamChat) { + for await (const content of this.customStreamChat(messages, options)) { + yield { role: "assistant", content }; + } + } else { + for await (const update of super._streamChat(messages, options)) { + yield update; + } + } + } + + protected async *_streamComplete( + prompt: string, + options: CompletionOptions + ): AsyncGenerator { + if (this.customStreamCompletion) { + for await (const content of this.customStreamCompletion( + prompt, + options + )) { + yield content; + } + } else { + for await (const content of super._streamComplete(prompt, options)) { + yield content; + } + } + } +} + +export default CustomLLMClass; diff --git a/core/llm/llms/FreeTrial.ts b/core/llm/llms/FreeTrial.ts index 95669513e..c1cd9686c 100644 --- a/core/llm/llms/FreeTrial.ts +++ b/core/llm/llms/FreeTrial.ts @@ -1,11 +1,10 @@ -import { LLM } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { ChatMessage, CompletionOptions, ModelProvider } from "../.."; // const SERVER_URL = "http://localhost:8080"; const SERVER_URL = "https://proxy-server-l6vsfbzhba-uw.a.run.app"; -class FreeTrial extends LLM { +class FreeTrial extends BaseLLM { static providerName: ModelProvider = "openai-free-trial"; private _getHeaders() { diff --git a/core/llm/llms/Gemini.ts b/core/llm/llms/Gemini.ts index 0e8ad731c..0156edd7e 100644 --- a/core/llm/llms/Gemini.ts +++ b/core/llm/llms/Gemini.ts @@ -1,8 +1,12 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; -class Gemini extends LLM { +class Gemini extends BaseLLM { static providerName: ModelProvider = "gemini"; static defaultOptions: Partial = { diff --git a/core/llm/llms/GooglePalm.ts b/core/llm/llms/GooglePalm.ts index 04fb0a40e..d8cc457a6 100644 --- a/core/llm/llms/GooglePalm.ts +++ b/core/llm/llms/GooglePalm.ts @@ -1,8 +1,12 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; -class GooglePalm extends LLM { +class GooglePalm extends BaseLLM { static providerName: ModelProvider = "google-palm-real"; static defaultOptions: Partial = { diff --git a/core/llm/llms/GooglePalmProxy.ts b/core/llm/llms/GooglePalmProxy.ts index e335a231b..6582698a5 100644 --- a/core/llm/llms/GooglePalmProxy.ts +++ b/core/llm/llms/GooglePalmProxy.ts @@ -1,9 +1,13 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; +import { BaseLLM } from ".."; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; import { ideRequest } from "../../ide/messaging"; -import { ChatMessage, CompletionOptions } from "../types"; -class GooglePalmProxy extends LLM { +class GooglePalmProxy extends BaseLLM { static providerName: ModelProvider = "google-palm"; static defaultOptions: Partial = { model: "chat-bison-001", diff --git a/core/llm/llms/HuggingFaceInferenceAPI.ts b/core/llm/llms/HuggingFaceInferenceAPI.ts index f878a7537..51acf308d 100644 --- a/core/llm/llms/HuggingFaceInferenceAPI.ts +++ b/core/llm/llms/HuggingFaceInferenceAPI.ts @@ -1,8 +1,7 @@ -import { LLM } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { ChatMessage, CompletionOptions, ModelProvider } from "../.."; -class HuggingFaceInferenceAPI extends LLM { +class HuggingFaceInferenceAPI extends BaseLLM { static providerName: ModelProvider = "huggingface-inference-api"; private _convertArgs(options: CompletionOptions, prompt: string) { diff --git a/core/llm/llms/HuggingFaceTGI.ts b/core/llm/llms/HuggingFaceTGI.ts index 49dd8034f..c67760069 100644 --- a/core/llm/llms/HuggingFaceTGI.ts +++ b/core/llm/llms/HuggingFaceTGI.ts @@ -1,8 +1,7 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -class HuggingFaceTGI extends LLM { +class HuggingFaceTGI extends BaseLLM { static providerName: ModelProvider = "huggingface-tgi"; static defaultOptions: Partial = { apiBase: "http://localhost:8080", diff --git a/core/llm/llms/LMStudio.ts b/core/llm/llms/LMStudio.ts index 083303d10..4279abaf1 100644 --- a/core/llm/llms/LMStudio.ts +++ b/core/llm/llms/LMStudio.ts @@ -1,5 +1,4 @@ -import { LLMOptions } from ".."; -import { ModelProvider } from "../../config"; +import { LLMOptions, ModelProvider } from "../.."; import OpenAI from "./OpenAI"; class LMStudio extends OpenAI { diff --git a/core/llm/llms/LlamaCpp.ts b/core/llm/llms/LlamaCpp.ts index f5090e6b2..60da57cfe 100644 --- a/core/llm/llms/LlamaCpp.ts +++ b/core/llm/llms/LlamaCpp.ts @@ -1,8 +1,7 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -class LlamaCpp extends LLM { +class LlamaCpp extends BaseLLM { static providerName: ModelProvider = "llama.cpp"; static defaultOptions: Partial = { apiBase: "http://127.0.0.1:8080", diff --git a/core/llm/llms/Llamafile.ts b/core/llm/llms/Llamafile.ts index be5ad40c9..f22ec3ba7 100644 --- a/core/llm/llms/Llamafile.ts +++ b/core/llm/llms/Llamafile.ts @@ -1,4 +1,4 @@ -import { ModelProvider } from "../../config"; +import { ModelProvider } from "../.."; import LlamaCpp from "./LlamaCpp"; class Llamafile extends LlamaCpp { diff --git a/core/llm/llms/Mistral.ts b/core/llm/llms/Mistral.ts index 05d2305eb..f07ab5263 100644 --- a/core/llm/llms/Mistral.ts +++ b/core/llm/llms/Mistral.ts @@ -1,5 +1,4 @@ -import { LLMOptions } from ".."; -import { ModelProvider } from "../../config"; +import { LLMOptions, ModelProvider } from "../.."; import OpenAI from "./OpenAI"; class Mistral extends OpenAI { diff --git a/core/llm/llms/Ollama.ts b/core/llm/llms/Ollama.ts index 0b594f8bf..38d698dba 100644 --- a/core/llm/llms/Ollama.ts +++ b/core/llm/llms/Ollama.ts @@ -1,8 +1,7 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -class Ollama extends LLM { +class Ollama extends BaseLLM { static providerName: ModelProvider = "ollama"; static defaultOptions: Partial = { apiBase: "http://localhost:11434", diff --git a/core/llm/llms/OpenAI.ts b/core/llm/llms/OpenAI.ts index b218b7f37..54e41e6dd 100644 --- a/core/llm/llms/OpenAI.ts +++ b/core/llm/llms/OpenAI.ts @@ -1,8 +1,13 @@ import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions"; -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; -class OpenAI extends LLM { +import { BaseLLM } from ".."; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; + +class OpenAI extends BaseLLM { static providerName: ModelProvider = "openai"; static defaultOptions: Partial = { apiBase: "https://api.openai.com", diff --git a/core/llm/llms/Replicate.ts b/core/llm/llms/Replicate.ts index c87d1ccdf..4f0ada041 100644 --- a/core/llm/llms/Replicate.ts +++ b/core/llm/llms/Replicate.ts @@ -1,9 +1,13 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; import ReplicateClient from "replicate"; +import { BaseLLM } from ".."; +import { + ChatMessage, + CompletionOptions, + LLMOptions, + ModelProvider, +} from "../.."; -class Replicate extends LLM { +class Replicate extends BaseLLM { private static MODEL_IDS: { [name: string]: `${string}/${string}:${string}`; } = { diff --git a/core/llm/llms/TextGenWebUI.ts b/core/llm/llms/TextGenWebUI.ts index 75dd47053..be68dc752 100644 --- a/core/llm/llms/TextGenWebUI.ts +++ b/core/llm/llms/TextGenWebUI.ts @@ -1,8 +1,7 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { ChatMessage, CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -class TextGenWebUI extends LLM { +class TextGenWebUI extends BaseLLM { static providerName: ModelProvider = "text-gen-webui"; static defaultOptions: Partial = { apiBase: "http://localhost:5000", diff --git a/core/llm/llms/Together.ts b/core/llm/llms/Together.ts index 04a100d80..768cd6c1d 100644 --- a/core/llm/llms/Together.ts +++ b/core/llm/llms/Together.ts @@ -1,8 +1,7 @@ -import { LLM, LLMOptions } from ".."; -import { ModelProvider } from "../../config"; -import { CompletionOptions } from "../types"; +import { BaseLLM } from ".."; +import { CompletionOptions, LLMOptions, ModelProvider } from "../.."; -class Together extends LLM { +class Together extends BaseLLM { static providerName: ModelProvider = "together"; static defaultOptions: Partial = { apiBase: "https://api.together.xyz", diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 7a531c175..3cbc722b0 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -1,5 +1,5 @@ -import { LLM, LLMOptions } from ".."; -import { BaseCompletionOptions, ModelDescription } from "../../config"; +import { BaseLLM } from ".."; +import { BaseCompletionOptions, LLMOptions, ModelDescription } from "../.."; import Anthropic from "./Anthropic"; import FreeTrial from "./FreeTrial"; import Gemini from "./Gemini"; @@ -37,7 +37,7 @@ const LLMs = [ export function llmFromDescription( desc: ModelDescription, completionOptions?: BaseCompletionOptions -): LLM | undefined { +): BaseLLM | undefined { const cls = LLMs.find((llm) => llm.providerName === desc.provider); if (!cls) { diff --git a/core/llm/templates/chat.ts b/core/llm/templates/chat.ts index 86b4e5630..55f0c8d2e 100644 --- a/core/llm/templates/chat.ts +++ b/core/llm/templates/chat.ts @@ -1,4 +1,4 @@ -import { ChatMessage } from "../types"; +import { ChatMessage } from "../.."; function llama2TemplateMessages(msgs: ChatMessage[]): string { if (msgs.length === 0) { @@ -160,11 +160,11 @@ function phindTemplateMessages(msgs: ChatMessage[]): string { } export { - llama2TemplateMessages, anthropicTemplateMessages, - zephyrTemplateMessages, chatmlTemplateMessages, - templateAlpacaMessages, deepseekTemplateMessages, + llama2TemplateMessages, phindTemplateMessages, + templateAlpacaMessages, + zephyrTemplateMessages, }; diff --git a/core/llm/types.d.ts b/core/llm/types.d.ts deleted file mode 100644 index 8ff71e2d8..000000000 --- a/core/llm/types.d.ts +++ /dev/null @@ -1,50 +0,0 @@ -interface CompletionOptions { - model: string; - - maxTokens: number; - temperature?: number; - topP?: number; - topK?: number; - presencePenalty?: number; - frequencyPenalty?: number; - stop?: string[]; -} - -type ChatMessageRole = "user" | "assistant" | "system"; - -interface ChatMessage { - role: ChatMessageRole; - content: string; -} - -interface ContextItemId { - providerTitle: string; - itemId: string; -} - -interface ContextItem { - content: string; - name: string; - description: string; - id: ContextItemId; - editing?: boolean; - editable?: boolean; -} - -interface ChatHistoryItem { - message: ChatMessage; - contextItems: ContextItem[]; - promptLogs?: [string, string][]; // [prompt, completion] -} - -type ChatHistory = ChatHistoryItem[]; - -export { - ChatHistory, - ChatHistoryItem, - ChatMessage, - ChatMessageRole, - CompletionOptions, - ContextItem, - ContextItemId, -}; diff --git a/core/types.d.ts b/core/types.d.ts deleted file mode 100644 index 343248118..000000000 --- a/core/types.d.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { ChatHistory } from "./llm/types"; - -export interface PersistedSessionInfo { - history: ChatHistory; - title: string; - workspaceDirectory: string; - sessionId: string; -} - -export interface SessionInfo { - sessionId: string; - title: string; - dateCreated: string; - workspaceDirectory: string; -} - -export interface RangeInFile { - filepath: string; - range: Range; -} - -export interface Range { - start: Position; - end: Position; -} -export interface Position { - line: number; - character: number; -} -export interface FileEdit { - filepath: string; - range: Range; - replacement: string; -} - -export interface ContinueError { - title: string; - message: string; -} diff --git a/core/util/index.ts b/core/util/index.ts index 58c9d5f9f..b03717430 100644 --- a/core/util/index.ts +++ b/core/util/index.ts @@ -1,5 +1,5 @@ import Handlebars from "handlebars"; -import { ChatMessage } from "../llm/types"; +import { ChatMessage } from ".."; export function removeQuotesAndEscapes(output: string): string { output = output.trim(); diff --git a/core/util/paths.ts b/core/util/paths.ts index 112918c05..47adf0a02 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; -import { SerializedContinueConfig } from "../config"; +import { SerializedContinueConfig } from ".."; import defaultConfig from "../config/default"; export function getContinueGlobalPath(): string { diff --git a/extensions/vscode/esbuild.mjs b/extensions/vscode/esbuild.mjs index 58ea0c281..08631eb7b 100644 --- a/extensions/vscode/esbuild.mjs +++ b/extensions/vscode/esbuild.mjs @@ -5,7 +5,7 @@ await esbuild.build({ entryPoints: ["src/extension.ts"], bundle: true, outfile: "out/extension.js", - external: ["vscode"], + external: ["vscode", "esbuild"], format: "cjs", platform: "node", sourcemap: true, diff --git a/extensions/vscode/src/activation/activate.ts b/extensions/vscode/src/activation/activate.ts index ff51aef06..07bd57cd3 100644 --- a/extensions/vscode/src/activation/activate.ts +++ b/extensions/vscode/src/activation/activate.ts @@ -99,15 +99,6 @@ function showRefactorMigrationMessage() { export async function activateExtension(context: vscode.ExtensionContext) { extensionContext = context; - try { - console.log( - "In workspace: ", - vscode.workspace.workspaceFolders?.[0].uri.fsPath - ); - } catch (e) { - console.log("Error getting workspace folder: ", e); - } - console.log("Window ID: ", windowId); // Register commands and providers registerAllCodeLensProviders(context); diff --git a/extensions/vscode/src/continueIdeClient.ts b/extensions/vscode/src/continueIdeClient.ts index 6cbe1de57..f84b130f4 100644 --- a/extensions/vscode/src/continueIdeClient.ts +++ b/extensions/vscode/src/continueIdeClient.ts @@ -1,4 +1,4 @@ -import { FileEdit, RangeInFile } from "core/types"; +import { FileEdit, RangeInFile } from "core"; import { getConfigJsonPath } from "core/util/paths"; import { readFileSync } from "fs"; import * as vscode from "vscode"; @@ -44,7 +44,9 @@ class IdeProtocolClient { if ( filepath.endsWith(".continue/config.json") || - filepath.endsWith(".continue\\config.json") + filepath.endsWith(".continue\\config.json") || + filepath.endsWith(".continue/config.ts") || + filepath.endsWith(".continue\\config.ts") ) { const config = readFileSync(getConfigJsonPath(), "utf8"); const configJson = JSON.parse(config); diff --git a/extensions/vscode/src/debugPanel.ts b/extensions/vscode/src/debugPanel.ts index f99e54020..f9f569eac 100644 --- a/extensions/vscode/src/debugPanel.ts +++ b/extensions/vscode/src/debugPanel.ts @@ -1,6 +1,5 @@ -import { ModelDescription } from "core/config"; +import { FileEdit, ModelDescription } from "core"; import { llmFromDescription } from "core/llm/llms"; -import { FileEdit } from "core/types"; import { editConfigJson, getConfigJsonPath, diff --git a/extensions/vscode/src/history.ts b/extensions/vscode/src/history.ts index 0b2bc905a..d1126db01 100644 --- a/extensions/vscode/src/history.ts +++ b/extensions/vscode/src/history.ts @@ -1,4 +1,4 @@ -import { PersistedSessionInfo, SessionInfo } from "core/types"; +import { PersistedSessionInfo, SessionInfo } from "core"; import { getSessionFilePath, getSessionsListPath } from "core/util/paths"; import * as fs from "fs"; diff --git a/extensions/vscode/src/ideProtocol.ts b/extensions/vscode/src/ideProtocol.ts index 04c698ad2..8bd809425 100644 --- a/extensions/vscode/src/ideProtocol.ts +++ b/extensions/vscode/src/ideProtocol.ts @@ -1,7 +1,7 @@ import defaultConfig from "core/config/default"; -import { SerializedContinueConfig } from "core/config/index"; -import { IDE } from "core/ide/types"; + import { + getConfigJsPath, getConfigJsonPath, getConfigTsPath, getContinueGlobalPath, @@ -11,6 +11,9 @@ import * as fs from "fs"; import * as vscode from "vscode"; import { ideProtocolClient } from "./activation/activate"; +import { IDE, SerializedContinueConfig } from "core"; +import esbuild from "esbuild"; + class VsCodeIde implements IDE { async getSerializedConfig(): Promise { try { @@ -57,18 +60,19 @@ class VsCodeIde implements IDE { return undefined; } - // const result = await esbuild.build({ - // entryPoints: [getConfigTsPath()], - // bundle: true, - // platform: "browser", - // outfile: getConfigJsPath(), - // external: ["esbuild"], - // }); + const result = await esbuild.build({ + entryPoints: [getConfigTsPath()], + bundle: true, + platform: "browser", + format: "esm", + outfile: getConfigJsPath(), + external: ["fetch"], + }); - // const configJsString = fs.readFileSync(getConfigJsPath(), "utf8"); + const configJsString = fs.readFileSync(getConfigJsPath(), "utf8"); - // var dataUrl = "data:text/javascript;base64," + btoa(configJsString); - // return dataUrl; + var dataUrl = "data:text/javascript;base64," + btoa(configJsString); + return dataUrl; // try { // // Use tsc to compile config.ts to config.js. Spawn a child process to do this diff --git a/gui/src/components/dialogs/AddContextGroupDialog.tsx b/gui/src/components/dialogs/AddContextGroupDialog.tsx index c42b80429..5061c4056 100644 --- a/gui/src/components/dialogs/AddContextGroupDialog.tsx +++ b/gui/src/components/dialogs/AddContextGroupDialog.tsx @@ -1,4 +1,4 @@ -import { ContextItem } from "core/llm/types"; +import { ContextItem } from "core"; import { useDispatch } from "react-redux"; import { Button, Input } from ".."; import { diff --git a/gui/src/components/gui/ErrorStepContainer.tsx b/gui/src/components/gui/ErrorStepContainer.tsx index 65996b142..5eb353831 100644 --- a/gui/src/components/gui/ErrorStepContainer.tsx +++ b/gui/src/components/gui/ErrorStepContainer.tsx @@ -1,5 +1,5 @@ import { MinusCircleIcon, XMarkIcon } from "@heroicons/react/24/outline"; -import { ContinueError } from "core/types"; +import { ContinueError } from "core"; import styled from "styled-components"; import { defaultBorderRadius, vscBackground } from ".."; import HeaderButtonWithText from "../HeaderButtonWithText"; diff --git a/gui/src/components/gui/StepContainer.tsx b/gui/src/components/gui/StepContainer.tsx index 3fd303ead..b200f9f47 100644 --- a/gui/src/components/gui/StepContainer.tsx +++ b/gui/src/components/gui/StepContainer.tsx @@ -2,7 +2,7 @@ import { HandThumbDownIcon, HandThumbUpIcon, } from "@heroicons/react/24/outline"; -import { ChatHistoryItem } from "core/llm/types"; +import { ChatHistoryItem } from "core"; import { useEffect, useRef, useState } from "react"; import { useSelector } from "react-redux"; import styled from "styled-components"; diff --git a/gui/src/components/gui/TimelineItem.tsx b/gui/src/components/gui/TimelineItem.tsx index d4f3cbb2a..3796a4cd9 100644 --- a/gui/src/components/gui/TimelineItem.tsx +++ b/gui/src/components/gui/TimelineItem.tsx @@ -1,5 +1,5 @@ import { ChatBubbleOvalLeftIcon } from "@heroicons/react/24/outline"; -import { ChatHistoryItem } from "core/llm/types"; +import { ChatHistoryItem } from "core"; import styled from "styled-components"; import { lightGray, vscBackground } from ".."; import { getFontSize } from "../../util"; diff --git a/gui/src/components/mainInput/ComboBox.tsx b/gui/src/components/mainInput/ComboBox.tsx index 2c3b99c9c..6e225d3ad 100644 --- a/gui/src/components/mainInput/ComboBox.tsx +++ b/gui/src/components/mainInput/ComboBox.tsx @@ -19,7 +19,7 @@ import { SparklesIcon, TrashIcon, } from "@heroicons/react/24/outline"; -import { ContextItem } from "core/llm/types"; +import { ContextItem } from "core"; import { useCombobox } from "downshift"; import React, { useCallback, diff --git a/gui/src/components/mainInput/PillButton.tsx b/gui/src/components/mainInput/PillButton.tsx index e3a25bf2a..e8eb3a47f 100644 --- a/gui/src/components/mainInput/PillButton.tsx +++ b/gui/src/components/mainInput/PillButton.tsx @@ -3,7 +3,7 @@ import { PaintBrushIcon, TrashIcon, } from "@heroicons/react/24/outline"; -import { ContextItem } from "core/llm/types"; +import { ContextItem } from "core"; import { useCallback, useEffect, useRef, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import styled from "styled-components"; diff --git a/gui/src/components/markdown/CodeSnippetPreview.tsx b/gui/src/components/markdown/CodeSnippetPreview.tsx index f63c000d2..a8c35b67a 100644 --- a/gui/src/components/markdown/CodeSnippetPreview.tsx +++ b/gui/src/components/markdown/CodeSnippetPreview.tsx @@ -1,19 +1,18 @@ -import React from "react"; -import { defaultBorderRadius, lightGray, secondaryDark } from ".."; -import styled from "styled-components"; -import { getFontSize, getMarkdownLanguageTagForFile } from "../../util"; -import FileIcon from "../FileIcon"; -import HeaderButtonWithText from "../HeaderButtonWithText"; -import { ContextItem } from "core/llm/types"; -import { postToIde } from "../../util/ide"; import { - ArrowUpLeftIcon, ChevronDownIcon, ChevronUpIcon, TrashIcon, } from "@heroicons/react/24/outline"; -import { deleteContextWithIds } from "../../redux/slices/stateSlice"; +import { ContextItem } from "core"; +import React from "react"; import { useDispatch } from "react-redux"; +import styled from "styled-components"; +import { defaultBorderRadius, lightGray, secondaryDark } from ".."; +import { deleteContextWithIds } from "../../redux/slices/stateSlice"; +import { getFontSize, getMarkdownLanguageTagForFile } from "../../util"; +import { postToIde } from "../../util/ide"; +import FileIcon from "../FileIcon"; +import HeaderButtonWithText from "../HeaderButtonWithText"; import StyledMarkdownPreview from "./StyledMarkdownPreview"; const PreviewMarkdownDiv = styled.div<{ scroll: boolean }>` diff --git a/gui/src/hooks/useChatHandler.ts b/gui/src/hooks/useChatHandler.ts index a4b79639a..0ad51e877 100644 --- a/gui/src/hooks/useChatHandler.ts +++ b/gui/src/hooks/useChatHandler.ts @@ -1,9 +1,8 @@ import { Dispatch } from "@reduxjs/toolkit"; -import { SlashCommand } from "core/commands"; +import { ChatHistory, ChatHistoryItem, ChatMessage, SlashCommand } from "core"; import { ExtensionIde } from "core/ide"; import { constructMessages } from "core/llm/constructMessages"; -import { ChatHistory, ChatHistoryItem, ChatMessage } from "core/llm/types"; import { usePostHog } from "posthog-js/react"; import { useEffect, useRef } from "react"; import { useSelector } from "react-redux"; diff --git a/gui/src/hooks/useContextProviders.ts b/gui/src/hooks/useContextProviders.ts index b2b5e86fc..697fff577 100644 --- a/gui/src/hooks/useContextProviders.ts +++ b/gui/src/hooks/useContextProviders.ts @@ -1,4 +1,4 @@ -import { ContextItem } from "core/llm/types"; +import { ContextItem } from "core"; import { useSelector } from "react-redux"; import { RootStore } from "../redux/store"; import { errorPopup } from "../util/ide"; diff --git a/gui/src/hooks/useHistory.tsx b/gui/src/hooks/useHistory.tsx index 649b7f533..8105184ad 100644 --- a/gui/src/hooks/useHistory.tsx +++ b/gui/src/hooks/useHistory.tsx @@ -1,5 +1,5 @@ +import { PersistedSessionInfo, SessionInfo } from "core"; import { ideRequest } from "core/ide/messaging"; -import { PersistedSessionInfo, SessionInfo } from "core/types"; import { useSelector } from "react-redux"; import { RootStore } from "../redux/store"; diff --git a/gui/src/hooks/useSetup.ts b/gui/src/hooks/useSetup.ts index 528ead136..24e86136c 100644 --- a/gui/src/hooks/useSetup.ts +++ b/gui/src/hooks/useSetup.ts @@ -3,7 +3,10 @@ import { useEffect } from "react"; import { setServerStatusMessage } from "../redux/slices/miscSlice"; import { errorPopup, postToIde } from "../util/ide"; -import { loadSerializedConfig } from "core/config/load"; +import { + intermediateToFinalConfig, + serializedToIntermediateConfig, +} from "core/config/load"; import { ExtensionIde } from "core/ide/index"; import { setVscMachineId } from "../redux/slices/configSlice"; import { @@ -17,25 +20,28 @@ function useSetup(dispatch: Dispatch) { const loadConfig = async () => { try { const ide = new ExtensionIde(); - let config = loadSerializedConfig(await ide.getSerializedConfig()); - // const configJsUrl = await ide.getConfigJsUrl(); - // if (configJsUrl) { - // try { - // // Try config.ts first - // const module = await import(configJsUrl); - // if (!module.config) { - // throw new Error("config.ts does not export a config object"); - // } - // console.log("Loaded config.ts", module.config); - // config = module.modifyConfig(config); - // } catch (e) { - // console.log("Error loading config.ts: ", e); - // errorPopup(e.message); - // } - // } - console.log("Loaded config.json", config); + 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 = intermediateToFinalConfig(intermediate); // Fall back to config.json - dispatch(setConfig(config)); + dispatch(setConfig(finalConfig)); } catch (e) { console.log("Error loading config.json: ", e); errorPopup(e.message); diff --git a/gui/src/pages/history.tsx b/gui/src/pages/history.tsx index a45d4745c..562f4917b 100644 --- a/gui/src/pages/history.tsx +++ b/gui/src/pages/history.tsx @@ -1,5 +1,5 @@ import { ArrowLeftIcon, TrashIcon } from "@heroicons/react/24/outline"; -import { PersistedSessionInfo, SessionInfo } from "core/types"; +import { PersistedSessionInfo, SessionInfo } from "core"; import React, { Fragment, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; import { useNavigate } from "react-router-dom"; diff --git a/gui/src/pages/settings.tsx b/gui/src/pages/settings.tsx index b4ed583bd..5c0331c21 100644 --- a/gui/src/pages/settings.tsx +++ b/gui/src/pages/settings.tsx @@ -1,5 +1,5 @@ import { ArrowLeftIcon } from "@heroicons/react/24/outline"; -import { ContinueConfig } from "core/config"; +import { ContinueConfig } from "core"; import { useEffect } from "react"; import { FormProvider, useForm } from "react-hook-form"; import { useDispatch, useSelector } from "react-redux"; diff --git a/gui/src/redux/slices/serverStateReducer.ts b/gui/src/redux/slices/serverStateReducer.ts index 9d43aaf2c..85f0a1ca8 100644 --- a/gui/src/redux/slices/serverStateReducer.ts +++ b/gui/src/redux/slices/serverStateReducer.ts @@ -1,6 +1,4 @@ import { createSlice } from "@reduxjs/toolkit"; -import { SerializedContinueConfig } from "core/config"; -import { loadSerializedConfig } from "core/config/load"; import FreeTrial from "core/llm/llms/FreeTrial"; import { RootStore } from "../store"; @@ -54,13 +52,6 @@ export const serverStateSlice = createSlice({ contextProviders: action.payload, }; }, - setConfig: (state, { payload }: { payload: SerializedContinueConfig }) => { - const config = loadSerializedConfig(payload); - return { - ...state, - config, - }; - }, setIndexingProgress: (state, { payload }: { payload: number }) => { return { ...state, @@ -70,10 +61,6 @@ export const serverStateSlice = createSlice({ }, }); -export const { - setContextProviders, - setSlashCommands, - setConfig, - setIndexingProgress, -} = serverStateSlice.actions; +export const { setContextProviders, setSlashCommands, setIndexingProgress } = + serverStateSlice.actions; export default serverStateSlice.reducer; diff --git a/gui/src/redux/slices/stateSlice.ts b/gui/src/redux/slices/stateSlice.ts index 2c0c2df82..275b781ff 100644 --- a/gui/src/redux/slices/stateSlice.ts +++ b/gui/src/redux/slices/stateSlice.ts @@ -1,9 +1,16 @@ import { createSlice } from "@reduxjs/toolkit"; -import { ContinueConfig } from "core/config"; +import { + ChatMessage, + ContextItem, + ContextItemId, + ContinueConfig, + PersistedSessionInfo, +} from "core"; import defaultConfig from "core/config/default"; -import { loadSerializedConfig } from "core/config/load"; -import { ChatMessage, ContextItem, ContextItemId } from "core/llm/types"; -import { PersistedSessionInfo } from "core/types"; +import { + intermediateToFinalConfig, + serializedToIntermediateConfig, +} from "core/config/load"; import { v4 } from "uuid"; import { RootStore } from "../store"; @@ -85,7 +92,9 @@ const initialState: RootStore["state"] = { history: [], contextItems: [], active: false, - config: loadSerializedConfig(defaultConfig), + config: intermediateToFinalConfig( + serializedToIntermediateConfig(defaultConfig) + ), title: "New Session", sessionId: v4(), defaultModelTitle: "GPT-4", diff --git a/gui/src/redux/store.ts b/gui/src/redux/store.ts index c146e053d..96453c4f5 100644 --- a/gui/src/redux/store.ts +++ b/gui/src/redux/store.ts @@ -1,15 +1,17 @@ import { combineReducers, configureStore } from "@reduxjs/toolkit"; -import { SlashCommandDescription } from "core/config"; -import { ContextProviderDescription } from "core/context"; -import { ContextItem } from "core/llm/types"; import configReducer from "./slices/configSlice"; import miscReducer from "./slices/miscSlice"; import serverStateReducer from "./slices/serverStateReducer"; import stateReducer from "./slices/stateSlice"; import uiStateReducer from "./slices/uiStateSlice"; -import { ContinueConfig } from "core/config"; -import { ChatHistory } from "core/llm/types"; +import { + ChatHistory, + ContextItem, + ContextProviderDescription, + ContinueConfig, + SlashCommandDescription, +} from "core"; import { createTransform } from "redux-persist"; import storage from "redux-persist/lib/storage"; diff --git a/gui/src/util/modelData.ts b/gui/src/util/modelData.ts index 09101e8fc..519608b9e 100644 --- a/gui/src/util/modelData.ts +++ b/gui/src/util/modelData.ts @@ -2,7 +2,7 @@ This is the data that populates the model selection page. */ -import { ModelName, ModelProvider } from "core/config"; +import { ModelName, ModelProvider } from "core"; import _ from "lodash"; export function updatedObj(old: any, pathToValue: { [key: string]: any }) {