From a005aa78ac75ac47be3e647e9e23b45eab7dafaf Mon Sep 17 00:00:00 2001 From: Test Date: Fri, 27 Dec 2024 14:48:23 -0600 Subject: [PATCH] fix: disable indexing for unsupported CPUs --- core/config/load.ts | 11 ++++- core/config/util.ts | 76 +++++++++++++++++++++++++++++ core/util/GlobalContext.ts | 1 + extensions/vscode/package-lock.json | 4 +- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index 99c701141..4e21a7c60 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -46,6 +46,8 @@ import CustomLLMClass from "../llm/llms/CustomLLM"; import FreeTrial from "../llm/llms/FreeTrial"; import { LLMReranker } from "../llm/llms/llm"; import TransformersJsEmbeddingsProvider from "../llm/llms/TransformersJsEmbeddingsProvider"; +import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile"; +import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles"; import { allTools } from "../tools"; import { copyOf } from "../util"; import { GlobalContext } from "../util/GlobalContext"; @@ -61,8 +63,6 @@ import { getEsbuildBinaryPath, } from "../util/paths"; -import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile"; -import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles"; import { defaultContextProvidersJetBrains, defaultContextProvidersVsCode, @@ -70,6 +70,7 @@ import { defaultSlashCommandsVscode, } from "./default"; import { getSystemPromptDotFile } from "./getSystemPromptDotFile"; +import { isSupportedLanceDbCpuTarget } from "./util"; import { ConfigValidationError, validateConfig } from "./validation.js"; export interface ConfigResult { @@ -112,6 +113,7 @@ function loadSerializedConfig( ideSettings: IdeSettings, ideType: IdeType, overrideConfigJson: SerializedContinueConfig | undefined, + ide: IDE ): ConfigResult { const configPath = getConfigJsonPath(ideType); let config: SerializedContinueConfig = overrideConfigJson!; @@ -174,6 +176,10 @@ function loadSerializedConfig( ? [...defaultSlashCommandsVscode] : [...defaultSlashCommandsJetBrains]; + if (!isSupportedLanceDbCpuTarget(ide)) { + config.disableIndexing = true; + } + return { config, errors, configLoadInterrupted: false }; } @@ -767,6 +773,7 @@ async function loadFullConfigNode( ideSettings, ideType, overrideConfigJson, + ide ); if (!serialized || configLoadInterrupted) { diff --git a/core/config/util.ts b/core/config/util.ts index 0247aa25d..100773f4b 100644 --- a/core/config/util.ts +++ b/core/config/util.ts @@ -1,10 +1,15 @@ +import { execSync } from "child_process"; +import os from "os"; + import { ContextProviderWithParams, ContinueConfig, + IDE, ILLM, ModelDescription, ModelRoles, } from "../"; +import { GlobalContext } from "../util/GlobalContext"; import { editConfigJson } from "../util/paths"; function stringify(obj: any, indentation?: number): string { @@ -96,3 +101,74 @@ export function getModelByRole( return matchingModel; } + +// https://github.com/continuedev/continue/issues/940 +export async function isSupportedLanceDbCpuTarget(ide: IDE) { + const globalContext = new GlobalContext(); + const globalContextVal = globalContext.get("isSupportedLanceDbCpuTarget"); + + // If we've already checked the CPU target, return the cached value + if (globalContextVal !== undefined) { + return globalContextVal; + } + + const arch = os.arch(); + const platform = os.platform(); + + //https://github.com/lancedb/lance/issues/2195#issuecomment-2057841311 + // Only applies to x64 + if (arch !== "x64") { + return true; + } + + try { + const CPU_FEATURES_TO_CHECK = ["avx", "fma"] as const; + + const cpuFlags = (() => { + switch (platform) { + case "darwin": + return execSync("sysctl -n machdep.cpu.features") + .toString() + .toLowerCase(); + case "linux": + return execSync("cat /proc/cpuinfo").toString().toLowerCase(); + case "win32": + return execSync("wmic cpu get caption /format:list") + .toString() + .toLowerCase(); + default: + return ""; + } + })(); + + // TODO: Remvoe ! + const isSupportedLanceDbCpuTarget = cpuFlags + ? !CPU_FEATURES_TO_CHECK.every((feature) => cpuFlags.includes(feature)) + : true; + + // If it's not a supported CPU target, and it's the first time we are checking, + // show a toast to inform the user that we are going to disable indexing. + if (!isSupportedLanceDbCpuTarget) { + const shouldOpenLink = await ide.showToast( + "warning", + "Cdoebase indexing is disabled due to CPU incompatibility", + "View details", + ); + + if (shouldOpenLink) { + // TODO + void ide.openUrl("https://continue.dev"); + } + } + + globalContext.update( + "isSupportedLanceDbCpuTarget", + isSupportedLanceDbCpuTarget, + ); + + return isSupportedLanceDbCpuTarget; + } catch (error) { + // If we can't determine CPU features, default to true + return true; + } +} diff --git a/core/util/GlobalContext.ts b/core/util/GlobalContext.ts index 1095234d8..a4eb66f81 100644 --- a/core/util/GlobalContext.ts +++ b/core/util/GlobalContext.ts @@ -16,6 +16,7 @@ export type GlobalContextType = { hasDismissedConfigTsNoticeJetBrains: boolean; hasAlreadyCreatedAPromptFile: boolean; showConfigUpdateToast: boolean; + isSupportedLanceDbCpuTarget: boolean; }; /** diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index 8f5cad8a0..0a2dd8330 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "0.9.247", + "version": "0.9.248", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "0.9.247", + "version": "0.9.248", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3",