@realtimex/node-llama-cpp 0.1.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/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/ChatWrapper.d.ts +27 -0
- package/dist/ChatWrapper.js +233 -0
- package/dist/ChatWrapper.js.map +1 -0
- 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 +203 -0
- package/dist/bindings/AddonTypes.js +2 -0
- package/dist/bindings/AddonTypes.js.map +1 -0
- package/dist/bindings/Llama.d.ts +104 -0
- package/dist/bindings/Llama.js +570 -0
- package/dist/bindings/Llama.js.map +1 -0
- 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 +297 -0
- package/dist/bindings/getLlama.js +569 -0
- package/dist/bindings/getLlama.js.map +1 -0
- package/dist/bindings/types.d.ts +72 -0
- package/dist/bindings/types.js +105 -0
- package/dist/bindings/types.js.map +1 -0
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +23 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +50 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
- package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
- package/dist/bindings/utils/NoBinaryFoundError.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 +29 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/binariesGithubRelease.d.ts +6 -0
- package/dist/bindings/utils/binariesGithubRelease.js +15 -0
- package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js +166 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
- package/dist/bindings/utils/compileLLamaCpp.d.ts +22 -0
- package/dist/bindings/utils/compileLLamaCpp.js +526 -0
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +18 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +311 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectBuildTools.d.ts +14 -0
- package/dist/bindings/utils/detectBuildTools.js +149 -0
- package/dist/bindings/utils/detectBuildTools.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +74 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/disposeBeforeExit.d.ts +8 -0
- package/dist/bindings/utils/disposeBeforeExit.js +36 -0
- package/dist/bindings/utils/disposeBeforeExit.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.d.ts +6 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +105 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
- 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/getLlamaGpuTypes.d.ts +13 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js +36 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +40 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.d.ts +2 -0
- package/dist/bindings/utils/getPlatform.js +15 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -0
- 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.d.ts +6 -0
- package/dist/bindings/utils/lastBuildInfo.js +17 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +22 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
- 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/resolveActualBindingBinaryPath.d.ts +1 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js +18 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
- package/dist/bindings/utils/testBindingBinary.d.ts +2 -0
- package/dist/bindings/utils/testBindingBinary.js +269 -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 +17 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js +33 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +6 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js +85 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.d.ts +37 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js +294 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js.map +1 -0
- package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
- package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FalconChatWrapper.d.ts +19 -0
- package/dist/chatWrappers/FalconChatWrapper.js +126 -0
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +17 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js +622 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
- 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 +19 -0
- package/dist/chatWrappers/GeneralChatWrapper.js +140 -0
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/HarmonyChatWrapper.d.ts +78 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js +539 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/Llama2ChatWrapper.js +95 -0
- 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 +32 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +290 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +264 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/MistralChatWrapper.js +180 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/QwenChatWrapper.d.ts +36 -0
- package/dist/chatWrappers/QwenChatWrapper.js +344 -0
- package/dist/chatWrappers/QwenChatWrapper.js.map +1 -0
- package/dist/chatWrappers/SeedChatWrapper.d.ts +25 -0
- package/dist/chatWrappers/SeedChatWrapper.js +183 -0
- package/dist/chatWrappers/SeedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +138 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +665 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +76 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +212 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.d.ts +7 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js +30 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +24 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.d.ts +25 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js +690 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js +66 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.d.ts +6 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js +19 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js.map +1 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js +35 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js.map +1 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.d.ts +22 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js +28 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +76 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +177 -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/getModelLinageNames.d.ts +2 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js +18 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +394 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.d.ts +2 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js +9 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.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 +148 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +325 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.js +45 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/ChatCommand.d.ts +59 -0
- package/dist/cli/commands/ChatCommand.js +856 -0
- package/dist/cli/commands/ChatCommand.js.map +1 -0
- package/dist/cli/commands/CompleteCommand.d.ts +47 -0
- package/dist/cli/commands/CompleteCommand.js +658 -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 +55 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +49 -0
- package/dist/cli/commands/InfillCommand.js +693 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +12 -0
- package/dist/cli/commands/InitCommand.js +230 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.d.ts +4 -0
- package/dist/cli/commands/OnPostInstallCommand.js +62 -0
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -0
- 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 +17 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +275 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +13 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +230 -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 +296 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +26 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +869 -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/source/commands/ClearCommand.d.ts +7 -0
- package/dist/cli/commands/source/commands/ClearCommand.js +54 -0
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/DownloadCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js +219 -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 +428 -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 +24 -0
- package/dist/cli/utils/ConsoleTable.js +90 -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 +81 -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 +13 -0
- package/dist/cli/utils/interactivelyAskForModel.js +485 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.d.ts +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.js +20 -0
- package/dist/cli/utils/isRunningUnderRosetta.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/packageJsonConfig.d.ts +6 -0
- package/dist/cli/utils/packageJsonConfig.js +51 -0
- package/dist/cli/utils/packageJsonConfig.js.map +1 -0
- package/dist/cli/utils/packageManager.d.ts +1 -0
- package/dist/cli/utils/packageManager.js +15 -0
- package/dist/cli/utils/packageManager.js.map +1 -0
- package/dist/cli/utils/parseXtcArg.d.ts +5 -0
- package/dist/cli/utils/parseXtcArg.js +16 -0
- package/dist/cli/utils/parseXtcArg.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +12 -0
- package/dist/cli/utils/printCommonInfoLines.js +163 -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/printModelDestination.d.ts +2 -0
- package/dist/cli/utils/printModelDestination.js +11 -0
- package/dist/cli/utils/printModelDestination.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 +19 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +123 -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 +14 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +12 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/resolveNpmrcConfig.d.ts +18 -0
- package/dist/cli/utils/resolveNpmrcConfig.js +129 -0
- package/dist/cli/utils/resolveNpmrcConfig.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/toBytes.d.ts +1 -0
- package/dist/cli/utils/toBytes.js +5 -0
- package/dist/cli/utils/toBytes.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 +6 -0
- package/dist/commands.js +9 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- 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 +500 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js +2696 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
- 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.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +260 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +520 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +628 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +45 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +191 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +15 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +16 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
- package/dist/evaluator/LlamaCompletion.d.ts +219 -0
- package/dist/evaluator/LlamaCompletion.js +498 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +336 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js +1919 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.d.ts +27 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js +130 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +39 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.d.ts +55 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js +20 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.d.ts +56 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js +266 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.d.ts +58 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js +138 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +602 -0
- package/dist/evaluator/LlamaContext/types.js +2 -0
- package/dist/evaluator/LlamaContext/types.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js +16 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js +42 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.d.ts +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js +18 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js +13 -0
- 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 +52 -0
- package/dist/evaluator/LlamaEmbeddingContext.js +86 -0
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
- package/dist/evaluator/LlamaGrammar.d.ts +39 -0
- package/dist/evaluator/LlamaGrammar.js +72 -0
- package/dist/evaluator/LlamaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +19 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js +29 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +17 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +35 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +344 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +853 -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/LlamaRankingContext.d.ts +91 -0
- package/dist/evaluator/LlamaRankingContext.js +178 -0
- package/dist/evaluator/LlamaRankingContext.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +37 -0
- package/dist/evaluator/TokenBias.js +68 -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/evaluator/utils/chunkDocument.d.ts +86 -0
- package/dist/evaluator/utils/chunkDocument.js +212 -0
- package/dist/evaluator/utils/chunkDocument.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 +106 -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 +28 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +94 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +78 -0
- package/dist/gguf/insights/GgufInsights.js +854 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +203 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +284 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsTokens.d.ts +5 -0
- package/dist/gguf/insights/GgufInsightsTokens.js +40 -0
- package/dist/gguf/insights/GgufInsightsTokens.js.map +1 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.d.ts +5 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js +7 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +33 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +117 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +20 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +251 -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 +184 -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 +54 -0
- package/dist/gguf/readGgufFileInfo.js +82 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +85 -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 +480 -0
- package/dist/gguf/types/GgufMetadataTypes.js +194 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +63 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +54 -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/getGgufMetadataKeyValue.d.ts +1 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js +27 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js.map +1 -0
- package/dist/gguf/utils/ggufQuantNames.d.ts +2 -0
- package/dist/gguf/utils/ggufQuantNames.js +42 -0
- package/dist/gguf/utils/ggufQuantNames.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +2 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +18 -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 +38 -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 +64 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +22 -0
- package/dist/state.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +408 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- 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 +92 -0
- package/dist/utils/LlamaText.js +527 -0
- package/dist/utils/LlamaText.js.map +1 -0
- 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/OpenAIFormat.d.ts +177 -0
- package/dist/utils/OpenAIFormat.js +488 -0
- package/dist/utils/OpenAIFormat.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.d.ts +9 -0
- package/dist/utils/ReplHistory.js +72 -0
- package/dist/utils/ReplHistory.js.map +1 -0
- package/dist/utils/StopGenerationDetector.d.ts +47 -0
- package/dist/utils/StopGenerationDetector.js +291 -0
- package/dist/utils/StopGenerationDetector.js.map +1 -0
- 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 +38 -0
- package/dist/utils/TokenStreamRegulator.js +200 -0
- package/dist/utils/TokenStreamRegulator.js.map +1 -0
- 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 +6 -0
- package/dist/utils/appendUserMessageToChatHistory.js +22 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
- package/dist/utils/clearTempFolder.d.ts +1 -0
- package/dist/utils/clearTempFolder.js +16 -0
- package/dist/utils/clearTempFolder.js.map +1 -0
- package/dist/utils/cmake.d.ts +10 -0
- package/dist/utils/cmake.js +146 -0
- package/dist/utils/cmake.js.map +1 -0
- package/dist/utils/compareTokens.d.ts +2 -0
- package/dist/utils/compareTokens.js +4 -0
- package/dist/utils/compareTokens.js.map +1 -0
- package/dist/utils/createModelDownloader.d.ts +262 -0
- package/dist/utils/createModelDownloader.js +486 -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 +20 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +85 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +19 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +60 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfTerminal.d.ts +11 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js +54 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -0
- 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/GbnfAnyJson.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js +53 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +18 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +83 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js +17 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js +90 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js +23 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js +24 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +88 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +86 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +12 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js +43 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.d.ts +8 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js +26 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +13 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +67 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +30 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +72 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -0
- package/dist/utils/gbnfJson/types.d.ts +213 -0
- package/dist/utils/gbnfJson/types.js +30 -0
- package/dist/utils/gbnfJson/types.js.map +1 -0
- 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/defsScope.d.ts +7 -0
- package/dist/utils/gbnfJson/utils/defsScope.js +17 -0
- package/dist/utils/gbnfJson/utils/defsScope.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +143 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js +16 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js.map +1 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +8 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +242 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -0
- package/dist/utils/getBuildDefaults.d.ts +5 -0
- package/dist/utils/getBuildDefaults.js +9 -0
- package/dist/utils/getBuildDefaults.js.map +1 -0
- package/dist/utils/getChatWrapperSegmentDefinition.d.ts +2 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js +9 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js.map +1 -0
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
- package/dist/utils/getConsoleLogPrefix.js +10 -0
- package/dist/utils/getConsoleLogPrefix.js.map +1 -0
- package/dist/utils/getFirstWritableDir.d.ts +8 -0
- package/dist/utils/getFirstWritableDir.js +60 -0
- package/dist/utils/getFirstWritableDir.js.map +1 -0
- package/dist/utils/getGrammarsFolder.d.ts +2 -0
- package/dist/utils/getGrammarsFolder.js +19 -0
- package/dist/utils/getGrammarsFolder.js.map +1 -0
- package/dist/utils/getLlamaClasses.d.ts +9 -0
- package/dist/utils/getLlamaClasses.js +14 -0
- package/dist/utils/getLlamaClasses.js.map +1 -0
- package/dist/utils/getModuleVersion.d.ts +1 -0
- package/dist/utils/getModuleVersion.js +13 -0
- package/dist/utils/getModuleVersion.js.map +1 -0
- 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/getTempDir.d.ts +10 -0
- package/dist/utils/getTempDir.js +121 -0
- package/dist/utils/getTempDir.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +205 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gitReleaseBundles.d.ts +2 -0
- package/dist/utils/gitReleaseBundles.js +132 -0
- package/dist/utils/gitReleaseBundles.js.map +1 -0
- package/dist/utils/hashString.d.ts +1 -0
- package/dist/utils/hashString.js +8 -0
- package/dist/utils/hashString.js.map +1 -0
- package/dist/utils/includesText.d.ts +1 -0
- package/dist/utils/includesText.js +12 -0
- package/dist/utils/includesText.js.map +1 -0
- package/dist/utils/isLockfileActive.d.ts +4 -0
- package/dist/utils/isLockfileActive.js +12 -0
- package/dist/utils/isLockfileActive.js.map +1 -0
- 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/modelDownloadEndpoints.d.ts +13 -0
- package/dist/utils/modelDownloadEndpoints.js +27 -0
- package/dist/utils/modelDownloadEndpoints.js.map +1 -0
- package/dist/utils/modelFileAccessTokens.d.ts +5 -0
- package/dist/utils/modelFileAccessTokens.js +41 -0
- package/dist/utils/modelFileAccessTokens.js.map +1 -0
- package/dist/utils/optionsMatrix.d.ts +58 -0
- package/dist/utils/optionsMatrix.js +97 -0
- package/dist/utils/optionsMatrix.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +15 -0
- package/dist/utils/parseModelFileName.js +132 -0
- package/dist/utils/parseModelFileName.js.map +1 -0
- package/dist/utils/parseModelUri.d.ts +40 -0
- package/dist/utils/parseModelUri.js +346 -0
- package/dist/utils/parseModelUri.js.map +1 -0
- 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 -0
- package/dist/utils/prettyPrintObject.js +84 -0
- package/dist/utils/prettyPrintObject.js.map +1 -0
- 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 -0
- package/dist/utils/removeNullFields.js +17 -0
- package/dist/utils/removeNullFields.js.map +1 -0
- package/dist/utils/resolveGithubRelease.d.ts +2 -0
- package/dist/utils/resolveGithubRelease.js +77 -0
- package/dist/utils/resolveGithubRelease.js.map +1 -0
- 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/resolveModelDestination.d.ts +16 -0
- package/dist/utils/resolveModelDestination.js +54 -0
- package/dist/utils/resolveModelDestination.js.map +1 -0
- package/dist/utils/resolveModelFile.d.ts +142 -0
- package/dist/utils/resolveModelFile.js +201 -0
- package/dist/utils/resolveModelFile.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/signalSleep.d.ts +1 -0
- package/dist/utils/signalSleep.js +20 -0
- package/dist/utils/signalSleep.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -0
- package/dist/utils/spawnCommand.js +89 -0
- package/dist/utils/spawnCommand.js.map +1 -0
- package/dist/utils/tokenizeInput.d.ts +3 -0
- package/dist/utils/tokenizeInput.js +14 -0
- package/dist/utils/tokenizeInput.js.map +1 -0
- package/dist/utils/tokenizerUtils.d.ts +12 -0
- package/dist/utils/tokenizerUtils.js +32 -0
- package/dist/utils/tokenizerUtils.js.map +1 -0
- package/dist/utils/transformPromisable.d.ts +54 -0
- package/dist/utils/transformPromisable.js +95 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +11 -0
- package/dist/utils/truncateTextAndRoundToWords.js +110 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
- package/dist/utils/utilTypes.d.ts +18 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.d.ts +5 -0
- package/dist/utils/waitForLockfileRelease.js +19 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -0
- package/dist/utils/withLockfile.d.ts +7 -0
- package/dist/utils/withLockfile.js +44 -0
- package/dist/utils/withLockfile.js.map +1 -0
- package/dist/utils/withOra.d.ts +7 -0
- package/dist/utils/withOra.js +37 -0
- package/dist/utils/withOra.js.map +1 -0
- 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.d.ts +6 -0
- package/dist/utils/withStatusLogs.js +25 -0
- package/dist/utils/withStatusLogs.js.map +1 -0
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +14 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/.clang-format +46 -0
- package/llama/CMakeLists.txt +141 -0
- package/llama/addon/AddonContext.cpp +1181 -0
- package/llama/addon/AddonContext.h +85 -0
- package/llama/addon/AddonGrammar.cpp +92 -0
- package/llama/addon/AddonGrammar.h +22 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +36 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +691 -0
- package/llama/addon/AddonModel.h +64 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +103 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +669 -0
- package/llama/addon/AddonSampler.h +75 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +330 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +143 -0
- package/llama/addon/globals/addonLog.h +24 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +146 -0
- package/llama/addon/globals/getGpuInfo.h +11 -0
- package/llama/addon/globals/getMemoryInfo.cpp +63 -0
- package/llama/addon/globals/getMemoryInfo.h +4 -0
- package/llama/addon/globals/getSwapInfo.cpp +69 -0
- package/llama/addon/globals/getSwapInfo.h +4 -0
- package/llama/binariesGithubRelease.json +3 -0
- package/llama/cmake/addVariantSuffix.cmake +21 -0
- package/llama/cmake/win32.ensureNinjaPath.cmake +68 -0
- package/llama/cmake/win32.ensureNodeLib.cmake +34 -0
- package/llama/cmake/win32.llvmApplyGnuModeAdaptations.cmake +12 -0
- package/llama/cmake/win32.llvmEnsureCmakeAr.cmake +37 -0
- package/llama/cmake/win32.llvmUseGnuModeCompilers.cmake +87 -0
- package/llama/cmake/win32.programFilesPaths.cmake +35 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +207 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/package.json +5 -0
- package/llama/profiles/llvm.win32.host-arm64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-x64.cmake +14 -0
- package/llama/toolchains/darwin.host-x64.target-arm64.cmake +8 -0
- package/llama/toolchains/linux.host-arm64.target-x64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm71.cmake +5 -0
- package/llama/toolchains/llvm.win32.host-x64.target-x64.cmake +20 -0
- package/llama/toolchains/win32.host-arm64.target-arm64.cmake +21 -0
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +21 -0
- package/llama/xpack/package.json +10 -0
- package/package.json +241 -0
- package/templates/README.md +6 -0
- package/templates/package.json +10 -0
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "llama.h"
|
|
3
|
+
#include "napi.h"
|
|
4
|
+
#include "RingBuffer.h"
|
|
5
|
+
#include "addonGlobals.h"
|
|
6
|
+
#include "AddonModel.h"
|
|
7
|
+
|
|
8
|
+
class AddonSampler : public Napi::ObjectWrap<AddonSampler> {
|
|
9
|
+
public:
|
|
10
|
+
AddonModel* model;
|
|
11
|
+
llama_sampler * chain = nullptr;
|
|
12
|
+
|
|
13
|
+
llama_sampler * temperatureSampler = nullptr;
|
|
14
|
+
bool temperatureSampler_initialized = false;
|
|
15
|
+
float temperatureSampler_temperature = 0.0f; // 0.0f = disabled
|
|
16
|
+
|
|
17
|
+
llama_sampler * greedySampler = nullptr;
|
|
18
|
+
|
|
19
|
+
llama_sampler * minPSampler = nullptr;
|
|
20
|
+
float minPSampler_minP = 0.0f; // Min p sampling <=0.0f = disabled
|
|
21
|
+
|
|
22
|
+
llama_sampler * topKSampler = nullptr;
|
|
23
|
+
bool topKSampler_initialized = false;
|
|
24
|
+
int topKSampler_topK = 0;
|
|
25
|
+
|
|
26
|
+
llama_sampler * topPSampler = nullptr;
|
|
27
|
+
float topPSampler_topP = 0.0f; // Top p sampling >=1.0 = disabled
|
|
28
|
+
|
|
29
|
+
llama_sampler * xtcSampler = nullptr;
|
|
30
|
+
float xtcSampler_probability = 0;
|
|
31
|
+
float xtcSampler_threshold = 0;
|
|
32
|
+
|
|
33
|
+
llama_sampler * seedSampler = nullptr;
|
|
34
|
+
uint32_t seedSampler_seed = 0;
|
|
35
|
+
|
|
36
|
+
llama_sampler * repeatPenaltySampler = nullptr;
|
|
37
|
+
RingBuffer<llama_token> repeatPenalty_lastTokens = RingBuffer<llama_token>(64);
|
|
38
|
+
int32_t repeatPenalty_maxTokens = 64;
|
|
39
|
+
float repeatPenalty_penalty = 1.10f; // 1.0 = disabled
|
|
40
|
+
float repeatPenalty_presencePenalty = 0.00f; // 0.0 = disabled
|
|
41
|
+
float repeatPenalty_frequencyPenalty = 0.00f; // 0.0 = disabled
|
|
42
|
+
|
|
43
|
+
llama_sampler * dryRepeatPenaltySampler = nullptr;
|
|
44
|
+
float dryRepeatPenalty_strength = 0.00f; // 0.00f = disabled
|
|
45
|
+
float dryRepeatPenalty_base = 0.00f;
|
|
46
|
+
int32_t dryRepeatPenalty_allowedLength = 1;
|
|
47
|
+
int32_t dryRepeatPenalty_lastTokens = 1;
|
|
48
|
+
bool dryRepeatPenalty_lastTokensAll = true;
|
|
49
|
+
std::vector<std::string> dryRepeatPenalty_sequenceBreakers;
|
|
50
|
+
|
|
51
|
+
llama_sampler * tokenBiasSampler = nullptr;
|
|
52
|
+
std::vector<llama_logit_bias> tokenBiasSampler_biases;
|
|
53
|
+
|
|
54
|
+
AddonGrammarEvaluationState* grammarEvaluationState = nullptr;
|
|
55
|
+
|
|
56
|
+
std::vector<llama_token_data> tokenCandidates;
|
|
57
|
+
|
|
58
|
+
bool disposed = false;
|
|
59
|
+
|
|
60
|
+
AddonSampler(const Napi::CallbackInfo& info);
|
|
61
|
+
~AddonSampler();
|
|
62
|
+
|
|
63
|
+
void dispose();
|
|
64
|
+
void freeChain();
|
|
65
|
+
void rebuildChainIfNeeded();
|
|
66
|
+
void acceptToken(llama_token token);
|
|
67
|
+
|
|
68
|
+
Napi::Value Dispose(const Napi::CallbackInfo& info);
|
|
69
|
+
Napi::Value ApplyConfig(const Napi::CallbackInfo& info);
|
|
70
|
+
|
|
71
|
+
static Napi::Value AcceptGrammarEvaluationStateToken(const Napi::CallbackInfo& info);
|
|
72
|
+
static Napi::Value CanBeNextTokenForGrammarEvaluationState(const Napi::CallbackInfo& info);
|
|
73
|
+
|
|
74
|
+
static void init(Napi::Object exports);
|
|
75
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// copied from llama-impl.h
|
|
2
|
+
template<typename T>
|
|
3
|
+
struct RingBuffer {
|
|
4
|
+
RingBuffer(size_t cap) : capacity(cap), data(cap) {}
|
|
5
|
+
|
|
6
|
+
T & front() {
|
|
7
|
+
if (sz == 0) {
|
|
8
|
+
throw std::runtime_error("ring buffer is empty");
|
|
9
|
+
}
|
|
10
|
+
return data[first];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const T & front() const {
|
|
14
|
+
if (sz == 0) {
|
|
15
|
+
throw std::runtime_error("ring buffer is empty");
|
|
16
|
+
}
|
|
17
|
+
return data[first];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
T & back() {
|
|
21
|
+
if (sz == 0) {
|
|
22
|
+
throw std::runtime_error("ring buffer is empty");
|
|
23
|
+
}
|
|
24
|
+
return data[pos];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const T & back() const {
|
|
28
|
+
if (sz == 0) {
|
|
29
|
+
throw std::runtime_error("ring buffer is empty");
|
|
30
|
+
}
|
|
31
|
+
return data[pos];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
void push_back(const T & value) {
|
|
35
|
+
if (capacity == 0) {
|
|
36
|
+
throw std::runtime_error("ring buffer: capacity is zero");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (sz == capacity) {
|
|
40
|
+
// advance the start when buffer is full
|
|
41
|
+
first = (first + 1) % capacity;
|
|
42
|
+
} else {
|
|
43
|
+
sz++;
|
|
44
|
+
}
|
|
45
|
+
data[pos] = value;
|
|
46
|
+
pos = (pos + 1) % capacity;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
T pop_front() {
|
|
50
|
+
if (sz == 0) {
|
|
51
|
+
throw std::runtime_error("ring buffer is empty");
|
|
52
|
+
}
|
|
53
|
+
T value = data[first];
|
|
54
|
+
first = (first + 1) % capacity;
|
|
55
|
+
sz--;
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//T & operator[](size_t i) {
|
|
60
|
+
// if (i >= sz) {
|
|
61
|
+
// throw std::runtime_error("ring buffer: index out of bounds");
|
|
62
|
+
// }
|
|
63
|
+
// return data[(first + i) % capacity];
|
|
64
|
+
//}
|
|
65
|
+
|
|
66
|
+
//const T & at(size_t i) const {
|
|
67
|
+
// if (i >= sz) {
|
|
68
|
+
// throw std::runtime_error("ring buffer: index out of bounds");
|
|
69
|
+
// }
|
|
70
|
+
// return data[(first + i) % capacity];
|
|
71
|
+
//}
|
|
72
|
+
|
|
73
|
+
const T & rat(size_t i) const {
|
|
74
|
+
if (i >= sz) {
|
|
75
|
+
throw std::runtime_error("ring buffer: index out of bounds");
|
|
76
|
+
}
|
|
77
|
+
return data[(first + sz - i - 1) % capacity];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
std::vector<T> to_vector() const {
|
|
81
|
+
std::vector<T> result;
|
|
82
|
+
result.reserve(sz);
|
|
83
|
+
for (size_t i = 0; i < sz; i++) {
|
|
84
|
+
result.push_back(data[(first + i) % capacity]);
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
void clear() {
|
|
90
|
+
// here only reset the status of the buffer
|
|
91
|
+
sz = 0;
|
|
92
|
+
first = 0;
|
|
93
|
+
pos = 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
bool empty() const {
|
|
97
|
+
return sz == 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
size_t size() const {
|
|
101
|
+
return sz;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
size_t capacity = 0;
|
|
105
|
+
size_t sz = 0;
|
|
106
|
+
size_t first = 0;
|
|
107
|
+
size_t pos = 0;
|
|
108
|
+
std::vector<T> data;
|
|
109
|
+
};
|
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
#include "addonGlobals.h"
|
|
2
|
+
#include "AddonModel.h"
|
|
3
|
+
#include "AddonModelLora.h"
|
|
4
|
+
#include "AddonGrammar.h"
|
|
5
|
+
#include "AddonGrammarEvaluationState.h"
|
|
6
|
+
#include "AddonSampler.h"
|
|
7
|
+
#include "AddonContext.h"
|
|
8
|
+
#include "globals/addonLog.h"
|
|
9
|
+
#include "globals/addonProgress.h"
|
|
10
|
+
#include "globals/getGpuInfo.h"
|
|
11
|
+
#include "globals/getSwapInfo.h"
|
|
12
|
+
#include "globals/getMemoryInfo.h"
|
|
13
|
+
|
|
14
|
+
#include <atomic>
|
|
15
|
+
#include <cstdlib>
|
|
16
|
+
#include <mutex>
|
|
17
|
+
|
|
18
|
+
std::mutex backendMutex;
|
|
19
|
+
bool backendInitialized = false;
|
|
20
|
+
bool backendDisposed = false;
|
|
21
|
+
|
|
22
|
+
Napi::Value systemInfo(const Napi::CallbackInfo& info) {
|
|
23
|
+
return Napi::String::From(info.Env(), llama_print_system_info());
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
Napi::Value addonGetSupportsGpuOffloading(const Napi::CallbackInfo& info) {
|
|
27
|
+
return Napi::Boolean::New(info.Env(), llama_supports_gpu_offload());
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
Napi::Value addonGetSupportsMmap(const Napi::CallbackInfo& info) {
|
|
31
|
+
return Napi::Boolean::New(info.Env(), llama_supports_mmap());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Napi::Value addonGetGpuSupportsMmap(const Napi::CallbackInfo& info) {
|
|
35
|
+
const auto llamaSupportsMmap = llama_supports_mmap();
|
|
36
|
+
const auto gpuDevice = getGpuDevice().first;
|
|
37
|
+
|
|
38
|
+
if (gpuDevice == nullptr) {
|
|
39
|
+
return Napi::Boolean::New(info.Env(), false);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ggml_backend_dev_props props;
|
|
43
|
+
ggml_backend_dev_get_props(gpuDevice, &props);
|
|
44
|
+
|
|
45
|
+
const bool gpuSupportsMmap = llama_supports_mmap() && props.caps.buffer_from_host_ptr;
|
|
46
|
+
return Napi::Boolean::New(info.Env(), gpuSupportsMmap);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Napi::Value addonGetSupportsMlock(const Napi::CallbackInfo& info) {
|
|
50
|
+
return Napi::Boolean::New(info.Env(), llama_supports_mlock());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
Napi::Value addonGetMathCores(const Napi::CallbackInfo& info) {
|
|
54
|
+
return Napi::Number::New(info.Env(), cpu_get_num_math());
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Napi::Value addonGetBlockSizeForGgmlType(const Napi::CallbackInfo& info) {
|
|
58
|
+
const int ggmlType = info[0].As<Napi::Number>().Int32Value();
|
|
59
|
+
|
|
60
|
+
if (ggmlType < 0 || ggmlType > GGML_TYPE_COUNT) {
|
|
61
|
+
return info.Env().Undefined();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const auto blockSize = ggml_blck_size(static_cast<ggml_type>(ggmlType));
|
|
65
|
+
|
|
66
|
+
return Napi::Number::New(info.Env(), blockSize);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
Napi::Value addonGetTypeSizeForGgmlType(const Napi::CallbackInfo& info) {
|
|
70
|
+
const int ggmlType = info[0].As<Napi::Number>().Int32Value();
|
|
71
|
+
|
|
72
|
+
if (ggmlType < 0 || ggmlType > GGML_TYPE_COUNT) {
|
|
73
|
+
return info.Env().Undefined();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const auto typeSize = ggml_type_size(static_cast<ggml_type>(ggmlType));
|
|
77
|
+
|
|
78
|
+
return Napi::Number::New(info.Env(), typeSize);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
Napi::Value addonGetGgmlGraphOverheadCustom(const Napi::CallbackInfo& info) {
|
|
82
|
+
if (info.Length() < 2 || !info[0].IsNumber() || !info[1].IsBoolean()) {
|
|
83
|
+
return Napi::Number::New(info.Env(), 0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const size_t size = info[0].As<Napi::Number>().Uint32Value();
|
|
87
|
+
const bool grads = info[1].As<Napi::Boolean>().Value();
|
|
88
|
+
|
|
89
|
+
const auto graphOverhead = ggml_graph_overhead_custom(size, grads);
|
|
90
|
+
|
|
91
|
+
return Napi::Number::New(info.Env(), graphOverhead);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
Napi::Value addonGetConsts(const Napi::CallbackInfo& info) {
|
|
95
|
+
Napi::Object consts = Napi::Object::New(info.Env());
|
|
96
|
+
consts.Set("ggmlMaxDims", Napi::Number::New(info.Env(), GGML_MAX_DIMS));
|
|
97
|
+
consts.Set("ggmlTypeF16Size", Napi::Number::New(info.Env(), ggml_type_size(GGML_TYPE_F16)));
|
|
98
|
+
consts.Set("ggmlTypeF32Size", Napi::Number::New(info.Env(), ggml_type_size(GGML_TYPE_F32)));
|
|
99
|
+
consts.Set("ggmlTensorOverhead", Napi::Number::New(info.Env(), ggml_tensor_overhead()));
|
|
100
|
+
consts.Set("llamaPosSize", Napi::Number::New(info.Env(), sizeof(llama_pos)));
|
|
101
|
+
consts.Set("llamaSeqIdSize", Napi::Number::New(info.Env(), sizeof(llama_seq_id)));
|
|
102
|
+
|
|
103
|
+
return consts;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
class AddonBackendLoadWorker : public Napi::AsyncWorker {
|
|
107
|
+
public:
|
|
108
|
+
AddonBackendLoadWorker(const Napi::Env& env)
|
|
109
|
+
: Napi::AsyncWorker(env, "AddonBackendLoadWorker"),
|
|
110
|
+
deferred(Napi::Promise::Deferred::New(env)) {
|
|
111
|
+
}
|
|
112
|
+
~AddonBackendLoadWorker() {
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
Napi::Promise GetPromise() {
|
|
116
|
+
return deferred.Promise();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
protected:
|
|
120
|
+
Napi::Promise::Deferred deferred;
|
|
121
|
+
|
|
122
|
+
void Execute() {
|
|
123
|
+
try {
|
|
124
|
+
std::lock_guard<std::mutex> lock(backendMutex);
|
|
125
|
+
|
|
126
|
+
llama_backend_init();
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
if (backendDisposed) {
|
|
130
|
+
llama_backend_free();
|
|
131
|
+
} else {
|
|
132
|
+
backendInitialized = true;
|
|
133
|
+
}
|
|
134
|
+
} catch (const std::exception& e) {
|
|
135
|
+
SetError(e.what());
|
|
136
|
+
} catch(...) {
|
|
137
|
+
SetError("Unknown error when calling \"llama_backend_free\"");
|
|
138
|
+
}
|
|
139
|
+
} catch (const std::exception& e) {
|
|
140
|
+
SetError(e.what());
|
|
141
|
+
} catch(...) {
|
|
142
|
+
SetError("Unknown error when calling \"llama_backend_init\"");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
void OnOK() {
|
|
146
|
+
deferred.Resolve(Env().Undefined());
|
|
147
|
+
}
|
|
148
|
+
void OnError(const Napi::Error& err) {
|
|
149
|
+
deferred.Reject(err.Value());
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
class AddonBackendUnloadWorker : public Napi::AsyncWorker {
|
|
155
|
+
public:
|
|
156
|
+
AddonBackendUnloadWorker(const Napi::Env& env)
|
|
157
|
+
: Napi::AsyncWorker(env, "AddonBackendUnloadWorker"),
|
|
158
|
+
deferred(Napi::Promise::Deferred::New(env)) {
|
|
159
|
+
}
|
|
160
|
+
~AddonBackendUnloadWorker() {
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
Napi::Promise GetPromise() {
|
|
164
|
+
return deferred.Promise();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
protected:
|
|
168
|
+
Napi::Promise::Deferred deferred;
|
|
169
|
+
|
|
170
|
+
void Execute() {
|
|
171
|
+
std::lock_guard<std::mutex> lock(backendMutex);
|
|
172
|
+
|
|
173
|
+
try {
|
|
174
|
+
if (backendInitialized) {
|
|
175
|
+
backendInitialized = false;
|
|
176
|
+
llama_backend_free();
|
|
177
|
+
}
|
|
178
|
+
} catch (const std::exception& e) {
|
|
179
|
+
SetError(e.what());
|
|
180
|
+
} catch(...) {
|
|
181
|
+
SetError("Unknown error when calling \"llama_backend_free\"");
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
void OnOK() {
|
|
185
|
+
deferred.Resolve(Env().Undefined());
|
|
186
|
+
}
|
|
187
|
+
void OnError(const Napi::Error& err) {
|
|
188
|
+
deferred.Reject(err.Value());
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
Napi::Value addonLoadBackends(const Napi::CallbackInfo& info) {
|
|
193
|
+
const std::string forceLoadLibrariesSearchPath = info.Length() == 0
|
|
194
|
+
? ""
|
|
195
|
+
: info[0].IsString()
|
|
196
|
+
? info[0].As<Napi::String>().Utf8Value()
|
|
197
|
+
: "";
|
|
198
|
+
|
|
199
|
+
ggml_backend_reg_count();
|
|
200
|
+
|
|
201
|
+
if (forceLoadLibrariesSearchPath.length() > 0) {
|
|
202
|
+
ggml_backend_load_all_from_path(forceLoadLibrariesSearchPath.c_str());
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
return info.Env().Undefined();
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
Napi::Value addonSetNuma(const Napi::CallbackInfo& info) {
|
|
209
|
+
const bool numaDisabled = info.Length() == 0
|
|
210
|
+
? true
|
|
211
|
+
: info[0].IsBoolean()
|
|
212
|
+
? !info[0].As<Napi::Boolean>().Value()
|
|
213
|
+
: false;
|
|
214
|
+
|
|
215
|
+
if (numaDisabled)
|
|
216
|
+
return info.Env().Undefined();
|
|
217
|
+
|
|
218
|
+
const auto numaType = info[0].IsString()
|
|
219
|
+
? info[0].As<Napi::String>().Utf8Value()
|
|
220
|
+
: "";
|
|
221
|
+
|
|
222
|
+
if (numaType == "distribute") {
|
|
223
|
+
llama_numa_init(GGML_NUMA_STRATEGY_DISTRIBUTE);
|
|
224
|
+
} else if (numaType == "isolate") {
|
|
225
|
+
llama_numa_init(GGML_NUMA_STRATEGY_ISOLATE);
|
|
226
|
+
} else if (numaType == "numactl") {
|
|
227
|
+
llama_numa_init(GGML_NUMA_STRATEGY_NUMACTL);
|
|
228
|
+
} else if (numaType == "mirror") {
|
|
229
|
+
llama_numa_init(GGML_NUMA_STRATEGY_MIRROR);
|
|
230
|
+
} else {
|
|
231
|
+
Napi::Error::New(info.Env(), std::string("Invalid NUMA strategy \"") + numaType + "\"").ThrowAsJavaScriptException();
|
|
232
|
+
return info.Env().Undefined();
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return info.Env().Undefined();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
Napi::Value markLoaded(const Napi::CallbackInfo& info) {
|
|
239
|
+
static std::atomic_bool loaded = false;
|
|
240
|
+
return Napi::Boolean::New(info.Env(), loaded.exchange(true));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
Napi::Value addonInit(const Napi::CallbackInfo& info) {
|
|
244
|
+
std::lock_guard<std::mutex> lock(backendMutex);
|
|
245
|
+
|
|
246
|
+
if (backendInitialized) {
|
|
247
|
+
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(info.Env());
|
|
248
|
+
deferred.Resolve(info.Env().Undefined());
|
|
249
|
+
return deferred.Promise();
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
AddonBackendLoadWorker* worker = new AddonBackendLoadWorker(info.Env());
|
|
253
|
+
worker->Queue();
|
|
254
|
+
return worker->GetPromise();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
Napi::Value addonDispose(const Napi::CallbackInfo& info) {
|
|
258
|
+
std::lock_guard<std::mutex> lock(backendMutex);
|
|
259
|
+
|
|
260
|
+
if (backendDisposed) {
|
|
261
|
+
Napi::Promise::Deferred deferred = Napi::Promise::Deferred::New(info.Env());
|
|
262
|
+
deferred.Resolve(info.Env().Undefined());
|
|
263
|
+
return deferred.Promise();
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
backendDisposed = true;
|
|
267
|
+
|
|
268
|
+
AddonBackendUnloadWorker* worker = new AddonBackendUnloadWorker(info.Env());
|
|
269
|
+
worker->Queue();
|
|
270
|
+
return worker->GetPromise();
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
static void addonFreeLlamaBackend() {
|
|
274
|
+
std::lock_guard<std::mutex> lock(backendMutex);
|
|
275
|
+
if (backendDisposed) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
backendDisposed = true;
|
|
280
|
+
if (backendInitialized) {
|
|
281
|
+
backendInitialized = false;
|
|
282
|
+
llama_backend_free();
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
static void addonFreeLlamaBackendFromFinalizer(Napi::Env env, int* data) {
|
|
286
|
+
addonFreeLlamaBackend();
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
Napi::Object registerCallback(Napi::Env env, Napi::Object exports) {
|
|
290
|
+
exports.DefineProperties({
|
|
291
|
+
Napi::PropertyDescriptor::Function("markLoaded", markLoaded),
|
|
292
|
+
Napi::PropertyDescriptor::Function("systemInfo", systemInfo),
|
|
293
|
+
Napi::PropertyDescriptor::Function("getSupportsGpuOffloading", addonGetSupportsGpuOffloading),
|
|
294
|
+
Napi::PropertyDescriptor::Function("getSupportsMmap", addonGetSupportsMmap),
|
|
295
|
+
Napi::PropertyDescriptor::Function("getGpuSupportsMmap", addonGetGpuSupportsMmap),
|
|
296
|
+
Napi::PropertyDescriptor::Function("getSupportsMlock", addonGetSupportsMlock),
|
|
297
|
+
Napi::PropertyDescriptor::Function("getMathCores", addonGetMathCores),
|
|
298
|
+
Napi::PropertyDescriptor::Function("getBlockSizeForGgmlType", addonGetBlockSizeForGgmlType),
|
|
299
|
+
Napi::PropertyDescriptor::Function("getTypeSizeForGgmlType", addonGetTypeSizeForGgmlType),
|
|
300
|
+
Napi::PropertyDescriptor::Function("getGgmlGraphOverheadCustom", addonGetGgmlGraphOverheadCustom),
|
|
301
|
+
Napi::PropertyDescriptor::Function("getConsts", addonGetConsts),
|
|
302
|
+
Napi::PropertyDescriptor::Function("setLogger", setLogger),
|
|
303
|
+
Napi::PropertyDescriptor::Function("setLoggerLogLevel", setLoggerLogLevel),
|
|
304
|
+
Napi::PropertyDescriptor::Function("getGpuVramInfo", getGpuVramInfo),
|
|
305
|
+
Napi::PropertyDescriptor::Function("getGpuDeviceInfo", getGpuDeviceInfo),
|
|
306
|
+
Napi::PropertyDescriptor::Function("getGpuType", getGpuType),
|
|
307
|
+
Napi::PropertyDescriptor::Function("ensureGpuDeviceIsSupported", ensureGpuDeviceIsSupported),
|
|
308
|
+
Napi::PropertyDescriptor::Function("getSwapInfo", getSwapInfo),
|
|
309
|
+
Napi::PropertyDescriptor::Function("getMemoryInfo", getMemoryInfo),
|
|
310
|
+
Napi::PropertyDescriptor::Function("loadBackends", addonLoadBackends),
|
|
311
|
+
Napi::PropertyDescriptor::Function("setNuma", addonSetNuma),
|
|
312
|
+
Napi::PropertyDescriptor::Function("init", addonInit),
|
|
313
|
+
Napi::PropertyDescriptor::Function("dispose", addonDispose),
|
|
314
|
+
});
|
|
315
|
+
AddonModel::init(exports);
|
|
316
|
+
AddonModelLora::init(exports);
|
|
317
|
+
AddonGrammar::init(exports);
|
|
318
|
+
AddonGrammarEvaluationState::init(exports);
|
|
319
|
+
AddonContext::init(exports);
|
|
320
|
+
AddonContextSequenceCheckpoint::init(exports);
|
|
321
|
+
AddonSampler::init(exports);
|
|
322
|
+
|
|
323
|
+
llama_log_set(addonLlamaCppLogCallback, nullptr);
|
|
324
|
+
|
|
325
|
+
exports.AddFinalizer(addonFreeLlamaBackendFromFinalizer, static_cast<int*>(nullptr));
|
|
326
|
+
env.AddCleanupHook(addonFreeLlamaBackend);
|
|
327
|
+
return exports;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
NODE_API_MODULE(NODE_GYP_MODULE_NAME, registerCallback)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#include <sstream>
|
|
2
|
+
#include <vector>
|
|
3
|
+
#include "addonGlobals.h"
|
|
4
|
+
#include "napi.h"
|
|
5
|
+
|
|
6
|
+
void adjustNapiExternalMemoryAdd(Napi::Env env, uint64_t size) {
|
|
7
|
+
const uint64_t chunkSize = std::numeric_limits<int64_t>::max();
|
|
8
|
+
while (size > 0) {
|
|
9
|
+
int64_t adjustSize = std::min(size, chunkSize);
|
|
10
|
+
Napi::MemoryManagement::AdjustExternalMemory(env, adjustSize);
|
|
11
|
+
size -= adjustSize;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
void adjustNapiExternalMemorySubtract(Napi::Env env, uint64_t size) {
|
|
16
|
+
const uint64_t chunkSize = std::numeric_limits<int64_t>::max();
|
|
17
|
+
while (size > 0) {
|
|
18
|
+
int64_t adjustSize = std::min(size, chunkSize);
|
|
19
|
+
Napi::MemoryManagement::AdjustExternalMemory(env, -adjustSize);
|
|
20
|
+
size -= adjustSize;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#include "napi.h"
|
|
3
|
+
|
|
4
|
+
class AddonModel;
|
|
5
|
+
class AddonModelLora;
|
|
6
|
+
class AddonModelData;
|
|
7
|
+
class AddonContext;
|
|
8
|
+
class AddonGrammar;
|
|
9
|
+
class AddonGrammarEvaluationState;
|
|
10
|
+
|
|
11
|
+
void adjustNapiExternalMemoryAdd(Napi::Env env, uint64_t size);
|
|
12
|
+
void adjustNapiExternalMemorySubtract(Napi::Env env, uint64_t size);
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
#include <sstream>
|
|
2
|
+
|
|
3
|
+
#include "addonLog.h"
|
|
4
|
+
|
|
5
|
+
AddonThreadSafeLogCallbackFunction addonThreadSafeLoggerCallback;
|
|
6
|
+
bool addonJsLoggerCallbackSet = false;
|
|
7
|
+
int addonLoggerLogLevel = 5;
|
|
8
|
+
int addonLastLoggerLogLevel = 6;
|
|
9
|
+
|
|
10
|
+
static int addonGetGgmlLogLevelNumber(ggml_log_level level) {
|
|
11
|
+
switch (level) {
|
|
12
|
+
case GGML_LOG_LEVEL_ERROR: return 2;
|
|
13
|
+
case GGML_LOG_LEVEL_WARN: return 3;
|
|
14
|
+
case GGML_LOG_LEVEL_INFO: return 4;
|
|
15
|
+
case GGML_LOG_LEVEL_NONE: return 5;
|
|
16
|
+
case GGML_LOG_LEVEL_DEBUG: return 6;
|
|
17
|
+
case GGML_LOG_LEVEL_CONT: return addonLastLoggerLogLevel;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
void addonCallJsLogCallback(
|
|
24
|
+
Napi::Env env, Napi::Function callback, AddonThreadSafeLogCallbackFunctionContext* context, addon_logger_log* data
|
|
25
|
+
) {
|
|
26
|
+
bool called = false;
|
|
27
|
+
|
|
28
|
+
if (env != nullptr && callback != nullptr && addonJsLoggerCallbackSet) {
|
|
29
|
+
try {
|
|
30
|
+
callback.Call({
|
|
31
|
+
Napi::Number::New(env, data->logLevelNumber),
|
|
32
|
+
Napi::String::New(env, data->stringStream->str()),
|
|
33
|
+
});
|
|
34
|
+
called = true;
|
|
35
|
+
} catch (const Napi::Error& e) {
|
|
36
|
+
called = false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (!called && data != nullptr) {
|
|
41
|
+
if (data->logLevelNumber == 2) {
|
|
42
|
+
fputs(data->stringStream->str().c_str(), stderr);
|
|
43
|
+
fflush(stderr);
|
|
44
|
+
} else {
|
|
45
|
+
fputs(data->stringStream->str().c_str(), stdout);
|
|
46
|
+
fflush(stdout);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (data != nullptr) {
|
|
51
|
+
delete data->stringStream;
|
|
52
|
+
delete data;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
void addonLlamaCppLogCallback(ggml_log_level level, const char* text, void* user_data) {
|
|
57
|
+
int logLevelNumber = addonGetGgmlLogLevelNumber(level);
|
|
58
|
+
addonLastLoggerLogLevel = logLevelNumber;
|
|
59
|
+
|
|
60
|
+
if (logLevelNumber > addonLoggerLogLevel) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (addonJsLoggerCallbackSet) {
|
|
65
|
+
std::stringstream* stringStream = new std::stringstream();
|
|
66
|
+
if (text != nullptr) {
|
|
67
|
+
*stringStream << text;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
addon_logger_log* data = new addon_logger_log {
|
|
71
|
+
logLevelNumber,
|
|
72
|
+
stringStream,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
auto status = addonThreadSafeLoggerCallback.NonBlockingCall(data);
|
|
76
|
+
|
|
77
|
+
if (status == napi_ok) {
|
|
78
|
+
return;
|
|
79
|
+
} else {
|
|
80
|
+
delete stringStream;
|
|
81
|
+
delete data;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (text != nullptr) {
|
|
86
|
+
if (level == 2) {
|
|
87
|
+
fputs(text, stderr);
|
|
88
|
+
fflush(stderr);
|
|
89
|
+
} else {
|
|
90
|
+
fputs(text, stdout);
|
|
91
|
+
fflush(stdout);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Napi::Value setLogger(const Napi::CallbackInfo& info) {
|
|
97
|
+
if (addonJsLoggerCallbackSet) {
|
|
98
|
+
addonJsLoggerCallbackSet = false;
|
|
99
|
+
addonThreadSafeLoggerCallback.Release();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (info.Length() < 1 || !info[0].IsFunction()) {
|
|
103
|
+
return info.Env().Undefined();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
auto addonLoggerJSCallback = info[0].As<Napi::Function>();
|
|
107
|
+
AddonThreadSafeLogCallbackFunctionContext* context = new Napi::Reference<Napi::Value>(Napi::Persistent(info.This()));
|
|
108
|
+
addonThreadSafeLoggerCallback = AddonThreadSafeLogCallbackFunction::New(
|
|
109
|
+
info.Env(),
|
|
110
|
+
addonLoggerJSCallback,
|
|
111
|
+
"loggerCallback",
|
|
112
|
+
0,
|
|
113
|
+
1,
|
|
114
|
+
context,
|
|
115
|
+
[](Napi::Env, void*, AddonThreadSafeLogCallbackFunctionContext* ctx) {
|
|
116
|
+
addonJsLoggerCallbackSet = false;
|
|
117
|
+
|
|
118
|
+
delete ctx;
|
|
119
|
+
}
|
|
120
|
+
);
|
|
121
|
+
addonJsLoggerCallbackSet = true;
|
|
122
|
+
|
|
123
|
+
// prevent blocking the main node process from exiting due to active resources
|
|
124
|
+
addonThreadSafeLoggerCallback.Unref(info.Env());
|
|
125
|
+
|
|
126
|
+
return info.Env().Undefined();
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
Napi::Value setLoggerLogLevel(const Napi::CallbackInfo& info) {
|
|
130
|
+
if (info.Length() < 1 || !info[0].IsNumber()) {
|
|
131
|
+
addonLoggerLogLevel = 5;
|
|
132
|
+
|
|
133
|
+
return info.Env().Undefined();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
addonLoggerLogLevel = info[0].As<Napi::Number>().Int32Value();
|
|
137
|
+
|
|
138
|
+
return info.Env().Undefined();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void addonLog(ggml_log_level level, const std::string text) {
|
|
142
|
+
addonLlamaCppLogCallback(level, std::string("[addon] " + text + "\n").c_str(), nullptr);
|
|
143
|
+
}
|