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
package/dist/utils/LlamaText.js
CHANGED
|
@@ -1,19 +1,332 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { pushAll } from "./pushAll.js";
|
|
2
|
+
class LlamaText {
|
|
3
|
+
values;
|
|
4
|
+
/**
|
|
5
|
+
* Can also be called without `new`
|
|
6
|
+
*/
|
|
7
|
+
constructor(...values) {
|
|
8
|
+
// the constructor logic is copied to `LlamaTextConstructor` to make the constructor callable as a normal function
|
|
9
|
+
this.values = createHistoryFromStringsAndValues(values);
|
|
10
|
+
}
|
|
11
|
+
concat(value) {
|
|
12
|
+
return new LlamaTextConstructor([...this.values, value]);
|
|
13
|
+
}
|
|
14
|
+
mapValues(mapper) {
|
|
15
|
+
return new LlamaTextConstructor(this.values.map(mapper));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Joins the values with the given separator.
|
|
19
|
+
*
|
|
20
|
+
* Note that the values are squashed when they are loaded into the `LlamaText`, so the separator is not added between adjacent strings.
|
|
21
|
+
*
|
|
22
|
+
* To add the separator on values before squashing them, use `LlamaText.joinValues` instead.
|
|
23
|
+
*/
|
|
24
|
+
joinValues(separator) {
|
|
25
|
+
const newValues = [];
|
|
26
|
+
for (let i = 0; i < this.values.length; i++) {
|
|
27
|
+
newValues.push(this.values[i]);
|
|
28
|
+
if (i !== this.values.length - 1) {
|
|
29
|
+
if (isLlamaText(separator))
|
|
30
|
+
pushAll(newValues, separator.values);
|
|
31
|
+
else
|
|
32
|
+
newValues.push(separator);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return new LlamaTextConstructor(newValues);
|
|
36
|
+
}
|
|
37
|
+
toString() {
|
|
38
|
+
return this.values
|
|
39
|
+
.map((value) => {
|
|
40
|
+
if (value instanceof SpecialToken)
|
|
41
|
+
return value.toString();
|
|
42
|
+
else if (value instanceof SpecialTokensText)
|
|
43
|
+
return value.toString();
|
|
44
|
+
else
|
|
45
|
+
return value;
|
|
46
|
+
})
|
|
47
|
+
.join("");
|
|
48
|
+
}
|
|
49
|
+
toJSON() {
|
|
50
|
+
if (this.values.length === 1 && typeof this.values[0] === "string")
|
|
51
|
+
return this.values[0];
|
|
52
|
+
else if (this.values.length === 0)
|
|
53
|
+
return "";
|
|
54
|
+
return this.values.map((value) => {
|
|
55
|
+
if (value instanceof SpecialToken)
|
|
56
|
+
return value.toJSON();
|
|
57
|
+
else if (value instanceof SpecialTokensText)
|
|
58
|
+
return value.toJSON();
|
|
59
|
+
else
|
|
60
|
+
return value;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
tokenize(tokenizer, options) {
|
|
64
|
+
let textToTokenize = "";
|
|
65
|
+
const res = [];
|
|
66
|
+
const hasContent = () => (res.length > 0 || textToTokenize.length > 0);
|
|
67
|
+
const resolveTokenizerOptions = () => (hasContent() ? "trimLeadingSpace" : options);
|
|
68
|
+
for (const value of this.values) {
|
|
69
|
+
if (value instanceof SpecialToken) {
|
|
70
|
+
pushAll(res, tokenizer(textToTokenize, false, resolveTokenizerOptions()));
|
|
71
|
+
pushAll(res, value.tokenize(tokenizer));
|
|
72
|
+
textToTokenize = "";
|
|
73
|
+
}
|
|
74
|
+
else if (value instanceof SpecialTokensText) {
|
|
75
|
+
pushAll(res, tokenizer(textToTokenize, false, resolveTokenizerOptions()));
|
|
76
|
+
pushAll(res, value.tokenize(tokenizer, hasContent() || options === "trimLeadingSpace"));
|
|
77
|
+
textToTokenize = "";
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
textToTokenize += value;
|
|
81
|
+
}
|
|
82
|
+
pushAll(res, tokenizer(textToTokenize, false, resolveTokenizerOptions()));
|
|
83
|
+
return res;
|
|
84
|
+
}
|
|
85
|
+
compare(other) {
|
|
86
|
+
return LlamaTextConstructor.compare(this, other);
|
|
87
|
+
}
|
|
88
|
+
trimStart() {
|
|
89
|
+
const newValues = this.values.slice();
|
|
90
|
+
while (newValues.length > 0) {
|
|
91
|
+
const firstValue = newValues[0];
|
|
92
|
+
if (firstValue instanceof SpecialToken)
|
|
93
|
+
break;
|
|
94
|
+
if (firstValue instanceof SpecialTokensText) {
|
|
95
|
+
const newValue = firstValue.value.trimStart();
|
|
96
|
+
if (newValue === "") {
|
|
97
|
+
newValues.shift();
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
else if (newValue !== firstValue.value) {
|
|
101
|
+
newValues[0] = new SpecialTokensText(newValue);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
else if (typeof firstValue === "string") {
|
|
107
|
+
const newValue = firstValue.trimStart();
|
|
108
|
+
if (newValue === "") {
|
|
109
|
+
newValues.shift();
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
else if (newValue !== firstValue) {
|
|
113
|
+
newValues[0] = newValue;
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
else
|
|
119
|
+
void firstValue;
|
|
120
|
+
}
|
|
121
|
+
return new LlamaTextConstructor(newValues);
|
|
122
|
+
}
|
|
123
|
+
trimEnd() {
|
|
124
|
+
const newValues = this.values.slice();
|
|
125
|
+
while (newValues.length > 0) {
|
|
126
|
+
const lastValue = newValues[newValues.length - 1];
|
|
127
|
+
if (lastValue instanceof SpecialToken)
|
|
128
|
+
break;
|
|
129
|
+
if (lastValue instanceof SpecialTokensText) {
|
|
130
|
+
const newValue = lastValue.value.trimEnd();
|
|
131
|
+
if (newValue === "") {
|
|
132
|
+
newValues.pop();
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
else if (newValue !== lastValue.value) {
|
|
136
|
+
newValues[newValues.length - 1] = new SpecialTokensText(newValue);
|
|
137
|
+
break;
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
}
|
|
141
|
+
else if (typeof lastValue === "string") {
|
|
142
|
+
const newValue = lastValue.trimEnd();
|
|
143
|
+
if (newValue === "") {
|
|
144
|
+
newValues.pop();
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
else if (newValue !== lastValue) {
|
|
148
|
+
newValues[newValues.length - 1] = newValue;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
151
|
+
break;
|
|
152
|
+
}
|
|
153
|
+
else
|
|
154
|
+
void lastValue;
|
|
13
155
|
}
|
|
14
|
-
|
|
156
|
+
return new LlamaTextConstructor(newValues);
|
|
157
|
+
}
|
|
158
|
+
includes(value) {
|
|
159
|
+
for (let i = 0; i <= this.values.length - value.values.length; i++) {
|
|
160
|
+
const thisValue = this.values[i];
|
|
161
|
+
let startMatch = compareLlamaTextValues(thisValue, value.values[0]);
|
|
162
|
+
if (!startMatch && thisValue instanceof SpecialTokensText && value.values[0] instanceof SpecialTokensText) {
|
|
163
|
+
startMatch = value.values.length > 1
|
|
164
|
+
? thisValue.value.endsWith(value.values[0].value)
|
|
165
|
+
: thisValue.value.includes(value.values[0].value);
|
|
166
|
+
}
|
|
167
|
+
if (!startMatch && typeof thisValue === "string" && typeof value.values[0] === "string") {
|
|
168
|
+
startMatch = value.values.length > 1
|
|
169
|
+
? thisValue.endsWith(value.values[0])
|
|
170
|
+
: thisValue.includes(value.values[0]);
|
|
171
|
+
}
|
|
172
|
+
if (startMatch) {
|
|
173
|
+
let j = 1;
|
|
174
|
+
for (; j < value.values.length; j++) {
|
|
175
|
+
const thisValue = this.values[i + j];
|
|
176
|
+
const valueValue = value.values[j];
|
|
177
|
+
let endMatch = compareLlamaTextValues(thisValue, valueValue);
|
|
178
|
+
if (!endMatch && thisValue instanceof SpecialTokensText && valueValue instanceof SpecialTokensText) {
|
|
179
|
+
endMatch = value.values.length - 1 === j
|
|
180
|
+
? thisValue.value.startsWith(valueValue.value)
|
|
181
|
+
: thisValue.value === valueValue.value;
|
|
182
|
+
}
|
|
183
|
+
if (!endMatch && typeof thisValue === "string" && typeof valueValue === "string") {
|
|
184
|
+
endMatch = value.values.length - 1 === j
|
|
185
|
+
? thisValue.startsWith(valueValue)
|
|
186
|
+
: thisValue === valueValue;
|
|
187
|
+
}
|
|
188
|
+
if (!endMatch)
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
if (j === value.values.length)
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
/** @internal */
|
|
198
|
+
[Symbol.for("nodejs.util.inspect.custom")](depth, inspectOptions, inspect) {
|
|
199
|
+
const inspectFunction = inspect ?? inspectOptions?.inspect;
|
|
200
|
+
if (inspectFunction == null)
|
|
201
|
+
return JSON.stringify(this.toJSON(), undefined, 4);
|
|
202
|
+
return "LlamaText(" + inspectFunction(this.values, {
|
|
203
|
+
...(inspectOptions ?? {}),
|
|
204
|
+
depth: depth == null
|
|
205
|
+
? undefined
|
|
206
|
+
: Math.max(0, depth - 1)
|
|
207
|
+
}) + ")";
|
|
208
|
+
}
|
|
209
|
+
static fromJSON(json) {
|
|
210
|
+
// assigned to `LlamaTextConstructor` manually to expose this static method
|
|
211
|
+
if (typeof json === "string")
|
|
212
|
+
return new LlamaTextConstructor(json);
|
|
213
|
+
return new LlamaTextConstructor(json.map((value) => {
|
|
214
|
+
if (typeof value === "string")
|
|
215
|
+
return value;
|
|
216
|
+
else if (SpecialToken.isSpecialTokenJSON(value))
|
|
217
|
+
return SpecialToken.fromJSON(value);
|
|
218
|
+
else if (SpecialTokensText.isSpecialTokensTextJSON(value))
|
|
219
|
+
return SpecialTokensText.fromJSON(value);
|
|
220
|
+
else {
|
|
221
|
+
void value;
|
|
222
|
+
throw new Error(`Unknown value type: ${value}`);
|
|
223
|
+
}
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
static compare(a, b) {
|
|
227
|
+
// assigned to `LlamaTextConstructor` manually to expose this static method
|
|
228
|
+
if (!isLlamaText(a) || !isLlamaText(b))
|
|
229
|
+
return false;
|
|
230
|
+
if (a.values.length !== b.values.length)
|
|
231
|
+
return false;
|
|
232
|
+
for (let i = 0; i < a.values.length; i++) {
|
|
233
|
+
if (!compareLlamaTextValues(a.values[i], b.values[i]))
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
return true;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Attempt to convert tokens to a `LlamaText` while preserving special tokens.
|
|
240
|
+
*
|
|
241
|
+
* Non-standard special tokens that don't have a text representation are ignored.
|
|
242
|
+
*/
|
|
243
|
+
static fromTokens(tokenizer, tokens) {
|
|
244
|
+
// assigned to `LlamaTextConstructor` manually to expose this static method
|
|
245
|
+
const res = [];
|
|
246
|
+
const pendingTokens = [];
|
|
247
|
+
const addPendingTokens = () => {
|
|
248
|
+
if (pendingTokens.length === 0)
|
|
249
|
+
return;
|
|
250
|
+
res.push(tokenizer.detokenize(pendingTokens, false));
|
|
251
|
+
pendingTokens.length = 0;
|
|
252
|
+
};
|
|
253
|
+
const builtinTokens = SpecialToken.getTokenToValueMap(tokenizer);
|
|
254
|
+
for (const token of tokens) {
|
|
255
|
+
if (token == null)
|
|
256
|
+
continue;
|
|
257
|
+
const builtinTokenValue = builtinTokens.get(token);
|
|
258
|
+
if (builtinTokenValue != null) {
|
|
259
|
+
addPendingTokens();
|
|
260
|
+
res.push(new SpecialToken(builtinTokenValue));
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const regularText = tokenizer.detokenize([token], false);
|
|
264
|
+
const retokenizedRegularText = tokenizer(regularText, false, "trimLeadingSpace");
|
|
265
|
+
if (retokenizedRegularText.length === 1 && retokenizedRegularText[0] === token) {
|
|
266
|
+
pendingTokens.push(token);
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const specialText = tokenizer.detokenize([token], true);
|
|
270
|
+
const retokenizedSpecialText = tokenizer(specialText, true, "trimLeadingSpace");
|
|
271
|
+
if (retokenizedSpecialText.length === 1 && retokenizedSpecialText[0] === token) {
|
|
272
|
+
addPendingTokens();
|
|
273
|
+
res.push(new SpecialTokensText(specialText));
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
pendingTokens.push(token);
|
|
277
|
+
}
|
|
278
|
+
addPendingTokens();
|
|
279
|
+
return new LlamaTextConstructor(res);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Join values with the given separator before squashing adjacent strings inside the values
|
|
283
|
+
*/
|
|
284
|
+
static joinValues(separator, values) {
|
|
285
|
+
// assigned to `LlamaTextConstructor` manually to expose this static method
|
|
286
|
+
const newValues = [];
|
|
287
|
+
for (let i = 0; i < values.length; i++) {
|
|
288
|
+
const value = values[i];
|
|
289
|
+
if (i !== 0)
|
|
290
|
+
newValues.push(separator);
|
|
291
|
+
newValues.push(value);
|
|
292
|
+
}
|
|
293
|
+
return new LlamaTextConstructor(newValues);
|
|
294
|
+
}
|
|
295
|
+
static isLlamaText(value) {
|
|
296
|
+
// assigned to `LlamaTextConstructor` manually to expose this static method
|
|
297
|
+
if (value instanceof LlamaTextConstructor || value instanceof LlamaText)
|
|
298
|
+
return true;
|
|
299
|
+
try {
|
|
300
|
+
// detect a `LlamaText` created from a different module import
|
|
301
|
+
return value != null && Object.getPrototypeOf(value)?._type === "LlamaText";
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
Object.defineProperty(LlamaText.prototype, "_type", {
|
|
309
|
+
enumerable: false,
|
|
310
|
+
configurable: false,
|
|
311
|
+
value: "LlamaText"
|
|
312
|
+
});
|
|
313
|
+
const LlamaTextConstructor = function LlamaText(...values) {
|
|
314
|
+
// this makes the constructor callable also as a normal function
|
|
315
|
+
if (new.target == null)
|
|
316
|
+
return new LlamaTextConstructor(...values);
|
|
317
|
+
this.values = createHistoryFromStringsAndValues(values);
|
|
318
|
+
return this;
|
|
15
319
|
};
|
|
16
|
-
|
|
320
|
+
LlamaTextConstructor.prototype = Object.create(LlamaText.prototype);
|
|
321
|
+
LlamaTextConstructor.prototype.constructor = LlamaTextConstructor;
|
|
322
|
+
LlamaTextConstructor.fromJSON = LlamaText.fromJSON;
|
|
323
|
+
LlamaTextConstructor.compare = LlamaText.compare;
|
|
324
|
+
LlamaTextConstructor.fromTokens = LlamaText.fromTokens;
|
|
325
|
+
LlamaTextConstructor.joinValues = LlamaText.joinValues;
|
|
326
|
+
LlamaTextConstructor.isLlamaText = LlamaText.isLlamaText;
|
|
327
|
+
const _LlamaText = LlamaTextConstructor;
|
|
328
|
+
export { _LlamaText as LlamaText, LlamaText as _LlamaText };
|
|
329
|
+
export class SpecialTokensText {
|
|
17
330
|
value;
|
|
18
331
|
constructor(value) {
|
|
19
332
|
this.value = value;
|
|
@@ -21,187 +334,192 @@ export class SpecialToken {
|
|
|
21
334
|
toString() {
|
|
22
335
|
return this.value;
|
|
23
336
|
}
|
|
24
|
-
tokenize(tokenizer) {
|
|
25
|
-
return tokenizer(this.value, true);
|
|
337
|
+
tokenize(tokenizer, trimLeadingSpace = false) {
|
|
338
|
+
return tokenizer(this.value, true, trimLeadingSpace ? "trimLeadingSpace" : undefined);
|
|
339
|
+
}
|
|
340
|
+
tokenizeSpecialTokensOnly(tokenizer) {
|
|
341
|
+
const tokens = this.tokenize(tokenizer, true);
|
|
342
|
+
const res = [];
|
|
343
|
+
let currentText = "";
|
|
344
|
+
for (const token of tokens) {
|
|
345
|
+
if (tokenizer.isSpecialToken(token)) {
|
|
346
|
+
if (currentText !== "") {
|
|
347
|
+
res.push(currentText);
|
|
348
|
+
currentText = "";
|
|
349
|
+
}
|
|
350
|
+
res.push(token);
|
|
351
|
+
}
|
|
352
|
+
else {
|
|
353
|
+
currentText += tokenizer.detokenize([token], false);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
if (currentText !== "")
|
|
357
|
+
res.push(currentText);
|
|
358
|
+
return res;
|
|
26
359
|
}
|
|
27
360
|
toJSON() {
|
|
28
361
|
return {
|
|
29
|
-
type: "
|
|
362
|
+
type: "specialTokensText",
|
|
30
363
|
value: this.value
|
|
31
364
|
};
|
|
32
365
|
}
|
|
366
|
+
/** @internal */
|
|
367
|
+
[Symbol.for("nodejs.util.inspect.custom")](depth, inspectOptions, inspect) {
|
|
368
|
+
const inspectFunction = inspect ?? inspectOptions?.inspect;
|
|
369
|
+
if (inspectFunction == null)
|
|
370
|
+
return JSON.stringify(this.toJSON(), undefined, 4);
|
|
371
|
+
return "new SpecialTokensText(" + inspectFunction(this.value, {
|
|
372
|
+
...(inspectOptions ?? {}),
|
|
373
|
+
depth: depth == null
|
|
374
|
+
? undefined
|
|
375
|
+
: Math.max(0, depth - 1)
|
|
376
|
+
}) + ")";
|
|
377
|
+
}
|
|
33
378
|
static fromJSON(json) {
|
|
34
|
-
if (json
|
|
35
|
-
return new
|
|
36
|
-
|
|
37
|
-
return new SpecialToken(json.value);
|
|
379
|
+
if (SpecialTokensText.isSpecialTokensTextJSON(json))
|
|
380
|
+
return new SpecialTokensText(json.value);
|
|
381
|
+
throw new Error(`Invalid JSON for SpecialTokensText: ${JSON.stringify(json)}`);
|
|
38
382
|
}
|
|
39
|
-
static
|
|
40
|
-
return value != null && typeof value === "object" && value.type === "
|
|
383
|
+
static isSpecialTokensTextJSON(value) {
|
|
384
|
+
return value != null && typeof value === "object" && value.type === "specialTokensText";
|
|
385
|
+
}
|
|
386
|
+
/**
|
|
387
|
+
* Wraps the value with a `SpecialTokensText` only if `shouldWrap` is true
|
|
388
|
+
*/
|
|
389
|
+
static wrapIf(shouldWrap, value) {
|
|
390
|
+
if (shouldWrap)
|
|
391
|
+
return new SpecialTokensText(value);
|
|
392
|
+
else
|
|
393
|
+
return value;
|
|
41
394
|
}
|
|
42
395
|
}
|
|
43
|
-
export class
|
|
396
|
+
export class SpecialToken {
|
|
44
397
|
value;
|
|
45
398
|
constructor(value) {
|
|
46
|
-
super(value);
|
|
47
399
|
this.value = value;
|
|
48
400
|
}
|
|
401
|
+
toString() {
|
|
402
|
+
return this.value;
|
|
403
|
+
}
|
|
49
404
|
tokenize(tokenizer) {
|
|
50
405
|
return tokenizer(this.value, "builtin");
|
|
51
406
|
}
|
|
52
407
|
toJSON() {
|
|
53
408
|
return {
|
|
54
409
|
type: "specialToken",
|
|
55
|
-
value: this.value
|
|
56
|
-
builtin: true
|
|
410
|
+
value: this.value
|
|
57
411
|
};
|
|
58
412
|
}
|
|
413
|
+
/** @internal */
|
|
414
|
+
[Symbol.for("nodejs.util.inspect.custom")](depth, inspectOptions, inspect) {
|
|
415
|
+
const inspectFunction = inspect ?? inspectOptions?.inspect;
|
|
416
|
+
if (inspectFunction == null)
|
|
417
|
+
return JSON.stringify(this.toJSON(), undefined, 4);
|
|
418
|
+
return "new SpecialToken(" + inspectFunction(this.value, {
|
|
419
|
+
...(inspectOptions ?? {}),
|
|
420
|
+
depth: depth == null
|
|
421
|
+
? undefined
|
|
422
|
+
: Math.max(0, depth - 1)
|
|
423
|
+
}) + ")";
|
|
424
|
+
}
|
|
425
|
+
static fromJSON(json) {
|
|
426
|
+
if (SpecialToken.isSpecialTokenJSON(json))
|
|
427
|
+
return new SpecialToken(json.value);
|
|
428
|
+
throw new Error(`Invalid JSON for SpecialToken: ${JSON.stringify(json)}`);
|
|
429
|
+
}
|
|
430
|
+
static isSpecialTokenJSON(value) {
|
|
431
|
+
return value != null && typeof value === "object" && value.type === "specialToken";
|
|
432
|
+
}
|
|
433
|
+
static getTokenToValueMap(tokenizer) {
|
|
434
|
+
const supportedValues = [
|
|
435
|
+
"BOS", "EOS", "NL", "EOT"
|
|
436
|
+
];
|
|
437
|
+
void 0;
|
|
438
|
+
const res = new Map(supportedValues.map((value) => ([tokenizer(value, "builtin")[0], value])));
|
|
439
|
+
res.delete(undefined);
|
|
440
|
+
return res;
|
|
441
|
+
}
|
|
59
442
|
}
|
|
60
443
|
export function isLlamaText(value) {
|
|
61
|
-
return
|
|
444
|
+
return LlamaText.isLlamaText(value);
|
|
62
445
|
}
|
|
446
|
+
/**
|
|
447
|
+
* Tokenize the given input using the given tokenizer, whether it's a `string` or a `LlamaText`
|
|
448
|
+
*/
|
|
63
449
|
export function tokenizeText(text, tokenizer) {
|
|
64
450
|
if (typeof text === "string")
|
|
65
451
|
return tokenizer(text, false);
|
|
66
452
|
else
|
|
67
453
|
return text.tokenize(tokenizer);
|
|
68
454
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
newValues.push(this.values[i]);
|
|
77
|
-
if (i !== this.values.length - 1) {
|
|
78
|
-
if (isLlamaText(separator))
|
|
79
|
-
newValues.push(...separator.values);
|
|
80
|
-
else
|
|
81
|
-
newValues.push(separator);
|
|
82
|
-
}
|
|
455
|
+
function createHistoryFromStringsAndValues(values) {
|
|
456
|
+
function addItemToRes(res, item) {
|
|
457
|
+
if (item === undefined || item === "" || (item instanceof SpecialTokensText && item.value === ""))
|
|
458
|
+
return res;
|
|
459
|
+
else if (typeof item === "string" || item instanceof SpecialTokensText || item instanceof SpecialToken) {
|
|
460
|
+
res.push(item);
|
|
461
|
+
return res;
|
|
83
462
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
463
|
+
else if (isLlamaText(item)) {
|
|
464
|
+
for (const value of item.values)
|
|
465
|
+
res.push(value);
|
|
466
|
+
return res;
|
|
467
|
+
}
|
|
468
|
+
else if (item instanceof Array) {
|
|
469
|
+
for (const value of item) {
|
|
470
|
+
if (isLlamaText(value)) {
|
|
471
|
+
for (const innerValue of value.values)
|
|
472
|
+
res.push(innerValue);
|
|
473
|
+
}
|
|
474
|
+
else if (value === "" || (value instanceof SpecialTokensText && value.value === ""))
|
|
475
|
+
continue;
|
|
476
|
+
else if (value instanceof Array)
|
|
477
|
+
addItemToRes(res, value);
|
|
478
|
+
else if (typeof value === "number" || typeof value === "boolean")
|
|
479
|
+
res.push(String(value));
|
|
480
|
+
else
|
|
481
|
+
res.push(value);
|
|
103
482
|
}
|
|
104
|
-
|
|
105
|
-
textToTokenize += value;
|
|
483
|
+
return res;
|
|
106
484
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
},
|
|
110
|
-
toJSON() {
|
|
111
|
-
return this.values.map((value) => {
|
|
112
|
-
if (value instanceof SpecialToken)
|
|
113
|
-
return { type: "specialToken", value: value.value };
|
|
114
|
-
else
|
|
115
|
-
return value;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
function createLlamaText(history) {
|
|
120
|
-
const llamaText = function LlamaText(strings, ...values) {
|
|
121
|
-
return createLlamaText(llamaText.values.concat(createHistoryFromStringsAndValues(strings, values)));
|
|
122
|
-
};
|
|
123
|
-
Object.defineProperties(llamaText, {
|
|
124
|
-
["type"]: {
|
|
125
|
-
value: "LlamaText",
|
|
126
|
-
writable: false,
|
|
127
|
-
configurable: false,
|
|
128
|
-
enumerable: true
|
|
129
|
-
},
|
|
130
|
-
["values"]: {
|
|
131
|
-
value: Object.freeze(history.slice()),
|
|
132
|
-
writable: false,
|
|
133
|
-
configurable: false,
|
|
134
|
-
enumerable: true
|
|
135
|
-
},
|
|
136
|
-
["mapValues"]: {
|
|
137
|
-
value: LlamaTextPrototypeFunctions.mapValues,
|
|
138
|
-
writable: false,
|
|
139
|
-
configurable: false,
|
|
140
|
-
enumerable: false
|
|
141
|
-
},
|
|
142
|
-
["joinValues"]: {
|
|
143
|
-
value: LlamaTextPrototypeFunctions.joinValues,
|
|
144
|
-
writable: false,
|
|
145
|
-
configurable: false,
|
|
146
|
-
enumerable: false
|
|
147
|
-
},
|
|
148
|
-
["toString"]: {
|
|
149
|
-
value: LlamaTextPrototypeFunctions.toString,
|
|
150
|
-
writable: false,
|
|
151
|
-
configurable: false,
|
|
152
|
-
enumerable: false
|
|
153
|
-
},
|
|
154
|
-
["tokenize"]: {
|
|
155
|
-
value: LlamaTextPrototypeFunctions.tokenize,
|
|
156
|
-
writable: false,
|
|
157
|
-
configurable: false,
|
|
158
|
-
enumerable: false
|
|
159
|
-
},
|
|
160
|
-
["toJSON"]: {
|
|
161
|
-
value: LlamaTextPrototypeFunctions.toJSON,
|
|
162
|
-
writable: false,
|
|
163
|
-
configurable: false,
|
|
164
|
-
enumerable: false
|
|
165
|
-
}
|
|
166
|
-
});
|
|
167
|
-
return llamaText;
|
|
168
|
-
}
|
|
169
|
-
function createHistoryFromStringsAndValues(strings, values) {
|
|
170
|
-
function addItemToRes(res, item) {
|
|
171
|
-
if (item === undefined || item === "")
|
|
485
|
+
else if (typeof item === "number" || typeof item === "boolean") {
|
|
486
|
+
res.push(String(item));
|
|
172
487
|
return res;
|
|
173
|
-
|
|
174
|
-
return res.concat([item]);
|
|
175
|
-
else if (isLlamaText(item))
|
|
176
|
-
return res.concat(item.values);
|
|
177
|
-
else if (item instanceof Array) {
|
|
178
|
-
return res.concat(item.reduce((res, value) => {
|
|
179
|
-
if (isLlamaText(value))
|
|
180
|
-
return res.concat(value.values);
|
|
181
|
-
else if (value === "")
|
|
182
|
-
return res;
|
|
183
|
-
return res.concat([value]);
|
|
184
|
-
}, []));
|
|
185
|
-
}
|
|
186
|
-
else if (typeof item === "number" || typeof item === "boolean")
|
|
187
|
-
return res.concat([String(item)]);
|
|
488
|
+
}
|
|
188
489
|
return item;
|
|
189
490
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
491
|
+
function squashAdjacentItems(res, item) {
|
|
492
|
+
if (res.length === 0) {
|
|
493
|
+
res.push(item);
|
|
494
|
+
return res;
|
|
495
|
+
}
|
|
496
|
+
const lastItem = res[res.length - 1];
|
|
497
|
+
if (lastItem instanceof SpecialToken || item instanceof SpecialToken) {
|
|
498
|
+
res.push(item);
|
|
499
|
+
return res;
|
|
500
|
+
}
|
|
501
|
+
if (typeof lastItem === "string" && typeof item === "string") {
|
|
502
|
+
res[res.length - 1] += item;
|
|
503
|
+
return res;
|
|
504
|
+
}
|
|
505
|
+
else if (lastItem instanceof SpecialTokensText && item instanceof SpecialTokensText) {
|
|
506
|
+
res[res.length - 1] = new SpecialTokensText(lastItem.value + item.value);
|
|
507
|
+
return res;
|
|
508
|
+
}
|
|
509
|
+
res.push(item);
|
|
510
|
+
return res;
|
|
200
511
|
}
|
|
201
|
-
return
|
|
512
|
+
return values
|
|
513
|
+
.reduce(addItemToRes, [])
|
|
514
|
+
.reduce(squashAdjacentItems, []);
|
|
202
515
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
205
|
-
value
|
|
516
|
+
function compareLlamaTextValues(a, b) {
|
|
517
|
+
if (a instanceof SpecialTokensText && b instanceof SpecialTokensText)
|
|
518
|
+
return a.value === b.value;
|
|
519
|
+
else if (a instanceof SpecialToken && b instanceof SpecialToken)
|
|
520
|
+
return a.value === b.value;
|
|
521
|
+
else if (a !== b)
|
|
522
|
+
return false;
|
|
523
|
+
return true;
|
|
206
524
|
}
|
|
207
525
|
//# sourceMappingURL=LlamaText.js.map
|