node-llama-cpp 3.0.0-beta.8 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -27
- package/bins/_linux-arm64.moved.txt +1 -0
- package/bins/_linux-armv7l.moved.txt +1 -0
- package/bins/_linux-x64-cuda.moved.txt +1 -0
- package/bins/_linux-x64-vulkan.moved.txt +1 -0
- package/bins/_linux-x64.moved.txt +1 -0
- package/bins/_mac-arm64-metal.moved.txt +1 -0
- package/bins/_mac-x64.moved.txt +1 -0
- package/bins/_win-arm64.moved.txt +1 -0
- package/bins/_win-x64-cuda.moved.txt +1 -0
- package/bins/_win-x64-vulkan.moved.txt +1 -0
- package/bins/_win-x64.moved.txt +1 -0
- package/dist/ChatWrapper.d.ts +19 -39
- package/dist/ChatWrapper.js +129 -72
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/apiDocsIndex.d.ts +1 -0
- package/dist/apiDocsIndex.js +7 -0
- package/dist/apiDocsIndex.js.map +1 -0
- package/dist/bindings/AddonTypes.d.ts +88 -20
- package/dist/bindings/Llama.d.ts +43 -6
- package/dist/bindings/Llama.js +214 -40
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/consts.d.ts +2 -0
- package/dist/bindings/consts.js +13 -0
- package/dist/bindings/consts.js.map +1 -0
- package/dist/bindings/getLlama.d.ts +123 -18
- package/dist/bindings/getLlama.js +288 -90
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/types.d.ts +29 -5
- package/dist/bindings/types.js +51 -2
- package/dist/bindings/types.js.map +1 -1
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +21 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +49 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/asyncEvery.d.ts +5 -0
- package/dist/bindings/utils/asyncEvery.js +15 -0
- package/dist/bindings/utils/asyncEvery.js.map +1 -0
- package/dist/bindings/utils/asyncSome.d.ts +5 -0
- package/dist/bindings/utils/asyncSome.js +27 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.js +39 -28
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.d.ts +11 -3
- package/dist/bindings/utils/compileLLamaCpp.js +250 -81
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +14 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +305 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +46 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +14 -6
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -1
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -1
- package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
- package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +27 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -1
- package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
- package/dist/bindings/utils/getPlatformInfo.js +28 -0
- package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
- package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
- package/dist/bindings/utils/hasFileInPath.js +34 -0
- package/dist/bindings/utils/hasFileInPath.js.map +1 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +3 -9
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -1
- package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +26 -26
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -1
- package/dist/bindings/utils/testBindingBinary.d.ts +1 -0
- package/dist/bindings/utils/testBindingBinary.js +100 -0
- package/dist/bindings/utils/testBindingBinary.js.map +1 -0
- package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
- package/dist/bindings/utils/testCmakeBinary.js +32 -0
- package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
- package/dist/chatWrappers/AlpacaChatWrapper.d.ts +2 -1
- package/dist/chatWrappers/AlpacaChatWrapper.js +10 -2
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +2 -14
- package/dist/chatWrappers/ChatMLChatWrapper.js +23 -21
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FalconChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/FalconChatWrapper.js +39 -21
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +8 -32
- package/dist/chatWrappers/FunctionaryChatWrapper.js +514 -118
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
- package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/GeneralChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/GeneralChatWrapper.js +46 -22
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/{LlamaChatWrapper.js → Llama2ChatWrapper.js} +37 -20
- package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +277 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +15 -0
- package/dist/chatWrappers/MistralChatWrapper.js +169 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +100 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +409 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +60 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +204 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +23 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +57 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +119 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
- package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
- package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
- package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +221 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
- package/dist/chatWrappers/utils/jsonDumps.js +18 -0
- package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +95 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +335 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.js +19 -11
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +16 -7
- package/dist/cli/commands/ChatCommand.js +323 -191
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/CompleteCommand.d.ts +31 -0
- package/dist/cli/commands/CompleteCommand.js +402 -0
- package/dist/cli/commands/CompleteCommand.js.map +1 -0
- package/dist/cli/commands/DebugCommand.d.ts +7 -0
- package/dist/cli/commands/DebugCommand.js +54 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +33 -0
- package/dist/cli/commands/InfillCommand.js +438 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +11 -0
- package/dist/cli/commands/InitCommand.js +195 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.js +6 -2
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
- package/dist/cli/commands/PullCommand.d.ts +13 -0
- package/dist/cli/commands/PullCommand.js +158 -0
- package/dist/cli/commands/PullCommand.js.map +1 -0
- package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/InspectCommand.js +21 -0
- package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +225 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +149 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +202 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +18 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +629 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
- package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
- package/dist/cli/commands/source/SourceCommand.js +19 -0
- package/dist/cli/commands/source/SourceCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
- package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
- package/dist/cli/commands/{ClearCommand.d.ts → source/commands/ClearCommand.d.ts} +1 -1
- package/dist/cli/commands/{ClearCommand.js → source/commands/ClearCommand.js} +11 -10
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/{DownloadCommand.d.ts → source/commands/DownloadCommand.d.ts} +5 -4
- package/dist/cli/commands/source/commands/DownloadCommand.js +217 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
- package/dist/cli/projectTemplates.d.ts +7 -0
- package/dist/cli/projectTemplates.js +10 -0
- package/dist/cli/projectTemplates.js.map +1 -0
- package/dist/cli/recommendedModels.d.ts +2 -0
- package/dist/cli/recommendedModels.js +585 -0
- package/dist/cli/recommendedModels.js.map +1 -0
- package/dist/cli/startCreateCli.d.ts +2 -0
- package/dist/cli/startCreateCli.js +26 -0
- package/dist/cli/startCreateCli.js.map +1 -0
- package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
- package/dist/cli/utils/ConsoleInteraction.js +122 -0
- package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/ConsoleTable.d.ts +23 -0
- package/dist/cli/utils/ConsoleTable.js +86 -0
- package/dist/cli/utils/ConsoleTable.js.map +1 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
- package/dist/cli/utils/consolePromptQuestion.js +82 -0
- package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
- package/dist/cli/utils/getReadablePath.d.ts +1 -0
- package/dist/cli/utils/getReadablePath.js +14 -0
- package/dist/cli/utils/getReadablePath.js.map +1 -0
- package/dist/cli/utils/interactivelyAskForModel.d.ts +8 -0
- package/dist/cli/utils/interactivelyAskForModel.js +450 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +9 -0
- package/dist/cli/utils/printCommonInfoLines.js +82 -0
- package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
- package/dist/cli/utils/printInfoLine.d.ts +12 -0
- package/dist/cli/utils/printInfoLine.js +54 -0
- package/dist/cli/utils/printInfoLine.js.map +1 -0
- package/dist/cli/utils/projectTemplates.d.ts +19 -0
- package/dist/cli/utils/projectTemplates.js +47 -0
- package/dist/cli/utils/projectTemplates.js.map +1 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +5 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +72 -0
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
- package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
- package/dist/cli/utils/resolveHeaderFlag.js +21 -0
- package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +19 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +7 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
- package/dist/cli/utils/splitAnsiToLines.js +32 -0
- package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
- package/dist/commands.d.ts +4 -3
- package/dist/commands.js +6 -3
- package/dist/commands.js.map +1 -1
- package/dist/config.d.ts +35 -4
- package/dist/config.js +58 -17
- package/dist/config.js.map +1 -1
- package/dist/consts.d.ts +4 -0
- package/dist/consts.js +11 -0
- package/dist/consts.js.map +1 -0
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +151 -41
- package/dist/evaluator/LlamaChat/LlamaChat.js +1289 -437
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +27 -17
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +187 -13
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +280 -53
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +40 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +186 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +10 -2
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.d.ts +168 -0
- package/dist/evaluator/LlamaCompletion.js +470 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +63 -22
- package/dist/evaluator/LlamaContext/LlamaContext.js +503 -121
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +31 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +177 -16
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/{resolveBatchItemsPrioritizingStrategy.js → resolveBatchItemsPrioritizationStrategy.js} +5 -5
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
- package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
- package/dist/evaluator/LlamaEmbedding.js +53 -0
- package/dist/evaluator/LlamaEmbedding.js.map +1 -0
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +29 -19
- package/dist/evaluator/LlamaEmbeddingContext.js +36 -43
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.d.ts +16 -13
- package/dist/evaluator/LlamaGrammar.js +17 -10
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +7 -3
- package/dist/evaluator/LlamaGrammarEvaluationState.js +8 -4
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -1
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +3 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +5 -3
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +255 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +780 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +34 -0
- package/dist/evaluator/TokenBias.js +65 -0
- package/dist/evaluator/TokenBias.js.map +1 -0
- package/dist/evaluator/TokenMeter.d.ts +45 -0
- package/dist/evaluator/TokenMeter.js +74 -0
- package/dist/evaluator/TokenMeter.js.map +1 -0
- package/dist/gguf/consts.d.ts +4 -0
- package/dist/gguf/consts.js +12 -0
- package/dist/gguf/consts.js.map +1 -0
- package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
- package/dist/gguf/fileReaders/GgufFileReader.js +109 -0
- package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +25 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +92 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +50 -0
- package/dist/gguf/insights/GgufInsights.js +401 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +146 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +226 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +19 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +78 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +15 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +183 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
- package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
- package/dist/gguf/insights/utils/scoreLevels.js +16 -0
- package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
- package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
- package/dist/gguf/parser/GgufV2Parser.js +156 -0
- package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
- package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
- package/dist/gguf/parser/GgufV3Parser.js +4 -0
- package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
- package/dist/gguf/parser/parseGguf.d.ts +8 -0
- package/dist/gguf/parser/parseGguf.js +61 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -0
- package/dist/gguf/readGgufFileInfo.d.ts +45 -0
- package/dist/gguf/readGgufFileInfo.js +71 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +84 -0
- package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
- package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
- package/dist/gguf/types/GgufMetadataTypes.d.ts +372 -0
- package/dist/gguf/types/GgufMetadataTypes.js +114 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +37 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +33 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
- package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
- package/dist/gguf/utils/GgufReadOffset.js +18 -0
- package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
- package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
- package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
- package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +16 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
- package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +39 -14
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/state.d.ts +2 -0
- package/dist/state.js +7 -0
- package/dist/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +131 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/DisposeGuard.d.ts +13 -0
- package/dist/utils/DisposeGuard.js +120 -0
- package/dist/utils/DisposeGuard.js.map +1 -0
- package/dist/utils/InsufficientMemoryError.d.ts +3 -0
- package/dist/utils/InsufficientMemoryError.js +6 -0
- package/dist/utils/InsufficientMemoryError.js.map +1 -0
- package/dist/utils/LlamaText.d.ts +73 -26
- package/dist/utils/LlamaText.js +475 -157
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/LruCache.d.ts +12 -0
- package/dist/utils/LruCache.js +44 -0
- package/dist/utils/LruCache.js.map +1 -0
- package/dist/utils/OverridesObject.d.ts +7 -0
- package/dist/utils/OverridesObject.js +2 -0
- package/dist/utils/OverridesObject.js.map +1 -0
- package/dist/utils/ReplHistory.js +5 -1
- package/dist/utils/ReplHistory.js.map +1 -1
- package/dist/utils/StopGenerationDetector.d.ts +27 -8
- package/dist/utils/StopGenerationDetector.js +108 -22
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/ThreadsSplitter.d.ts +32 -0
- package/dist/utils/ThreadsSplitter.js +177 -0
- package/dist/utils/ThreadsSplitter.js.map +1 -0
- package/dist/utils/TokenStreamRegulator.d.ts +10 -4
- package/dist/utils/TokenStreamRegulator.js +102 -10
- package/dist/utils/TokenStreamRegulator.js.map +1 -1
- package/dist/utils/UnsupportedError.d.ts +2 -0
- package/dist/utils/UnsupportedError.js +7 -0
- package/dist/utils/UnsupportedError.js.map +1 -0
- package/dist/utils/appendUserMessageToChatHistory.d.ts +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -1
- package/dist/utils/clearTempFolder.js.map +1 -1
- package/dist/utils/cmake.js +23 -10
- package/dist/utils/cmake.js.map +1 -1
- package/dist/utils/compareTokens.d.ts +1 -1
- package/dist/utils/compareTokens.js.map +1 -1
- package/dist/utils/createModelDownloader.d.ts +199 -0
- package/dist/utils/createModelDownloader.js +405 -0
- package/dist/utils/createModelDownloader.js.map +1 -0
- package/dist/utils/findBestOption.d.ts +4 -0
- package/dist/utils/findBestOption.js +15 -0
- package/dist/utils/findBestOption.js.map +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +23 -12
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +7 -4
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
- package/dist/utils/gbnfJson/types.d.ts +3 -0
- package/dist/utils/gbnfJson/types.js.map +1 -1
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +3 -3
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
- package/dist/utils/getBuildDefaults.d.ts +1 -2
- package/dist/utils/getBuildDefaults.js +2 -3
- package/dist/utils/getBuildDefaults.js.map +1 -1
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -1
- package/dist/utils/getConsoleLogPrefix.js +5 -4
- package/dist/utils/getConsoleLogPrefix.js.map +1 -1
- package/dist/utils/getGrammarsFolder.js +1 -1
- package/dist/utils/getGrammarsFolder.js.map +1 -1
- package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
- package/dist/utils/getReadableContextSize.d.ts +1 -0
- package/dist/utils/getReadableContextSize.js +7 -0
- package/dist/utils/getReadableContextSize.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +15 -11
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gitReleaseBundles.js +68 -1
- package/dist/utils/gitReleaseBundles.js.map +1 -1
- package/dist/utils/isToken.d.ts +2 -0
- package/dist/utils/isToken.js +4 -0
- package/dist/utils/isToken.js.map +1 -0
- package/dist/utils/isUrl.d.ts +1 -0
- package/dist/utils/isUrl.js +15 -0
- package/dist/utils/isUrl.js.map +1 -0
- package/dist/utils/mergeUnionTypes.d.ts +10 -0
- package/dist/utils/mergeUnionTypes.js +2 -0
- package/dist/utils/mergeUnionTypes.js.map +1 -0
- package/dist/utils/modelFileAccesTokens.d.ts +4 -0
- package/dist/utils/modelFileAccesTokens.js +40 -0
- package/dist/utils/modelFileAccesTokens.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +1 -0
- package/dist/utils/parseModelFileName.js +6 -1
- package/dist/utils/parseModelFileName.js.map +1 -1
- package/dist/utils/parseTextTemplate.d.ts +66 -0
- package/dist/utils/parseTextTemplate.js +116 -0
- package/dist/utils/parseTextTemplate.js.map +1 -0
- package/dist/utils/prettyPrintObject.d.ts +10 -1
- package/dist/utils/prettyPrintObject.js +61 -15
- package/dist/utils/prettyPrintObject.js.map +1 -1
- package/dist/utils/pushAll.d.ts +6 -0
- package/dist/utils/pushAll.js +11 -0
- package/dist/utils/pushAll.js.map +1 -0
- package/dist/utils/removeNullFields.d.ts +2 -2
- package/dist/utils/removeNullFields.js.map +1 -1
- package/dist/utils/resolveGithubRelease.d.ts +2 -2
- package/dist/utils/resolveGithubRelease.js.map +1 -1
- package/dist/utils/resolveLastTokens.d.ts +2 -0
- package/dist/utils/resolveLastTokens.js +12 -0
- package/dist/utils/resolveLastTokens.js.map +1 -0
- package/dist/utils/runtime.d.ts +4 -0
- package/dist/utils/runtime.js +8 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/safeEventCallback.d.ts +6 -0
- package/dist/utils/safeEventCallback.js +29 -0
- package/dist/utils/safeEventCallback.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -2
- package/dist/utils/spawnCommand.js +55 -7
- package/dist/utils/spawnCommand.js.map +1 -1
- package/dist/utils/tokenizeInput.d.ts +1 -1
- package/dist/utils/tokenizeInput.js +6 -3
- package/dist/utils/tokenizeInput.js.map +1 -1
- package/dist/utils/transformPromisable.d.ts +40 -0
- package/dist/utils/transformPromisable.js +64 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +2 -0
- package/dist/utils/truncateTextAndRoundToWords.js +32 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
- package/dist/utils/utilTypes.d.ts +3 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -1
- package/dist/utils/withLockfile.js.map +1 -1
- package/dist/utils/withOra.d.ts +2 -0
- package/dist/utils/withOra.js +22 -6
- package/dist/utils/withOra.js.map +1 -1
- package/dist/utils/withProgressLog.d.ts +22 -0
- package/dist/utils/withProgressLog.js +211 -0
- package/dist/utils/withProgressLog.js.map +1 -0
- package/dist/utils/withStatusLogs.js +1 -1
- package/dist/utils/withStatusLogs.js.map +1 -1
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +9 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/.clang-format +1 -2
- package/llama/CMakeLists.txt +134 -5
- package/llama/addon/AddonContext.cpp +629 -0
- package/llama/addon/AddonContext.h +52 -0
- package/llama/addon/AddonGrammar.cpp +39 -0
- package/llama/addon/AddonGrammar.h +19 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +25 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +672 -0
- package/llama/addon/AddonModel.h +61 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +105 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +513 -0
- package/llama/addon/AddonSampler.h +65 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +223 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +136 -0
- package/llama/addon/globals/addonLog.h +21 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +108 -0
- package/llama/addon/globals/getGpuInfo.h +6 -0
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/gpuInfo/cuda-gpu-info.cu +120 -0
- package/llama/gpuInfo/cuda-gpu-info.h +10 -0
- package/llama/gpuInfo/metal-gpu-info.h +8 -0
- package/llama/gpuInfo/metal-gpu-info.mm +30 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +83 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/grammars/README.md +297 -6
- package/llama/grammars/json.gbnf +4 -4
- package/llama/grammars/json_arr.gbnf +4 -4
- package/llama/llama.cpp.info.json +1 -1
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
- package/package.json +109 -59
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
- package/dist/AbortError.d.ts +0 -2
- package/dist/AbortError.js +0 -7
- package/dist/AbortError.js.map +0 -1
- package/dist/chatWrappers/LlamaChatWrapper.d.ts +0 -13
- package/dist/chatWrappers/LlamaChatWrapper.js.map +0 -1
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -57
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
- package/dist/cli/commands/BuildCommand.d.ts +0 -11
- package/dist/cli/commands/BuildCommand.js +0 -106
- package/dist/cli/commands/BuildCommand.js.map +0 -1
- package/dist/cli/commands/ClearCommand.js.map +0 -1
- package/dist/cli/commands/DownloadCommand.js +0 -169
- package/dist/cli/commands/DownloadCommand.js.map +0 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +0 -22
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +0 -121
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -2
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
- package/dist/evaluator/LlamaModel.d.ts +0 -120
- package/dist/evaluator/LlamaModel.js +0 -320
- package/dist/evaluator/LlamaModel.js.map +0 -1
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
- package/dist/utils/parseModelTypeDescription.d.ts +0 -6
- package/dist/utils/parseModelTypeDescription.js +0 -9
- package/dist/utils/parseModelTypeDescription.js.map +0 -1
- package/dist/utils/resolveChatWrapper.d.ts +0 -4
- package/dist/utils/resolveChatWrapper.js +0 -16
- package/dist/utils/resolveChatWrapper.js.map +0 -1
- package/llama/addon.cpp +0 -916
- package/llamaBins/linux-arm64/.buildMetadata.json +0 -1
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/.buildMetadata.json +0 -1
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/linux-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/mac-arm64-metal/.buildMetadata.json +0 -1
- package/llamaBins/mac-arm64-metal/ggml-metal.metal +0 -6119
- package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
- package/llamaBins/mac-x64/.buildMetadata.json +0 -1
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64/.buildMetadata.json +0 -1
- package/llamaBins/win-x64/llama-addon.exp +0 -0
- package/llamaBins/win-x64/llama-addon.lib +0 -0
- package/llamaBins/win-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import { LlamaLogLevel } from "./types.js";
|
|
1
|
+
import { LlamaGpuType, LlamaLogLevel } from "./types.js";
|
|
2
2
|
import { Llama } from "./Llama.js";
|
|
3
3
|
export type LlamaOptions = {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
*
|
|
5
|
+
* The compute layer implementation type to use for llama.cpp.
|
|
6
|
+
* - **`"auto"`**: Automatically detect and use the best GPU available (Metal on macOS, and CUDA or Vulkan on Windows and Linux)
|
|
7
|
+
* - **`"metal"`**: Use Metal.
|
|
8
|
+
* Only supported on macOS.
|
|
9
|
+
* Enabled by default on Apple Silicon Macs.
|
|
10
|
+
* - **`"cuda"`**: Use CUDA.
|
|
11
|
+
* - **`"vulkan"`**: Use Vulkan.
|
|
12
|
+
* - **`false`**: Disable any GPU support and only use the CPU.
|
|
13
|
+
*
|
|
14
|
+
* `"auto"` by default.
|
|
13
15
|
*/
|
|
14
|
-
|
|
16
|
+
gpu?: "auto" | LlamaGpuType | {
|
|
17
|
+
type: "auto";
|
|
18
|
+
exclude?: LlamaGpuType[];
|
|
19
|
+
};
|
|
15
20
|
/**
|
|
16
21
|
* Set the minimum log level for llama.cpp.
|
|
17
|
-
* Defaults to "
|
|
22
|
+
* Defaults to `"warn"`.
|
|
18
23
|
*/
|
|
19
24
|
logLevel?: LlamaLogLevel;
|
|
20
25
|
/**
|
|
@@ -32,7 +37,11 @@ export type LlamaOptions = {
|
|
|
32
37
|
* - **`"forceRebuild"`**: Always build from source.
|
|
33
38
|
* Be cautious with this option, as it will cause the build to fail on Windows when the binaries are in use by another process.
|
|
34
39
|
*
|
|
35
|
-
*
|
|
40
|
+
* When running from inside an Asar archive in Electron, building from source is not possible, so it'll never build from source.
|
|
41
|
+
* To allow building from source in Electron apps, make sure you ship `node-llama-cpp` as an unpacked module.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `"auto"`.
|
|
44
|
+
* On Electron, defaults to `"never"`.
|
|
36
45
|
*/
|
|
37
46
|
build?: "auto" | "never" | "forceRebuild";
|
|
38
47
|
/**
|
|
@@ -60,24 +69,120 @@ export type LlamaOptions = {
|
|
|
60
69
|
* Disabled by default.
|
|
61
70
|
*/
|
|
62
71
|
skipDownload?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* The maximum number of threads to use for the Llama instance.
|
|
74
|
+
*
|
|
75
|
+
* Set to `0` to have no thread limit.
|
|
76
|
+
*
|
|
77
|
+
* When not using a GPU, defaults to the number of CPU cores that are useful for math (`.cpuMathCores`), or `4`, whichever is higher.
|
|
78
|
+
*
|
|
79
|
+
* When using a GPU, there's no limit by default.
|
|
80
|
+
*/
|
|
81
|
+
maxThreads?: number;
|
|
82
|
+
/**
|
|
83
|
+
* Pad the available VRAM for the memory size calculations, as these calculations are not always accurate.
|
|
84
|
+
* Recommended to ensure stability.
|
|
85
|
+
* This only affects the calculations of `"auto"` in function options and is not reflected in the `getVramState` function.
|
|
86
|
+
*
|
|
87
|
+
* Defaults to `6%` of the total VRAM or 1GB, whichever is lower.
|
|
88
|
+
* Set to `0` to disable.
|
|
89
|
+
*/
|
|
90
|
+
vramPadding?: number | ((totalVram: number) => number);
|
|
91
|
+
/**
|
|
92
|
+
* Enable debug mode to find issues with llama.cpp.
|
|
93
|
+
* Makes logs print directly to the console from `llama.cpp` and not through the provided logger.
|
|
94
|
+
*
|
|
95
|
+
* Defaults to `false`.
|
|
96
|
+
*
|
|
97
|
+
* The default can be set using the `NODE_LLAMA_CPP_DEBUG` environment variable.
|
|
98
|
+
*/
|
|
99
|
+
debug?: boolean;
|
|
63
100
|
};
|
|
64
101
|
export type LastBuildOptions = {
|
|
65
102
|
/**
|
|
66
103
|
* Set the minimum log level for llama.cpp.
|
|
67
|
-
* Defaults to "
|
|
104
|
+
* Defaults to "warn".
|
|
68
105
|
*/
|
|
69
106
|
logLevel?: LlamaLogLevel;
|
|
70
107
|
/**
|
|
71
108
|
* Set a custom logger for llama.cpp logs.
|
|
72
109
|
*/
|
|
73
110
|
logger?: (level: LlamaLogLevel, message: string) => void;
|
|
111
|
+
/**
|
|
112
|
+
* If a local build is not found, use prebuilt binaries.
|
|
113
|
+
* Enabled by default.
|
|
114
|
+
*/
|
|
115
|
+
usePrebuiltBinaries?: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* If a local build is not found, and prebuilt binaries are not found, when building from source,
|
|
118
|
+
* print binary compilation progress logs.
|
|
119
|
+
* Enabled by default.
|
|
120
|
+
*/
|
|
121
|
+
progressLogs?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* If a local build is not found, and prebuilt binaries are not found, don't download llama.cpp source if it's not found.
|
|
124
|
+
* When set to `true`, and llama.cpp source is needed but is not found, a `NoBinaryFoundError` error will be thrown.
|
|
125
|
+
* Disabled by default.
|
|
126
|
+
*/
|
|
127
|
+
skipDownload?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* The maximum number of threads to use for the Llama instance.
|
|
130
|
+
*
|
|
131
|
+
* Set to `0` to have no thread limit.
|
|
132
|
+
*
|
|
133
|
+
* When not using a GPU, defaults to the number of CPU cores that are useful for math (`.cpuMathCores`), or `4`, whichever is higher.
|
|
134
|
+
*
|
|
135
|
+
* When using a GPU, there's no limit by default.
|
|
136
|
+
*/
|
|
137
|
+
maxThreads?: number;
|
|
138
|
+
/**
|
|
139
|
+
* Pad the available VRAM for the memory size calculations, as these calculations are not always accurate.
|
|
140
|
+
* Recommended to ensure stability.
|
|
141
|
+
* This only affects the calculations of `"auto"` in function options and is not reflected in the `getVramState` function.
|
|
142
|
+
*
|
|
143
|
+
* Defaults to `6%` of the total VRAM or 1GB, whichever is lower.
|
|
144
|
+
* Set to `0` to disable.
|
|
145
|
+
*/
|
|
146
|
+
vramPadding?: number | ((totalVram: number) => number);
|
|
147
|
+
/**
|
|
148
|
+
* Enable debug mode to find issues with llama.cpp.
|
|
149
|
+
* Makes logs print directly to the console from `llama.cpp` and not through the provided logger.
|
|
150
|
+
*
|
|
151
|
+
* Defaults to `false`.
|
|
152
|
+
*
|
|
153
|
+
* The default can be set using the `NODE_LLAMA_CPP_DEBUG` environment variable.
|
|
154
|
+
*/
|
|
155
|
+
debug?: boolean;
|
|
74
156
|
};
|
|
75
157
|
export declare const getLlamaFunctionName = "getLlama";
|
|
158
|
+
export declare const defaultLlamaVramPadding: (totalVram: number) => number;
|
|
76
159
|
/**
|
|
77
|
-
* Get a llama.cpp binding.
|
|
78
|
-
*
|
|
79
|
-
*
|
|
160
|
+
* Get a `llama.cpp` binding.
|
|
161
|
+
*
|
|
162
|
+
* Defaults to use a local binary built using the `source download` or `source build` CLI commands if one exists,
|
|
163
|
+
* otherwise, uses a prebuilt binary, and fallbacks to building from source if a prebuilt binary is not found.
|
|
164
|
+
*
|
|
165
|
+
* Pass `"lastBuild"` to default to use the last successful build created
|
|
166
|
+
* using the `source download` or `source build` CLI commands if one exists.
|
|
167
|
+
*
|
|
168
|
+
* The difference between using `"lastBuild"` and not using it is that `"lastBuild"` will use the binary built using a CLI command
|
|
169
|
+
* with the configuration used to build that binary (like using its GPU type),
|
|
170
|
+
* while not using `"lastBuild"` will only attempt to only use a binary that complies with the given options.
|
|
171
|
+
*
|
|
172
|
+
* For example, if your machine supports both CUDA and Vulkan, and you run the `source download --gpu vulkan` command,
|
|
173
|
+
* calling `getLlama("lastBuild")` will return the binary you built with Vulkan,
|
|
174
|
+
* while calling `getLlama()` will return a binding from a pre-built binary with CUDA,
|
|
175
|
+
* since CUDA is preferable on systems that support it.
|
|
176
|
+
*
|
|
177
|
+
* For example, if your machine supports CUDA, and you run the `source download --gpu cuda` command,
|
|
178
|
+
* calling `getLlama("lastBuild")` will return the binary you built with CUDA,
|
|
179
|
+
* and calling `getLlama()` will also return that same binary you built with CUDA.
|
|
180
|
+
*
|
|
181
|
+
* You should prefer to use `getLlama()` without `"lastBuild"` unless you have a specific reason to use the last build.
|
|
80
182
|
*/
|
|
81
|
-
export declare function getLlama(): Promise<Llama>;
|
|
82
|
-
export declare function getLlama(options: LlamaOptions, lastBuildOptions?: never): Promise<Llama>;
|
|
183
|
+
export declare function getLlama(options?: LlamaOptions): Promise<Llama>;
|
|
83
184
|
export declare function getLlama(type: "lastBuild", lastBuildOptions?: LastBuildOptions): Promise<Llama>;
|
|
185
|
+
export declare function getLlamaForOptions({ gpu, logLevel, logger, build, cmakeOptions, existingPrebuiltBinaryMustMatchBuildOptions, usePrebuiltBinaries, progressLogs, skipDownload, maxThreads, vramPadding, debug }: LlamaOptions, { updateLastBuildInfoOnCompile, skipLlamaInit }?: {
|
|
186
|
+
updateLastBuildInfoOnCompile?: boolean;
|
|
187
|
+
skipLlamaInit?: boolean;
|
|
188
|
+
}): Promise<Llama>;
|
|
@@ -2,10 +2,11 @@ import process from "process";
|
|
|
2
2
|
import path from "path";
|
|
3
3
|
import console from "console";
|
|
4
4
|
import { createRequire } from "module";
|
|
5
|
-
import { builtinLlamaCppGitHubRepo, builtinLlamaCppRelease,
|
|
5
|
+
import { builtinLlamaCppGitHubRepo, builtinLlamaCppRelease, defaultLlamaCppLogLevel, defaultLlamaCppGitHubRepo, defaultLlamaCppGpuSupport, defaultLlamaCppRelease, defaultSkipDownload, llamaLocalBuildBinsDirectory, recommendedBaseDockerImage, defaultLlamaCppDebugMode } from "../config.js";
|
|
6
6
|
import { getConsoleLogPrefix } from "../utils/getConsoleLogPrefix.js";
|
|
7
7
|
import { waitForLockfileRelease } from "../utils/waitForLockfileRelease.js";
|
|
8
8
|
import { isGithubReleaseNeedsResolving, resolveGithubRelease } from "../utils/resolveGithubRelease.js";
|
|
9
|
+
import { runningInsideAsar, runningInElectron } from "../utils/runtime.js";
|
|
9
10
|
import { compileLlamaCpp, getLocalBuildBinaryBuildMetadata, getLocalBuildBinaryPath, getPrebuiltBinaryBuildMetadata, getPrebuiltBinaryPath } from "./utils/compileLLamaCpp.js";
|
|
10
11
|
import { getLastBuildInfo } from "./utils/lastBuildInfo.js";
|
|
11
12
|
import { getClonedLlamaCppRepoReleaseInfo, isLlamaCppRepoCloned } from "./utils/cloneLlamaCppRepo.js";
|
|
@@ -15,54 +16,70 @@ import { resolveCustomCmakeOptions } from "./utils/resolveCustomCmakeOptions.js"
|
|
|
15
16
|
import { getCanUsePrebuiltBinaries } from "./utils/getCanUsePrebuiltBinaries.js";
|
|
16
17
|
import { NoBinaryFoundError } from "./utils/NoBinaryFoundError.js";
|
|
17
18
|
import { Llama } from "./Llama.js";
|
|
19
|
+
import { getGpuTypesToUseForOption } from "./utils/getGpuTypesToUseForOption.js";
|
|
20
|
+
import { getPrettyBuildGpuName } from "./consts.js";
|
|
21
|
+
import { detectGlibc } from "./utils/detectGlibc.js";
|
|
22
|
+
import { getLinuxDistroInfo, isDistroAlpineLinux } from "./utils/getLinuxDistroInfo.js";
|
|
23
|
+
import { testBindingBinary } from "./utils/testBindingBinary.js";
|
|
24
|
+
import { getPlatformInfo } from "./utils/getPlatformInfo.js";
|
|
25
|
+
import { hasBuildingFromSourceDependenciesInstalled } from "./utils/hasBuildingFromSourceDependenciesInstalled.js";
|
|
18
26
|
const require = createRequire(import.meta.url);
|
|
19
27
|
export const getLlamaFunctionName = "getLlama";
|
|
28
|
+
export const defaultLlamaVramPadding = (totalVram) => Math.floor(Math.min(totalVram * 0.06, 1024 * 1024 * 1024));
|
|
29
|
+
const defaultBuildOption = runningInElectron
|
|
30
|
+
? "never"
|
|
31
|
+
: "auto";
|
|
20
32
|
export async function getLlama(options, lastBuildOptions) {
|
|
21
33
|
if (options === "lastBuild") {
|
|
22
34
|
const lastBuildInfo = await getLastBuildInfo();
|
|
35
|
+
const getLlamaOptions = {
|
|
36
|
+
logLevel: lastBuildOptions?.logLevel ?? defaultLlamaCppLogLevel,
|
|
37
|
+
logger: lastBuildOptions?.logger ?? Llama.defaultConsoleLogger,
|
|
38
|
+
usePrebuiltBinaries: lastBuildOptions?.usePrebuiltBinaries ?? true,
|
|
39
|
+
progressLogs: lastBuildOptions?.progressLogs ?? true,
|
|
40
|
+
skipDownload: lastBuildOptions?.skipDownload ?? defaultSkipDownload,
|
|
41
|
+
maxThreads: lastBuildOptions?.maxThreads,
|
|
42
|
+
vramPadding: lastBuildOptions?.vramPadding ?? defaultLlamaVramPadding,
|
|
43
|
+
debug: lastBuildOptions?.debug ?? defaultLlamaCppDebugMode
|
|
44
|
+
};
|
|
23
45
|
if (lastBuildInfo == null)
|
|
24
|
-
return getLlamaForOptions(
|
|
46
|
+
return getLlamaForOptions(getLlamaOptions);
|
|
25
47
|
const localBuildFolder = path.join(llamaLocalBuildBinsDirectory, lastBuildInfo.folderName);
|
|
26
48
|
const localBuildBinPath = await getLocalBuildBinaryPath(lastBuildInfo.folderName);
|
|
27
49
|
await waitForLockfileRelease({ resourcePath: localBuildFolder });
|
|
28
50
|
if (localBuildBinPath != null) {
|
|
29
51
|
try {
|
|
30
|
-
const binding =
|
|
52
|
+
const binding = loadBindingModule(localBuildBinPath);
|
|
31
53
|
const buildMetadata = await getLocalBuildBinaryBuildMetadata(lastBuildInfo.folderName);
|
|
32
54
|
return await Llama._create({
|
|
33
55
|
bindings: binding,
|
|
34
56
|
buildType: "localBuild",
|
|
35
57
|
buildMetadata,
|
|
36
58
|
logger: lastBuildOptions?.logger ?? Llama.defaultConsoleLogger,
|
|
37
|
-
logLevel: lastBuildOptions?.logLevel ??
|
|
59
|
+
logLevel: lastBuildOptions?.logLevel ?? defaultLlamaCppLogLevel,
|
|
60
|
+
maxThreads: lastBuildOptions?.maxThreads,
|
|
61
|
+
vramPadding: lastBuildOptions?.vramPadding ?? defaultLlamaVramPadding,
|
|
62
|
+
debug: lastBuildOptions?.debug ?? defaultLlamaCppDebugMode
|
|
38
63
|
});
|
|
39
64
|
}
|
|
40
65
|
catch (err) {
|
|
41
66
|
console.error(getConsoleLogPrefix() + "Failed to load last build. Error:", err);
|
|
42
67
|
console.info(getConsoleLogPrefix() + "Falling back to default binaries");
|
|
43
|
-
try {
|
|
44
|
-
delete require.cache[require.resolve(localBuildBinPath)];
|
|
45
|
-
}
|
|
46
|
-
catch (err) { }
|
|
47
68
|
}
|
|
48
69
|
}
|
|
49
|
-
return getLlamaForOptions(
|
|
70
|
+
return getLlamaForOptions(getLlamaOptions);
|
|
50
71
|
}
|
|
51
72
|
return getLlamaForOptions(options ?? {});
|
|
52
73
|
}
|
|
53
|
-
async function getLlamaForOptions({
|
|
74
|
+
export async function getLlamaForOptions({ gpu = defaultLlamaCppGpuSupport, logLevel = defaultLlamaCppLogLevel, logger = Llama.defaultConsoleLogger, build = defaultBuildOption, cmakeOptions = {}, existingPrebuiltBinaryMustMatchBuildOptions = false, usePrebuiltBinaries = true, progressLogs = true, skipDownload = defaultSkipDownload, maxThreads, vramPadding = defaultLlamaVramPadding, debug = defaultLlamaCppDebugMode }, { updateLastBuildInfoOnCompile = false, skipLlamaInit = false } = {}) {
|
|
54
75
|
const platform = getPlatform();
|
|
55
76
|
const arch = process.arch;
|
|
56
|
-
if (platform !== "mac")
|
|
57
|
-
metal = false;
|
|
58
|
-
else if (platform === "mac" && arch === "arm64")
|
|
59
|
-
cuda = false;
|
|
60
77
|
if (logLevel == null)
|
|
61
|
-
logLevel =
|
|
78
|
+
logLevel = defaultLlamaCppLogLevel;
|
|
62
79
|
if (logger == null)
|
|
63
80
|
logger = Llama.defaultConsoleLogger;
|
|
64
81
|
if (build == null)
|
|
65
|
-
build =
|
|
82
|
+
build = defaultBuildOption;
|
|
66
83
|
if (cmakeOptions == null)
|
|
67
84
|
cmakeOptions = {};
|
|
68
85
|
if (existingPrebuiltBinaryMustMatchBuildOptions == null)
|
|
@@ -73,107 +90,240 @@ async function getLlamaForOptions({ metal = defaultLlamaCppMetalSupport, cuda =
|
|
|
73
90
|
progressLogs = true;
|
|
74
91
|
if (skipDownload == null)
|
|
75
92
|
skipDownload = defaultSkipDownload;
|
|
93
|
+
if (vramPadding == null)
|
|
94
|
+
vramPadding = defaultLlamaVramPadding;
|
|
95
|
+
if (debug == null)
|
|
96
|
+
debug = defaultLlamaCppDebugMode;
|
|
76
97
|
const clonedLlamaCppRepoReleaseInfo = await getClonedLlamaCppRepoReleaseInfo();
|
|
77
|
-
|
|
78
|
-
customCmakeOptions: resolveCustomCmakeOptions(cmakeOptions),
|
|
79
|
-
progressLogs,
|
|
80
|
-
platform,
|
|
81
|
-
arch,
|
|
82
|
-
computeLayers: {
|
|
83
|
-
metal,
|
|
84
|
-
cuda
|
|
85
|
-
},
|
|
86
|
-
llamaCpp: {
|
|
87
|
-
repo: clonedLlamaCppRepoReleaseInfo?.llamaCppGithubRepo ?? builtinLlamaCppGitHubRepo,
|
|
88
|
-
release: clonedLlamaCppRepoReleaseInfo?.tag ?? builtinLlamaCppRelease
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const canUsePrebuiltBinaries = (build === "forceRebuild" || !usePrebuiltBinaries)
|
|
98
|
+
let canUsePrebuiltBinaries = (build === "forceRebuild" || !usePrebuiltBinaries)
|
|
92
99
|
? false
|
|
93
100
|
: await getCanUsePrebuiltBinaries();
|
|
94
|
-
|
|
101
|
+
const buildGpusToTry = await getGpuTypesToUseForOption(gpu, { platform, arch });
|
|
102
|
+
const platformInfo = await getPlatformInfo();
|
|
103
|
+
const llamaCppInfo = {
|
|
104
|
+
repo: clonedLlamaCppRepoReleaseInfo?.llamaCppGithubRepo ?? builtinLlamaCppGitHubRepo,
|
|
105
|
+
release: clonedLlamaCppRepoReleaseInfo?.tag ?? builtinLlamaCppRelease
|
|
106
|
+
};
|
|
107
|
+
let shouldLogNoGlibcWarningIfNoBuildIsAvailable = false;
|
|
108
|
+
const canBuild = build !== "never" && !runningInsideAsar &&
|
|
109
|
+
(!runningInElectron || await hasBuildingFromSourceDependenciesInstalled());
|
|
110
|
+
if (canUsePrebuiltBinaries && platform === "linux") {
|
|
111
|
+
if (!(await detectGlibc({ platform }))) {
|
|
112
|
+
canUsePrebuiltBinaries = false;
|
|
113
|
+
shouldLogNoGlibcWarningIfNoBuildIsAvailable = true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (buildGpusToTry.length === 0)
|
|
117
|
+
throw new Error("No GPU types available to try building with");
|
|
95
118
|
if (build === "auto" || build === "never") {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
119
|
+
for (let i = 0; i < buildGpusToTry.length; i++) {
|
|
120
|
+
const gpu = buildGpusToTry[i];
|
|
121
|
+
const isLastItem = i === buildGpusToTry.length - 1;
|
|
122
|
+
if (gpu == null)
|
|
123
|
+
continue;
|
|
124
|
+
const buildOptions = {
|
|
125
|
+
customCmakeOptions: resolveCustomCmakeOptions(cmakeOptions),
|
|
126
|
+
progressLogs,
|
|
127
|
+
platform,
|
|
128
|
+
platformInfo,
|
|
129
|
+
arch,
|
|
130
|
+
gpu,
|
|
131
|
+
llamaCpp: llamaCppInfo
|
|
132
|
+
};
|
|
133
|
+
const llama = await loadExistingLlamaBinary({
|
|
134
|
+
buildOptions,
|
|
135
|
+
canUsePrebuiltBinaries,
|
|
136
|
+
logLevel,
|
|
137
|
+
logger,
|
|
138
|
+
existingPrebuiltBinaryMustMatchBuildOptions,
|
|
139
|
+
progressLogs,
|
|
140
|
+
platform,
|
|
141
|
+
platformInfo,
|
|
142
|
+
skipLlamaInit,
|
|
143
|
+
maxThreads,
|
|
144
|
+
vramPadding,
|
|
145
|
+
fallbackMessage: !isLastItem
|
|
146
|
+
? `falling back to using ${getPrettyBuildGpuName(buildGpusToTry[i + 1])}`
|
|
147
|
+
: (canBuild
|
|
148
|
+
? "falling back to building from source"
|
|
149
|
+
: null),
|
|
150
|
+
debug
|
|
151
|
+
});
|
|
152
|
+
if (llama != null)
|
|
153
|
+
return llama;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (shouldLogNoGlibcWarningIfNoBuildIsAvailable && progressLogs)
|
|
157
|
+
await logNoGlibcWarning();
|
|
158
|
+
if (!canBuild)
|
|
159
|
+
throw new NoBinaryFoundError();
|
|
160
|
+
const llamaCppRepoCloned = await isLlamaCppRepoCloned();
|
|
161
|
+
if (!llamaCppRepoCloned) {
|
|
162
|
+
if (skipDownload)
|
|
163
|
+
throw new NoBinaryFoundError("No prebuilt binaries found, no llama.cpp source found and `skipDownload` or NODE_LLAMA_CPP_SKIP_DOWNLOAD env var is set to true, so llama.cpp cannot be built from source");
|
|
164
|
+
llamaCppInfo.repo = defaultLlamaCppGitHubRepo;
|
|
165
|
+
llamaCppInfo.release = defaultLlamaCppRelease;
|
|
166
|
+
if (isGithubReleaseNeedsResolving(llamaCppInfo.release)) {
|
|
167
|
+
const [owner, name] = defaultLlamaCppGitHubRepo.split("/");
|
|
168
|
+
llamaCppInfo.release = await resolveGithubRelease(owner, name, llamaCppInfo.release);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
for (let i = 0; i < buildGpusToTry.length; i++) {
|
|
172
|
+
const gpu = buildGpusToTry[i];
|
|
173
|
+
const isLastItem = i === buildGpusToTry.length - 1;
|
|
174
|
+
if (gpu == null)
|
|
175
|
+
continue;
|
|
176
|
+
const buildOptions = {
|
|
177
|
+
customCmakeOptions: resolveCustomCmakeOptions(cmakeOptions),
|
|
178
|
+
progressLogs,
|
|
179
|
+
platform,
|
|
180
|
+
platformInfo,
|
|
181
|
+
arch,
|
|
182
|
+
gpu,
|
|
183
|
+
llamaCpp: llamaCppInfo
|
|
184
|
+
};
|
|
185
|
+
try {
|
|
186
|
+
return await buildAndLoadLlamaBinary({
|
|
187
|
+
buildOptions,
|
|
188
|
+
skipDownload,
|
|
189
|
+
logLevel,
|
|
190
|
+
logger,
|
|
191
|
+
updateLastBuildInfoOnCompile,
|
|
192
|
+
maxThreads,
|
|
193
|
+
vramPadding,
|
|
194
|
+
skipLlamaInit,
|
|
195
|
+
debug
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
catch (err) {
|
|
199
|
+
console.error(getConsoleLogPrefix() +
|
|
200
|
+
`Failed to build llama.cpp with ${getPrettyBuildGpuName(gpu)} support. ` +
|
|
201
|
+
(!isLastItem
|
|
202
|
+
? `falling back to building llama.cpp with ${getPrettyBuildGpuName(buildGpusToTry[i + 1])} support. `
|
|
203
|
+
: "") +
|
|
204
|
+
"Error:", err);
|
|
205
|
+
if (isLastItem)
|
|
206
|
+
throw err;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
throw new Error("Failed to build llama.cpp");
|
|
210
|
+
}
|
|
211
|
+
async function loadExistingLlamaBinary({ buildOptions, canUsePrebuiltBinaries, logLevel, logger, existingPrebuiltBinaryMustMatchBuildOptions, progressLogs, platform, platformInfo, skipLlamaInit, maxThreads, vramPadding, fallbackMessage, debug }) {
|
|
212
|
+
const buildFolderName = await getBuildFolderNameForBuildOptions(buildOptions);
|
|
213
|
+
const localBuildFolder = path.join(llamaLocalBuildBinsDirectory, buildFolderName.withCustomCmakeOptions);
|
|
214
|
+
const localBuildBinPath = await getLocalBuildBinaryPath(buildFolderName.withCustomCmakeOptions);
|
|
215
|
+
await waitForLockfileRelease({ resourcePath: localBuildFolder });
|
|
216
|
+
if (localBuildBinPath != null) {
|
|
217
|
+
try {
|
|
218
|
+
const buildMetadata = await getLocalBuildBinaryBuildMetadata(buildFolderName.withCustomCmakeOptions);
|
|
219
|
+
const shouldTestBinaryBeforeLoading = getShouldTestBinaryBeforeLoading({
|
|
220
|
+
isPrebuiltBinary: false,
|
|
221
|
+
platform,
|
|
222
|
+
platformInfo,
|
|
223
|
+
buildMetadata
|
|
224
|
+
});
|
|
225
|
+
const binaryCompatible = shouldTestBinaryBeforeLoading
|
|
226
|
+
? await testBindingBinary(localBuildBinPath)
|
|
227
|
+
: true;
|
|
228
|
+
if (binaryCompatible) {
|
|
229
|
+
const binding = loadBindingModule(localBuildBinPath);
|
|
103
230
|
return await Llama._create({
|
|
104
231
|
bindings: binding,
|
|
105
232
|
buildType: "localBuild",
|
|
106
233
|
buildMetadata,
|
|
107
234
|
logLevel,
|
|
108
|
-
logger
|
|
235
|
+
logger,
|
|
236
|
+
maxThreads,
|
|
237
|
+
vramPadding,
|
|
238
|
+
skipLlamaInit,
|
|
239
|
+
debug
|
|
109
240
|
});
|
|
110
241
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
catch (err) { }
|
|
242
|
+
else if (progressLogs) {
|
|
243
|
+
console.warn(getConsoleLogPrefix() + "The local build binary was not built in the current system and is incompatible with it");
|
|
244
|
+
if (canUsePrebuiltBinaries)
|
|
245
|
+
console.info(getConsoleLogPrefix() + "Falling back to prebuilt binaries");
|
|
246
|
+
else if (fallbackMessage != null)
|
|
247
|
+
console.info(getConsoleLogPrefix() + fallbackMessage);
|
|
119
248
|
}
|
|
120
249
|
}
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
250
|
+
catch (err) {
|
|
251
|
+
const binaryDescription = describeBinary(buildOptions);
|
|
252
|
+
console.error(getConsoleLogPrefix() + `Failed to load a local build ${binaryDescription}. Error:`, err);
|
|
253
|
+
if (canUsePrebuiltBinaries)
|
|
254
|
+
console.info(getConsoleLogPrefix() + "Falling back to prebuilt binaries");
|
|
255
|
+
else if (fallbackMessage != null)
|
|
256
|
+
console.info(getConsoleLogPrefix() + fallbackMessage);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
if (canUsePrebuiltBinaries) {
|
|
260
|
+
const prebuiltBinDetails = await getPrebuiltBinaryPath(buildOptions, existingPrebuiltBinaryMustMatchBuildOptions
|
|
261
|
+
? buildFolderName.withCustomCmakeOptions
|
|
262
|
+
: buildFolderName.withoutCustomCmakeOptions);
|
|
263
|
+
if (prebuiltBinDetails != null) {
|
|
264
|
+
try {
|
|
265
|
+
const buildMetadata = await getPrebuiltBinaryBuildMetadata(prebuiltBinDetails.folderPath, prebuiltBinDetails.folderName);
|
|
266
|
+
const shouldTestBinaryBeforeLoading = getShouldTestBinaryBeforeLoading({
|
|
267
|
+
isPrebuiltBinary: true,
|
|
268
|
+
platform,
|
|
269
|
+
platformInfo,
|
|
270
|
+
buildMetadata
|
|
271
|
+
});
|
|
272
|
+
const binaryCompatible = shouldTestBinaryBeforeLoading
|
|
273
|
+
? await testBindingBinary(prebuiltBinDetails.binaryPath)
|
|
274
|
+
: true;
|
|
275
|
+
if (binaryCompatible) {
|
|
276
|
+
const binding = loadBindingModule(prebuiltBinDetails.binaryPath);
|
|
129
277
|
return await Llama._create({
|
|
130
278
|
bindings: binding,
|
|
131
279
|
buildType: "prebuilt",
|
|
132
280
|
buildMetadata,
|
|
133
281
|
logLevel,
|
|
134
|
-
logger
|
|
282
|
+
logger,
|
|
283
|
+
maxThreads,
|
|
284
|
+
vramPadding,
|
|
285
|
+
skipLlamaInit,
|
|
286
|
+
debug
|
|
135
287
|
});
|
|
136
288
|
}
|
|
137
|
-
|
|
289
|
+
else if (progressLogs) {
|
|
138
290
|
const binaryDescription = describeBinary({
|
|
139
291
|
...buildOptions,
|
|
140
292
|
customCmakeOptions: existingPrebuiltBinaryMustMatchBuildOptions
|
|
141
293
|
? buildOptions.customCmakeOptions
|
|
142
294
|
: new Map()
|
|
143
295
|
});
|
|
144
|
-
console.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
delete require.cache[require.resolve(prebuiltBinPath)];
|
|
149
|
-
}
|
|
150
|
-
catch (err) { }
|
|
296
|
+
console.warn(getConsoleLogPrefix() +
|
|
297
|
+
`The prebuilt ${binaryDescription} is not compatible with the current system` + (fallbackMessage != null
|
|
298
|
+
? ", " + fallbackMessage
|
|
299
|
+
: ""));
|
|
151
300
|
}
|
|
152
301
|
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
throw new NoBinaryFoundError("No prebuilt binaries found, no llama.cpp source found and `skipDownload` or NODE_LLAMA_CPP_SKIP_DOWNLOAD env var is set to true, so llama.cpp cannot be built from source");
|
|
165
|
-
buildOptions.llamaCpp.repo = defaultLlamaCppGitHubRepo;
|
|
166
|
-
buildOptions.llamaCpp.release = defaultLlamaCppRelease;
|
|
167
|
-
if (isGithubReleaseNeedsResolving(buildOptions.llamaCpp.release)) {
|
|
168
|
-
const [owner, name] = defaultLlamaCppGitHubRepo.split("/");
|
|
169
|
-
buildOptions.llamaCpp.release = await resolveGithubRelease(owner, name, buildOptions.llamaCpp.release);
|
|
170
|
-
buildFolderName = await getBuildFolderNameForBuildOptions(buildOptions);
|
|
302
|
+
catch (err) {
|
|
303
|
+
const binaryDescription = describeBinary({
|
|
304
|
+
...buildOptions,
|
|
305
|
+
customCmakeOptions: existingPrebuiltBinaryMustMatchBuildOptions
|
|
306
|
+
? buildOptions.customCmakeOptions
|
|
307
|
+
: new Map()
|
|
308
|
+
});
|
|
309
|
+
console.error(getConsoleLogPrefix() + `Failed to load a prebuilt ${binaryDescription}` + (fallbackMessage != null
|
|
310
|
+
? ", " + fallbackMessage
|
|
311
|
+
: "") + ". Error:", err);
|
|
312
|
+
}
|
|
171
313
|
}
|
|
314
|
+
else if (progressLogs)
|
|
315
|
+
console.warn(getConsoleLogPrefix() + "A prebuilt binary was not found" + (fallbackMessage != null
|
|
316
|
+
? ", " + fallbackMessage
|
|
317
|
+
: ""));
|
|
172
318
|
}
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
async function buildAndLoadLlamaBinary({ buildOptions, skipDownload, logLevel, logger, updateLastBuildInfoOnCompile, maxThreads, vramPadding, skipLlamaInit, debug }) {
|
|
322
|
+
const buildFolderName = await getBuildFolderNameForBuildOptions(buildOptions);
|
|
173
323
|
await compileLlamaCpp(buildOptions, {
|
|
174
324
|
ensureLlamaCppRepoIsCloned: !skipDownload,
|
|
175
325
|
downloadCmakeIfNeeded: true,
|
|
176
|
-
updateLastBuildInfo:
|
|
326
|
+
updateLastBuildInfo: updateLastBuildInfoOnCompile
|
|
177
327
|
});
|
|
178
328
|
const localBuildFolder = path.join(llamaLocalBuildBinsDirectory, buildFolderName.withCustomCmakeOptions);
|
|
179
329
|
await waitForLockfileRelease({ resourcePath: localBuildFolder });
|
|
@@ -181,23 +331,40 @@ async function getLlamaForOptions({ metal = defaultLlamaCppMetalSupport, cuda =
|
|
|
181
331
|
if (localBuildBinPath == null) {
|
|
182
332
|
throw new Error("Failed to build llama.cpp");
|
|
183
333
|
}
|
|
184
|
-
const binding =
|
|
334
|
+
const binding = loadBindingModule(localBuildBinPath);
|
|
185
335
|
const buildMetadata = await getLocalBuildBinaryBuildMetadata(buildFolderName.withCustomCmakeOptions);
|
|
186
336
|
return await Llama._create({
|
|
187
337
|
bindings: binding,
|
|
188
338
|
buildType: "localBuild",
|
|
189
339
|
buildMetadata,
|
|
190
340
|
logLevel,
|
|
191
|
-
logger
|
|
341
|
+
logger,
|
|
342
|
+
maxThreads,
|
|
343
|
+
vramPadding,
|
|
344
|
+
skipLlamaInit,
|
|
345
|
+
debug
|
|
192
346
|
});
|
|
193
347
|
}
|
|
348
|
+
async function logNoGlibcWarning() {
|
|
349
|
+
console.warn(getConsoleLogPrefix() +
|
|
350
|
+
"The prebuilt binaries cannot be used in this Linux distro, as `glibc` is not detected");
|
|
351
|
+
const linuxDistroInfo = await getLinuxDistroInfo();
|
|
352
|
+
const isAlpineLinux = await isDistroAlpineLinux(linuxDistroInfo);
|
|
353
|
+
if (isAlpineLinux) {
|
|
354
|
+
console.warn(getConsoleLogPrefix() +
|
|
355
|
+
"Using Alpine Linux is not recommended for running LLMs, " +
|
|
356
|
+
"as using GPU drivers is complicated and suboptimal in this distro at the moment.\n" +
|
|
357
|
+
getConsoleLogPrefix() +
|
|
358
|
+
"Consider using a different Linux distro, such as Debian or Ubuntu.\n" +
|
|
359
|
+
getConsoleLogPrefix() +
|
|
360
|
+
`If you're trying to run this inside of a Docker container, consider using "${recommendedBaseDockerImage}" image`);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
194
363
|
function describeBinary(binaryOptions) {
|
|
195
364
|
let res = `binary for platform "${binaryOptions.platform}" "${binaryOptions.arch}"`;
|
|
196
365
|
const additions = [];
|
|
197
|
-
if (binaryOptions.
|
|
198
|
-
additions.push(
|
|
199
|
-
if (binaryOptions.computeLayers.cuda)
|
|
200
|
-
additions.push("with CUDA support");
|
|
366
|
+
if (binaryOptions.gpu != false)
|
|
367
|
+
additions.push(`with ${getPrettyBuildGpuName(binaryOptions.gpu)} support`);
|
|
201
368
|
if (binaryOptions.customCmakeOptions.size > 0)
|
|
202
369
|
additions.push("with custom build options");
|
|
203
370
|
res += additions
|
|
@@ -213,4 +380,35 @@ function describeBinary(binaryOptions) {
|
|
|
213
380
|
.join("");
|
|
214
381
|
return res;
|
|
215
382
|
}
|
|
383
|
+
function loadBindingModule(bindingModulePath) {
|
|
384
|
+
// each llama instance has its own settings, such as a different logger, so we have to make sure we load a new instance every time
|
|
385
|
+
try {
|
|
386
|
+
delete require.cache[require.resolve(bindingModulePath)];
|
|
387
|
+
}
|
|
388
|
+
catch (err) { }
|
|
389
|
+
try {
|
|
390
|
+
const binding = require(bindingModulePath);
|
|
391
|
+
return binding;
|
|
392
|
+
}
|
|
393
|
+
finally {
|
|
394
|
+
try {
|
|
395
|
+
delete require.cache[require.resolve(bindingModulePath)];
|
|
396
|
+
}
|
|
397
|
+
catch (err) { }
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function getShouldTestBinaryBeforeLoading({ isPrebuiltBinary, platform, platformInfo, buildMetadata }) {
|
|
401
|
+
if (platform === "linux") {
|
|
402
|
+
if (isPrebuiltBinary)
|
|
403
|
+
return true;
|
|
404
|
+
if (platformInfo.name !== buildMetadata.buildOptions.platformInfo.name ||
|
|
405
|
+
platformInfo.version !== buildMetadata.buildOptions.platformInfo.version)
|
|
406
|
+
return true;
|
|
407
|
+
}
|
|
408
|
+
else if (platform === "win") {
|
|
409
|
+
if (buildMetadata.buildOptions.gpu !== false)
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
return false;
|
|
413
|
+
}
|
|
216
414
|
//# sourceMappingURL=getLlama.js.map
|