From 7d5dc4958a051765750764500a32a8eba059576b Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Mon, 13 May 2024 21:14:00 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20pass=20ideSettings=20to=20llmFro?= =?UTF-8?q?mDescription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/config/handler.ts | 13 ++----------- core/config/load.ts | 31 +++++++++++++++++-------------- core/llm/llms/index.ts | 15 ++++++++++++++- core/util/paths.ts | 24 ++++++++++++++++-------- 4 files changed, 49 insertions(+), 34 deletions(-) diff --git a/core/config/handler.ts b/core/config/handler.ts index fa8c84dc6..3db69d37b 100644 --- a/core/config/handler.ts +++ b/core/config/handler.ts @@ -29,7 +29,7 @@ export class ConfigHandler { } updateIdeSettings(ideSettings: IdeSettings) { - this.ideSettings = ideSettings + this.ideSettings = ideSettings; this.reloadConfig(); } @@ -63,19 +63,10 @@ export class ConfigHandler { const ideInfo = await this.ide.getIdeInfo(); const uniqueId = await this.ide.getUniqueId(); - let remoteConfigServerUrl = undefined; - try { - remoteConfigServerUrl = - typeof this.ideSettings.remoteConfigServerUrl !== "string" || - this.ideSettings.remoteConfigServerUrl === "" - ? undefined - : new URL(this.ideSettings.remoteConfigServerUrl); - } catch (e) {} - this.savedConfig = await loadFullConfigNode( this.ide.readFile.bind(this.ide), workspaceConfigs, - remoteConfigServerUrl, + this.ideSettings, ideInfo.ideType, uniqueId, this.writeLog, diff --git a/core/config/load.ts b/core/config/load.ts index f41384a58..234bbc31c 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -31,6 +31,7 @@ import { AllEmbeddingsProviders } from "../indexing/embeddings/index.js"; import { BaseLLM } from "../llm/index.js"; import CustomLLMClass from "../llm/llms/CustomLLM.js"; import { llmFromDescription } from "../llm/llms/index.js"; +import { IdeSettings } from "../protocol.js"; import { fetchwithRequestOptions } from "../util/fetchWithOptions.js"; import { copyOf } from "../util/index.js"; import mergeJson from "../util/merge.js"; @@ -81,7 +82,7 @@ const configMergeKeys = { function loadSerializedConfig( workspaceConfigs: ContinueRcJson[], - remoteConfigServerUrl: URL | undefined, + ideSettings: IdeSettings, ideType: IdeType, ): SerializedContinueConfig { const configPath = getConfigJsonPath(ideType); @@ -96,10 +97,10 @@ function loadSerializedConfig( config.allowAnonymousTelemetry = true; } - if (remoteConfigServerUrl) { + if (ideSettings.remoteConfigServerUrl) { try { const remoteConfigJson = resolveSerializedConfig( - getConfigJsonPathForRemote(remoteConfigServerUrl), + getConfigJsonPathForRemote(ideSettings.remoteConfigServerUrl), ); config = mergeJson(config, remoteConfigJson, "merge", configMergeKeys); } catch (e) { @@ -168,6 +169,7 @@ function isContextProviderWithParams( async function intermediateToFinalConfig( config: Config, readFile: (filepath: string) => Promise, + ideSettings: IdeSettings, uniqueId: string, writeLog: (log: string) => Promise, ): Promise { @@ -179,11 +181,14 @@ async function intermediateToFinalConfig( desc, readFile, uniqueId, + ideSettings, writeLog, config.completionOptions, config.systemMessage, ); - if (!llm) {continue;} + if (!llm) { + continue; + } if (llm.model === "AUTODETECT") { try { @@ -198,6 +203,7 @@ async function intermediateToFinalConfig( }, readFile, uniqueId, + ideSettings, writeLog, copyOf(config.completionOptions), config.systemMessage, @@ -257,6 +263,7 @@ async function intermediateToFinalConfig( config.tabAutocompleteModel, readFile, uniqueId, + ideSettings, writeLog, config.completionOptions, config.systemMessage, @@ -446,16 +453,12 @@ async function buildConfigTs() { async function loadFullConfigNode( readFile: (filepath: string) => Promise, workspaceConfigs: ContinueRcJson[], - remoteConfigServerUrl: URL | undefined, + ideSettings: IdeSettings, ideType: IdeType, uniqueId: string, writeLog: (log: string) => Promise, ): Promise { - let serialized = loadSerializedConfig( - workspaceConfigs, - remoteConfigServerUrl, - ideType, - ); + let serialized = loadSerializedConfig(workspaceConfigs, ideSettings, ideType); let intermediate = serializedToIntermediateConfig(serialized); const configJsContents = await buildConfigTs(); @@ -475,10 +478,10 @@ async function loadFullConfigNode( } // Remote config.js - if (remoteConfigServerUrl) { + if (ideSettings.remoteConfigServerUrl) { try { const configJsPathForRemote = getConfigJsPathForRemote( - remoteConfigServerUrl, + ideSettings.remoteConfigServerUrl, ); const module = await require(configJsPathForRemote); delete require.cache[require.resolve(configJsPathForRemote)]; @@ -494,6 +497,7 @@ async function loadFullConfigNode( const finalConfig = await intermediateToFinalConfig( intermediate, readFile, + ideSettings, uniqueId, writeLog, ); @@ -505,6 +509,5 @@ export { intermediateToFinalConfig, loadFullConfigNode, serializedToIntermediateConfig, - type BrowserSerializedContinueConfig + type BrowserSerializedContinueConfig, }; - diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 845e1d9c9..043511159 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -5,6 +5,7 @@ import { LLMOptions, ModelDescription, } from "../../index.js"; +import { IdeSettings } from "../../protocol.js"; import { DEFAULT_MAX_TOKENS } from "../constants.js"; import { BaseLLM } from "../index.js"; import Anthropic from "./Anthropic.js"; @@ -104,6 +105,7 @@ export async function llmFromDescription( desc: ModelDescription, readFile: (filepath: string) => Promise, uniqueId: string, + ideSettings: IdeSettings, writeLog: (log: string) => Promise, completionOptions?: BaseCompletionOptions, systemMessage?: string, @@ -124,7 +126,7 @@ export async function llmFromDescription( systemMessage = await renderTemplatedString(systemMessage, readFile, {}); } - const options: LLMOptions = { + let options: LLMOptions = { ...desc, completionOptions: { ...finalCompletionOptions, @@ -139,6 +141,17 @@ export async function llmFromDescription( uniqueId, }; + if (desc.provider === "continue-proxy") { + options = { + ...options, + apiBase: new URL( + "/proxy/v1", + ideSettings.remoteConfigServerUrl, + ).toString(), + apiKey: ideSettings.userToken, + }; + } + return new cls(options); } diff --git a/core/util/paths.ts b/core/util/paths.ts index f2c024441..5293b7759 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -2,9 +2,9 @@ import dotenv from "dotenv"; import * as fs from "fs"; import * as os from "os"; import * as path from "path"; -import { IdeType, SerializedContinueConfig } from "../index.js"; import { defaultConfig, defaultConfigJetBrains } from "../config/default.js"; import Types from "../config/types.js"; +import { IdeType, SerializedContinueConfig } from "../index.js"; export function getContinueGlobalPath(): string { // This is ~/.continue on mac/linux @@ -197,22 +197,30 @@ export function getRemoteConfigsFolderPath(): string { return dir; } -export function getPathToRemoteConfig(remoteConfigServerUrl: URL): string { - const dir = path.join( - getRemoteConfigsFolderPath(), - remoteConfigServerUrl.hostname, - ); +export function getPathToRemoteConfig(remoteConfigServerUrl: string): string { + let url: URL | undefined = undefined; + try { + url = + typeof remoteConfigServerUrl !== "string" || remoteConfigServerUrl === "" + ? undefined + : new URL(remoteConfigServerUrl); + } catch (e) {} + const dir = path.join(getRemoteConfigsFolderPath(), url?.hostname ?? "None"); if (!fs.existsSync(dir)) { fs.mkdirSync(dir); } return dir; } -export function getConfigJsonPathForRemote(remoteConfigServerUrl: URL): string { +export function getConfigJsonPathForRemote( + remoteConfigServerUrl: string, +): string { return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.json"); } -export function getConfigJsPathForRemote(remoteConfigServerUrl: URL): string { +export function getConfigJsPathForRemote( + remoteConfigServerUrl: string, +): string { return path.join(getPathToRemoteConfig(remoteConfigServerUrl), "config.js"); }