node-llama-cpp 3.0.0-beta.13 → 3.0.0-beta.15
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 +1 -1
- package/dist/ChatWrapper.js +4 -0
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/bindings/AddonTypes.d.ts +35 -6
- package/dist/bindings/Llama.d.ts +12 -0
- package/dist/bindings/Llama.js +100 -7
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/getLlama.d.ts +19 -1
- package/dist/bindings/getLlama.js +16 -6
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/types.d.ts +18 -0
- package/dist/bindings/types.js +31 -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/cloneLlamaCppRepo.d.ts +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.js +4 -3
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.d.ts +4 -1
- package/dist/bindings/utils/compileLLamaCpp.js +133 -97
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +3 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +155 -13
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -1
- 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/logDistroInstallInstruction.d.ts +1 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js +16 -6
- package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -1
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +2 -2
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -1
- package/dist/bindings/utils/testBindingBinary.js +2 -2
- package/dist/bindings/utils/testBindingBinary.js.map +1 -1
- 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 +9 -2
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/ChatMLChatWrapper.js +12 -10
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FalconChatWrapper.d.ts +2 -1
- package/dist/chatWrappers/FalconChatWrapper.js +28 -11
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FunctionaryChatWrapper.js +59 -45
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GemmaChatWrapper.js +9 -7
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GeneralChatWrapper.d.ts +2 -1
- package/dist/chatWrappers/GeneralChatWrapper.js +35 -12
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
- package/dist/chatWrappers/LlamaChatWrapper.d.ts +7 -0
- package/dist/chatWrappers/LlamaChatWrapper.js +26 -8
- package/dist/chatWrappers/LlamaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +73 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +355 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/{TemplateChatWrapper.d.ts → chatWrappers/generic/TemplateChatWrapper.d.ts} +16 -18
- package/dist/{TemplateChatWrapper.js → chatWrappers/generic/TemplateChatWrapper.js} +31 -69
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +33 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +206 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +67 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +206 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.js +1 -1
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +7 -4
- package/dist/cli/commands/ChatCommand.js +177 -70
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/ClearCommand.d.ts +1 -1
- package/dist/cli/commands/ClearCommand.js +5 -5
- package/dist/cli/commands/ClearCommand.js.map +1 -1
- package/dist/cli/commands/CompleteCommand.d.ts +3 -2
- package/dist/cli/commands/CompleteCommand.js +115 -51
- package/dist/cli/commands/CompleteCommand.js.map +1 -1
- package/dist/cli/commands/InfillCommand.d.ts +3 -2
- package/dist/cli/commands/InfillCommand.js +115 -51
- package/dist/cli/commands/InfillCommand.js.map +1 -1
- package/dist/cli/commands/OnPostInstallCommand.js +2 -0
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
- package/dist/cli/commands/{InspectCommand.d.ts → inspect/InspectCommand.d.ts} +1 -4
- package/dist/cli/commands/inspect/InspectCommand.js +17 -0
- package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +10 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +108 -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 +98 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +14 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +577 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.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/printCommonInfoLines.d.ts +9 -0
- package/dist/cli/utils/printCommonInfoLines.js +70 -0
- package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
- package/dist/cli/utils/printInfoLine.d.ts +10 -0
- package/dist/cli/utils/printInfoLine.js +45 -0
- package/dist/cli/utils/printInfoLine.js.map +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +6 -0
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
- package/dist/config.d.ts +3 -1
- package/dist/config.js +7 -1
- package/dist/config.js.map +1 -1
- package/dist/evaluator/LlamaChat/LlamaChat.js +13 -5
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.js +5 -3
- package/dist/evaluator/LlamaCompletion.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +43 -9
- package/dist/evaluator/LlamaContext/LlamaContext.js +251 -60
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaContext/types.d.ts +68 -10
- 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} +4 -4
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +29 -7
- package/dist/evaluator/LlamaEmbeddingContext.js +31 -22
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.js +1 -0
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel.d.ts +78 -20
- package/dist/evaluator/LlamaModel.js +385 -21
- package/dist/evaluator/LlamaModel.js.map +1 -1
- package/dist/evaluator/TokenMeter.d.ts +54 -0
- package/dist/evaluator/TokenMeter.js +86 -0
- package/dist/evaluator/TokenMeter.js.map +1 -0
- package/dist/gguf/GgufInsights.d.ts +40 -0
- package/dist/gguf/GgufInsights.js +350 -0
- package/dist/gguf/GgufInsights.js.map +1 -0
- package/dist/gguf/consts.d.ts +3 -0
- package/dist/gguf/consts.js +8 -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 +33 -0
- package/dist/gguf/fileReaders/GgufFileReader.js +76 -0
- package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +17 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js +45 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +22 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +63 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/parser/GgufV2Parser.d.ts +19 -0
- package/dist/gguf/parser/GgufV2Parser.js +115 -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 +58 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -0
- package/dist/gguf/readGgufFileInfo.d.ts +30 -0
- package/dist/gguf/readGgufFileInfo.js +37 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +52 -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 +330 -0
- package/dist/gguf/types/GgufMetadataTypes.js +86 -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 +5 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +38 -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/index.d.ts +13 -7
- package/dist/index.js +11 -6
- 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/types.d.ts +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 +25 -10
- package/dist/utils/LlamaText.js +205 -23
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/StopGenerationDetector.js +3 -1
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/cmake.js +1 -1
- package/dist/utils/cmake.js.map +1 -1
- 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/getConsoleLogPrefix.js +3 -2
- package/dist/utils/getConsoleLogPrefix.js.map +1 -1
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js +3 -3
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -1
- package/dist/utils/gitReleaseBundles.js +68 -1
- package/dist/utils/gitReleaseBundles.js.map +1 -1
- package/dist/utils/mergeUnionTypes.d.ts +4 -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/prettyPrintObject.d.ts +10 -1
- package/dist/utils/prettyPrintObject.js +57 -13
- package/dist/utils/prettyPrintObject.js.map +1 -1
- package/dist/utils/removeNullFields.d.ts +2 -2
- package/dist/utils/removeNullFields.js.map +1 -1
- package/dist/utils/spawnCommand.d.ts +11 -1
- 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 +3 -3
- package/dist/utils/tokenizeInput.js.map +1 -1
- package/dist/utils/withOra.d.ts +1 -0
- package/dist/utils/withOra.js +2 -2
- package/dist/utils/withOra.js.map +1 -1
- package/llama/CMakeLists.txt +5 -5
- package/llama/addon.cpp +793 -88
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/gpuInfo/cuda-gpu-info.cu +21 -0
- package/llama/gpuInfo/cuda-gpu-info.h +3 -0
- package/llama/gpuInfo/metal-gpu-info.h +4 -1
- package/llama/gpuInfo/metal-gpu-info.mm +14 -1
- package/llama/gpuInfo/vulkan-gpu-info.cpp +20 -2
- package/llama/gpuInfo/vulkan-gpu-info.h +2 -0
- package/llama/grammars/json.gbnf +1 -1
- package/llama/grammars/json_arr.gbnf +1 -1
- package/llama/llama.cpp.info.json +1 -1
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
- package/llamaBins/linux-arm64/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/linux-x64-cuda/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/linux-x64-vulkan/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/linux-x64-vulkan/llama-addon.node +0 -0
- package/llamaBins/mac-arm64-metal/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/mac-arm64-metal/default.metallib +0 -0
- package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
- package/llamaBins/mac-x64/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-arm64/_nlcBuildMetadata.json +1 -0
- package/llamaBins/win-arm64/llama-addon.exp +0 -0
- package/llamaBins/win-arm64/llama-addon.lib +0 -0
- package/llamaBins/win-arm64/llama-addon.node +0 -0
- package/llamaBins/win-x64/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -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 → _nlcBuildMetadata.json} +1 -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/llamaBins/win-x64-vulkan/{.buildMetadata.json → _nlcBuildMetadata.json} +1 -1
- package/llamaBins/win-x64-vulkan/llama-addon.exp +0 -0
- package/llamaBins/win-x64-vulkan/llama-addon.lib +0 -0
- package/llamaBins/win-x64-vulkan/llama-addon.node +0 -0
- package/package.json +16 -11
- package/dist/TemplateChatWrapper.js.map +0 -1
- package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.d.ts +0 -33
- package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.js +0 -49
- package/dist/bindings/utils/resolveChatWrapperBasedOnWrapperTypeName.js.map +0 -1
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -63
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
- package/dist/cli/commands/InspectCommand.js +0 -113
- package/dist/cli/commands/InspectCommand.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/gguf/GGUFInsights.d.ts +0 -28
- package/dist/gguf/GGUFInsights.js +0 -58
- package/dist/gguf/GGUFInsights.js.map +0 -1
- package/dist/gguf/GGUFMetadata.d.ts +0 -19
- package/dist/gguf/GGUFMetadata.js +0 -38
- package/dist/gguf/GGUFMetadata.js.map +0 -1
- package/dist/gguf/errors/InvalidGGUFMagicError.d.ts +0 -3
- package/dist/gguf/errors/InvalidGGUFMagicError.js +0 -6
- package/dist/gguf/errors/InvalidGGUFMagicError.js.map +0 -1
- package/dist/gguf/errors/MetadataNotParsedYetError.d.ts +0 -3
- package/dist/gguf/errors/MetadataNotParsedYetError.js +0 -6
- package/dist/gguf/errors/MetadataNotParsedYetError.js.map +0 -1
- package/dist/gguf/errors/MissingNodeLlamaError.d.ts +0 -3
- package/dist/gguf/errors/MissingNodeLlamaError.js +0 -6
- package/dist/gguf/errors/MissingNodeLlamaError.js.map +0 -1
- package/dist/gguf/errors/ModelScore/NotEnoughVRamError.d.ts +0 -5
- package/dist/gguf/errors/ModelScore/NotEnoughVRamError.js +0 -12
- package/dist/gguf/errors/ModelScore/NotEnoughVRamError.js.map +0 -1
- package/dist/gguf/errors/UnsupportedMetadataTypeError.d.ts +0 -4
- package/dist/gguf/errors/UnsupportedMetadataTypeError.js +0 -8
- package/dist/gguf/errors/UnsupportedMetadataTypeError.js.map +0 -1
- package/dist/gguf/ggufParser/GGUFParser.d.ts +0 -18
- package/dist/gguf/ggufParser/GGUFParser.js +0 -123
- package/dist/gguf/ggufParser/GGUFParser.js.map +0 -1
- package/dist/gguf/ggufParser/GGUFTypes.d.ts +0 -257
- package/dist/gguf/ggufParser/GGUFTypes.js +0 -2
- package/dist/gguf/ggufParser/GGUFTypes.js.map +0 -1
- package/dist/gguf/ggufParser/checkArchitecture.d.ts +0 -14
- package/dist/gguf/ggufParser/checkArchitecture.js +0 -74
- package/dist/gguf/ggufParser/checkArchitecture.js.map +0 -1
- package/dist/gguf/ggufParser/stream/GGUFBaseStream.d.ts +0 -38
- package/dist/gguf/ggufParser/stream/GGUFBaseStream.js +0 -83
- package/dist/gguf/ggufParser/stream/GGUFBaseStream.js.map +0 -1
- package/dist/gguf/ggufParser/stream/GGUFFetchStream.d.ts +0 -14
- package/dist/gguf/ggufParser/stream/GGUFFetchStream.js +0 -35
- package/dist/gguf/ggufParser/stream/GGUFFetchStream.js.map +0 -1
- package/dist/gguf/ggufParser/stream/GGUFReadStream.d.ts +0 -15
- package/dist/gguf/ggufParser/stream/GGUFReadStream.js +0 -40
- package/dist/gguf/ggufParser/stream/GGUFReadStream.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/llamaBins/mac-arm64-metal/ggml-metal.metal +0 -7731
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ChatWrapper } from "
|
|
3
|
-
import { parseTextTemplate } from "
|
|
1
|
+
import { SpecialToken, LlamaText, SpecialTokensText } from "../../utils/LlamaText.js";
|
|
2
|
+
import { ChatWrapper } from "../../ChatWrapper.js";
|
|
3
|
+
import { parseTextTemplate } from "../../utils/parseTextTemplate.js";
|
|
4
|
+
import { parseFunctionCallMessageTemplate } from "./utils/chatHistoryFunctionCallMessageTemplate.js";
|
|
4
5
|
/**
|
|
5
6
|
* A chat wrapper based on a simple template.
|
|
6
7
|
*
|
|
@@ -45,6 +46,8 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
45
46
|
/** @internal */ _parsedChatHistoryTemplate;
|
|
46
47
|
constructor({ template, historyTemplate, modelRoleName, userRoleName, systemRoleName = "System", functionCallMessageTemplate, joinAdjacentMessagesOfTheSameType = true }) {
|
|
47
48
|
super();
|
|
49
|
+
if (template == null || historyTemplate == null || modelRoleName == null || userRoleName == null)
|
|
50
|
+
throw new Error("Template chat wrapper settings must have a template, historyTemplate, modelRoleName, and userRoleName.");
|
|
48
51
|
this.template = template;
|
|
49
52
|
this.historyTemplate = historyTemplate;
|
|
50
53
|
this.modelRoleName = modelRoleName;
|
|
@@ -63,9 +66,9 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
63
66
|
documentParams: documentFunctionParams
|
|
64
67
|
});
|
|
65
68
|
const resultItems = [];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const systemTexts = [];
|
|
70
|
+
const userTexts = [];
|
|
71
|
+
const modelTexts = [];
|
|
69
72
|
let currentAggregateFocus = null;
|
|
70
73
|
function flush() {
|
|
71
74
|
if (systemTexts.length > 0 || userTexts.length > 0 || modelTexts.length > 0)
|
|
@@ -74,18 +77,10 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
74
77
|
user: userTexts.join("\n\n"),
|
|
75
78
|
model: modelTexts.join("\n\n")
|
|
76
79
|
});
|
|
77
|
-
systemTexts =
|
|
78
|
-
userTexts =
|
|
79
|
-
modelTexts =
|
|
80
|
+
systemTexts.length = 0;
|
|
81
|
+
userTexts.length = 0;
|
|
82
|
+
modelTexts.length = 0;
|
|
80
83
|
}
|
|
81
|
-
const getHistoryItem = (role, text, prefix) => {
|
|
82
|
-
const { roleNamePrefix, messagePrefix, messageSuffix } = this._parsedChatHistoryTemplate;
|
|
83
|
-
return LlamaText([
|
|
84
|
-
new SpecialToken((prefix ?? "") + roleNamePrefix + role + messagePrefix),
|
|
85
|
-
text,
|
|
86
|
-
new SpecialToken(messageSuffix)
|
|
87
|
-
]);
|
|
88
|
-
};
|
|
89
84
|
for (const item of historyWithFunctions) {
|
|
90
85
|
if (item.type === "system") {
|
|
91
86
|
if (!this.joinAdjacentMessagesOfTheSameType || currentAggregateFocus !== "system")
|
|
@@ -105,20 +100,30 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
105
100
|
currentAggregateFocus = "model";
|
|
106
101
|
modelTexts.push(this.generateModelResponseText(item.response));
|
|
107
102
|
}
|
|
103
|
+
else
|
|
104
|
+
void (item);
|
|
108
105
|
}
|
|
109
106
|
flush();
|
|
107
|
+
const getHistoryItem = (role, text, prefix) => {
|
|
108
|
+
const { roleNamePrefix, messagePrefix, messageSuffix } = this._parsedChatHistoryTemplate;
|
|
109
|
+
return LlamaText([
|
|
110
|
+
new SpecialTokensText((prefix ?? "") + roleNamePrefix + role + messagePrefix),
|
|
111
|
+
text,
|
|
112
|
+
new SpecialTokensText(messageSuffix)
|
|
113
|
+
]);
|
|
114
|
+
};
|
|
110
115
|
const contextText = LlamaText(resultItems.map(({ system, user, model }, index) => {
|
|
111
116
|
const isFirstItem = index === 0;
|
|
112
117
|
const isLastItem = index === resultItems.length - 1;
|
|
113
118
|
const res = LlamaText([
|
|
114
119
|
isFirstItem
|
|
115
120
|
? system.length === 0
|
|
116
|
-
? new
|
|
121
|
+
? new SpecialTokensText((this._parsedChatTemplate.systemPromptPrefix ?? "") + this._parsedChatTemplate.historyPrefix)
|
|
117
122
|
: this._parsedChatTemplate.systemPromptPrefix != null
|
|
118
123
|
? LlamaText([
|
|
119
|
-
new
|
|
124
|
+
new SpecialTokensText(this._parsedChatTemplate.systemPromptPrefix),
|
|
120
125
|
system,
|
|
121
|
-
new
|
|
126
|
+
new SpecialTokensText(this._parsedChatTemplate.historyPrefix)
|
|
122
127
|
])
|
|
123
128
|
: getHistoryItem("system", system, this._parsedChatTemplate.historyPrefix)
|
|
124
129
|
: system.length === 0
|
|
@@ -132,17 +137,17 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
132
137
|
: !isLastItem
|
|
133
138
|
? getHistoryItem("model", model)
|
|
134
139
|
: LlamaText([
|
|
135
|
-
new
|
|
140
|
+
new SpecialTokensText(this._parsedChatTemplate.completionPrefix),
|
|
136
141
|
model
|
|
137
142
|
])
|
|
138
143
|
]);
|
|
139
144
|
return LlamaText(res.values.reduce((res, value) => {
|
|
140
|
-
if (value instanceof
|
|
145
|
+
if (value instanceof SpecialTokensText) {
|
|
141
146
|
const lastItem = res[res.length - 1];
|
|
142
|
-
if (lastItem == null || !(lastItem instanceof
|
|
147
|
+
if (lastItem == null || !(lastItem instanceof SpecialTokensText))
|
|
143
148
|
return res.concat([value]);
|
|
144
149
|
return res.slice(0, -1).concat([
|
|
145
|
-
new
|
|
150
|
+
new SpecialTokensText(lastItem.value + value.value)
|
|
146
151
|
]);
|
|
147
152
|
}
|
|
148
153
|
return res.concat([value]);
|
|
@@ -151,56 +156,13 @@ export class TemplateChatWrapper extends ChatWrapper {
|
|
|
151
156
|
return {
|
|
152
157
|
contextText,
|
|
153
158
|
stopGenerationTriggers: [
|
|
154
|
-
LlamaText(new
|
|
159
|
+
LlamaText(new SpecialToken("EOS")),
|
|
155
160
|
LlamaText(this._parsedChatTemplate.completionSuffix),
|
|
156
|
-
LlamaText(new
|
|
161
|
+
LlamaText(new SpecialTokensText(this._parsedChatTemplate.completionSuffix))
|
|
157
162
|
]
|
|
158
163
|
};
|
|
159
164
|
}
|
|
160
165
|
}
|
|
161
|
-
function parseFunctionCallMessageTemplate(template) {
|
|
162
|
-
if (template == null)
|
|
163
|
-
return null;
|
|
164
|
-
const [functionCallTemplate, functionCallResultTemplate] = template;
|
|
165
|
-
if (functionCallTemplate == null || functionCallResultTemplate == null)
|
|
166
|
-
throw new Error("Both function call and function call result templates are required");
|
|
167
|
-
const parsedFunctionCallTemplate = parseTextTemplate(functionCallTemplate, [{
|
|
168
|
-
text: "{{functionName}}",
|
|
169
|
-
key: "functionName"
|
|
170
|
-
}, {
|
|
171
|
-
text: "{{functionParams}}",
|
|
172
|
-
key: "functionParams"
|
|
173
|
-
}]);
|
|
174
|
-
const parsedFunctionCallResultTemplate = parseTextTemplate(functionCallResultTemplate, [{
|
|
175
|
-
text: "{{functionCallResult}}",
|
|
176
|
-
key: "functionCallResult"
|
|
177
|
-
}]);
|
|
178
|
-
const callPrefix = parsedFunctionCallTemplate.functionName.prefix;
|
|
179
|
-
const callParamsPrefix = parsedFunctionCallTemplate.functionParams.prefix;
|
|
180
|
-
const callSuffix = parsedFunctionCallTemplate.functionParams.suffix;
|
|
181
|
-
const resultPrefix = parsedFunctionCallResultTemplate.functionCallResult.prefix;
|
|
182
|
-
const resultSuffix = parsedFunctionCallResultTemplate.functionCallResult.suffix;
|
|
183
|
-
if (callPrefix.length === 0)
|
|
184
|
-
throw new Error('Function call template must have text before "{{functionName}}"');
|
|
185
|
-
if (callSuffix.length === 0)
|
|
186
|
-
throw new Error('Function call template must have text after "{{functionParams}}"');
|
|
187
|
-
if (resultPrefix.length === 0)
|
|
188
|
-
throw new Error('Function call result template must have text before "{{functionCallResult}}"');
|
|
189
|
-
if (resultSuffix.length === 0)
|
|
190
|
-
throw new Error('Function call result template must have text after "{{functionCallResult}}"');
|
|
191
|
-
return {
|
|
192
|
-
call: {
|
|
193
|
-
optionalPrefixSpace: true,
|
|
194
|
-
prefix: callPrefix,
|
|
195
|
-
paramsPrefix: callParamsPrefix,
|
|
196
|
-
suffix: callSuffix
|
|
197
|
-
},
|
|
198
|
-
result: {
|
|
199
|
-
prefix: resultPrefix,
|
|
200
|
-
suffix: resultSuffix
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
166
|
function parseChatTemplate(template) {
|
|
205
167
|
const parsedTemplate = parseTextTemplate(template, [{
|
|
206
168
|
text: "{{systemPrompt}}",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TemplateChatWrapper.js","sourceRoot":"","sources":["../../../src/chatWrappers/generic/TemplateChatWrapper.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,YAAY,EAAE,SAAS,EAAkB,iBAAiB,EAAC,MAAM,0BAA0B,CAAC;AACpG,OAAO,EAAC,WAAW,EAAsB,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAyC,gCAAgC,EAAC,MAAM,mDAAmD,CAAC;AAe3I;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAChC,WAAW,GAAG,UAAU,CAAC;IAChB,QAAQ,CAAsB;IAEvC,QAAQ,CAAe;IACvB,eAAe,CAAsB;IACrC,aAAa,CAAS;IACtB,YAAY,CAAS;IACrB,cAAc,CAAS;IACvB,iCAAiC,CAAU;IAE3D,gBAAgB,CAAk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ED,SAAS,wBAAwB,CAAC,QAA6B;IAK3D,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;YAChD,IAAI,EAAE,cAAc;YACpB,GAAG,EAAE,UAAU;SAClB,EAAE;YACC,IAAI,EAAE,aAAa;YACnB,GAAG,EAAE,SAAS;SACjB,CAAC,CAAC,CAAC;IAEJ,OAAO;QACH,cAAc,EAAE,cAAc,CAAC,QAAQ,CAAC,MAAM;QAC9C,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM;QAC5C,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM;KAC/C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare function parseFunctionCallMessageTemplate(template?: ChatHistoryFunctionCallMessageTemplate): {
|
|
2
|
+
call: {
|
|
3
|
+
optionalPrefixSpace: boolean;
|
|
4
|
+
prefix: string;
|
|
5
|
+
paramsPrefix: string;
|
|
6
|
+
suffix: string;
|
|
7
|
+
};
|
|
8
|
+
result: {
|
|
9
|
+
prefix: string;
|
|
10
|
+
suffix: string;
|
|
11
|
+
};
|
|
12
|
+
} | null;
|
|
13
|
+
/**
|
|
14
|
+
* Template format for how functions can be called by the model and how their results are fed to the model after the function call.
|
|
15
|
+
* Consists of an array with two elements:
|
|
16
|
+
* 1. The function call template.
|
|
17
|
+
* 2. The function call result template.
|
|
18
|
+
*
|
|
19
|
+
* For example:
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const template: ChatHistoryFunctionCallMessageTemplate = [
|
|
22
|
+
* "[[call: {{functionName}}({{functionParams}})]]"
|
|
23
|
+
* " [[result: {{functionCallResult}}]]"
|
|
24
|
+
* ];
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* It's mandatory for the call template to have text before `{{functionName}}` in order for the chat wrapper know when
|
|
28
|
+
* to activate the function calling grammar.
|
|
29
|
+
*/
|
|
30
|
+
export type ChatHistoryFunctionCallMessageTemplate = [
|
|
31
|
+
call: `${string}{{functionName}}${string}{{functionParams}}${string}`,
|
|
32
|
+
result: `${string}{{functionCallResult}}${string}`
|
|
33
|
+
];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { parseTextTemplate } from "../../../utils/parseTextTemplate.js";
|
|
2
|
+
export function parseFunctionCallMessageTemplate(template) {
|
|
3
|
+
if (template == null)
|
|
4
|
+
return null;
|
|
5
|
+
const [functionCallTemplate, functionCallResultTemplate] = template;
|
|
6
|
+
if (functionCallTemplate == null || functionCallResultTemplate == null)
|
|
7
|
+
throw new Error("Both function call and function call result templates are required");
|
|
8
|
+
const parsedFunctionCallTemplate = parseTextTemplate(functionCallTemplate, [{
|
|
9
|
+
text: "{{functionName}}",
|
|
10
|
+
key: "functionName"
|
|
11
|
+
}, {
|
|
12
|
+
text: "{{functionParams}}",
|
|
13
|
+
key: "functionParams"
|
|
14
|
+
}]);
|
|
15
|
+
const parsedFunctionCallResultTemplate = parseTextTemplate(functionCallResultTemplate, [{
|
|
16
|
+
text: "{{functionCallResult}}",
|
|
17
|
+
key: "functionCallResult"
|
|
18
|
+
}]);
|
|
19
|
+
const callPrefix = parsedFunctionCallTemplate.functionName.prefix;
|
|
20
|
+
const callParamsPrefix = parsedFunctionCallTemplate.functionParams.prefix;
|
|
21
|
+
const callSuffix = parsedFunctionCallTemplate.functionParams.suffix;
|
|
22
|
+
const resultPrefix = parsedFunctionCallResultTemplate.functionCallResult.prefix;
|
|
23
|
+
const resultSuffix = parsedFunctionCallResultTemplate.functionCallResult.suffix;
|
|
24
|
+
if (callPrefix.length === 0)
|
|
25
|
+
throw new Error("Function call template must have text before \"{{functionName}}\"");
|
|
26
|
+
if (callSuffix.length === 0)
|
|
27
|
+
throw new Error("Function call template must have text after \"{{functionParams}}\"");
|
|
28
|
+
if (resultPrefix.length === 0)
|
|
29
|
+
throw new Error("Function call result template must have text before \"{{functionCallResult}}\"");
|
|
30
|
+
if (resultSuffix.length === 0)
|
|
31
|
+
throw new Error("Function call result template must have text after \"{{functionCallResult}}\"");
|
|
32
|
+
return {
|
|
33
|
+
call: {
|
|
34
|
+
optionalPrefixSpace: true,
|
|
35
|
+
prefix: callPrefix,
|
|
36
|
+
paramsPrefix: callParamsPrefix,
|
|
37
|
+
suffix: callSuffix
|
|
38
|
+
},
|
|
39
|
+
result: {
|
|
40
|
+
prefix: resultPrefix,
|
|
41
|
+
suffix: resultSuffix
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=chatHistoryFunctionCallMessageTemplate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chatHistoryFunctionCallMessageTemplate.js","sourceRoot":"","sources":["../../../../src/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAC,MAAM,qCAAqC,CAAC;AAEtE,MAAM,UAAU,gCAAgC,CAAC,QAAiD;IAC9F,IAAI,QAAQ,IAAI,IAAI;QAChB,OAAO,IAAI,CAAC;IAEhB,MAAM,CAAC,oBAAoB,EAAE,0BAA0B,CAAC,GAAG,QAAQ,CAAC;IAEpE,IAAI,oBAAoB,IAAI,IAAI,IAAI,0BAA0B,IAAI,IAAI;QAClE,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAE1F,MAAM,0BAA0B,GAAG,iBAAiB,CAAC,oBAAoB,EAAE,CAAC;YACxE,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,cAAc;SACtB,EAAE;YACC,IAAI,EAAE,oBAAoB;YAC1B,GAAG,EAAE,gBAAgB;SACxB,CAAC,CAAC,CAAC;IACJ,MAAM,gCAAgC,GAAG,iBAAiB,CAAC,0BAA0B,EAAE,CAAC;YACpF,IAAI,EAAE,wBAAwB;YAC9B,GAAG,EAAE,oBAAoB;SAC5B,CAAC,CAAC,CAAC;IAEJ,MAAM,UAAU,GAAG,0BAA0B,CAAC,YAAY,CAAC,MAAM,CAAC;IAClE,MAAM,gBAAgB,GAAG,0BAA0B,CAAC,cAAc,CAAC,MAAM,CAAC;IAC1E,MAAM,UAAU,GAAG,0BAA0B,CAAC,cAAc,CAAC,MAAM,CAAC;IAEpE,MAAM,YAAY,GAAG,gCAAgC,CAAC,kBAAkB,CAAC,MAAM,CAAC;IAChF,MAAM,YAAY,GAAG,gCAAgC,CAAC,kBAAkB,CAAC,MAAM,CAAC;IAEhF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IAEzF,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,oEAAoE,CAAC,CAAC;IAE1F,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,gFAAgF,CAAC,CAAC;IAEtG,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,+EAA+E,CAAC,CAAC;IAErG,OAAO;QACH,IAAI,EAAE;YACF,mBAAmB,EAAE,IAAI;YACzB,MAAM,EAAE,UAAU;YAClB,YAAY,EAAE,gBAAgB;YAC9B,MAAM,EAAE,UAAU;SACrB;QACD,MAAM,EAAE;YACJ,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE,YAAY;SACvB;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ChatWrapper } from "../../ChatWrapper.js";
|
|
2
|
+
import { Tokenizer } from "../../types.js";
|
|
3
|
+
import { JinjaTemplateChatWrapperOptions } from "../generic/JinjaTemplateChatWrapper.js";
|
|
4
|
+
export declare function isJinjaTemplateEquivalentToSpecializedChatWrapper(jinjaTemplateWrapperOptions: JinjaTemplateChatWrapperOptions, specializedChatWrapper: ChatWrapper, tokenizer?: Tokenizer): boolean;
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { JinjaTemplateChatWrapper } from "../generic/JinjaTemplateChatWrapper.js";
|
|
2
|
+
import { SpecialToken, LlamaText } from "../../utils/LlamaText.js";
|
|
3
|
+
import { compareTokens } from "../../utils/compareTokens.js";
|
|
4
|
+
import { StopGenerationDetector } from "../../utils/StopGenerationDetector.js";
|
|
5
|
+
export function isJinjaTemplateEquivalentToSpecializedChatWrapper(jinjaTemplateWrapperOptions, specializedChatWrapper, tokenizer) {
|
|
6
|
+
const canTestMultipleConvertSystemMessagesToUserMessages = jinjaTemplateWrapperOptions.convertUnsupportedSystemMessagesToUserMessages == null ||
|
|
7
|
+
jinjaTemplateWrapperOptions.convertUnsupportedSystemMessagesToUserMessages === "auto";
|
|
8
|
+
try {
|
|
9
|
+
const jinjaChatWrapper = new JinjaTemplateChatWrapper({
|
|
10
|
+
...jinjaTemplateWrapperOptions,
|
|
11
|
+
convertUnsupportedSystemMessagesToUserMessages: canTestMultipleConvertSystemMessagesToUserMessages
|
|
12
|
+
? false
|
|
13
|
+
: jinjaTemplateWrapperOptions.convertUnsupportedSystemMessagesToUserMessages,
|
|
14
|
+
trimLeadingWhitespaceInResponses: false
|
|
15
|
+
});
|
|
16
|
+
if (checkEquivalence(jinjaChatWrapper, specializedChatWrapper, testChatHistories, tokenizer))
|
|
17
|
+
return true;
|
|
18
|
+
const jinjaChatWrapperWithLeadingWhitespaceTrimming = new JinjaTemplateChatWrapper({
|
|
19
|
+
...jinjaTemplateWrapperOptions,
|
|
20
|
+
convertUnsupportedSystemMessagesToUserMessages: canTestMultipleConvertSystemMessagesToUserMessages
|
|
21
|
+
? false
|
|
22
|
+
: jinjaTemplateWrapperOptions.convertUnsupportedSystemMessagesToUserMessages,
|
|
23
|
+
trimLeadingWhitespaceInResponses: true
|
|
24
|
+
});
|
|
25
|
+
if (checkEquivalence(jinjaChatWrapperWithLeadingWhitespaceTrimming, specializedChatWrapper, testChatHistories, tokenizer))
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
// Do nothing
|
|
30
|
+
}
|
|
31
|
+
if (!canTestMultipleConvertSystemMessagesToUserMessages)
|
|
32
|
+
return false;
|
|
33
|
+
try {
|
|
34
|
+
const convertSystemMessagesToUserMessagesTemplate = "System: {{message}}";
|
|
35
|
+
const jinjaChatWrapper = new JinjaTemplateChatWrapper({
|
|
36
|
+
...jinjaTemplateWrapperOptions,
|
|
37
|
+
convertUnsupportedSystemMessagesToUserMessages: {
|
|
38
|
+
use: "always",
|
|
39
|
+
format: convertSystemMessagesToUserMessagesTemplate
|
|
40
|
+
},
|
|
41
|
+
trimLeadingWhitespaceInResponses: false
|
|
42
|
+
});
|
|
43
|
+
const transformedTestChatHistories = testChatHistories
|
|
44
|
+
.map((history) => (history
|
|
45
|
+
.slice()
|
|
46
|
+
.map((item, index, array) => {
|
|
47
|
+
if (item.type === "system") {
|
|
48
|
+
if (index === 0 && array.length > 1 && array[1].type === "user") {
|
|
49
|
+
array[1] = {
|
|
50
|
+
type: "user",
|
|
51
|
+
text: convertSystemMessagesToUserMessagesTemplate.replace("{{message}}", item.text) + "\n\n" + array[1].text
|
|
52
|
+
};
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
type: "user",
|
|
57
|
+
text: convertSystemMessagesToUserMessagesTemplate.replace("{{message}}", item.text)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return item;
|
|
61
|
+
})
|
|
62
|
+
.filter((item) => item != null)));
|
|
63
|
+
if (checkEquivalence(jinjaChatWrapper, specializedChatWrapper, transformedTestChatHistories, tokenizer))
|
|
64
|
+
return true;
|
|
65
|
+
const jinjaChatWrapperWithLeadingWhitespaceTrimming = new JinjaTemplateChatWrapper({
|
|
66
|
+
...jinjaTemplateWrapperOptions,
|
|
67
|
+
convertUnsupportedSystemMessagesToUserMessages: {
|
|
68
|
+
use: "always",
|
|
69
|
+
format: convertSystemMessagesToUserMessagesTemplate
|
|
70
|
+
},
|
|
71
|
+
trimLeadingWhitespaceInResponses: true
|
|
72
|
+
});
|
|
73
|
+
if (checkEquivalence(jinjaChatWrapperWithLeadingWhitespaceTrimming, specializedChatWrapper, transformedTestChatHistories, tokenizer))
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
// Do nothing
|
|
78
|
+
}
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
function checkEquivalence(jinjaChatWrapper, specializedChatWrapper, testChatHistories, tokenizer) {
|
|
82
|
+
for (const testChatHistory of testChatHistories) {
|
|
83
|
+
const jinjaRes = jinjaChatWrapper.generateContextText(testChatHistory);
|
|
84
|
+
const specializedWrapperRes = specializedChatWrapper.generateContextText(testChatHistory);
|
|
85
|
+
if (!compareContextTexts(jinjaRes.contextText, specializedWrapperRes.contextText, tokenizer))
|
|
86
|
+
return false;
|
|
87
|
+
const jinjaHasAllSpecializedStopGenerationTriggers = jinjaRes.stopGenerationTriggers
|
|
88
|
+
.every((trigger) => {
|
|
89
|
+
return [trigger, trigger.trimEnd(), trigger.trimStart(), trigger.trimStart().trimEnd()].some((normalizedJinjaTrigger) => {
|
|
90
|
+
if (normalizedJinjaTrigger.values.length === 0)
|
|
91
|
+
return true;
|
|
92
|
+
const foundSimilarTriggers = specializedWrapperRes.stopGenerationTriggers.some((specializedTrigger) => (normalizedJinjaTrigger.includes(specializedTrigger)));
|
|
93
|
+
if (foundSimilarTriggers)
|
|
94
|
+
return true;
|
|
95
|
+
if (tokenizer != null) {
|
|
96
|
+
const resolvedStopGenerationTrigger = StopGenerationDetector.resolveLlamaTextTrigger(normalizedJinjaTrigger, tokenizer);
|
|
97
|
+
const foundSimilarOrShorterTokenizedTriggers = specializedWrapperRes.stopGenerationTriggers
|
|
98
|
+
.some((specializedTrigger) => {
|
|
99
|
+
const resolvedSpecializedTrigger = StopGenerationDetector.resolveLlamaTextTrigger(specializedTrigger, tokenizer);
|
|
100
|
+
return resolvedSpecializedTrigger.every((item, index) => {
|
|
101
|
+
const resolveTriggerItem = resolvedStopGenerationTrigger[index];
|
|
102
|
+
if (typeof item === "string" && typeof resolveTriggerItem === "string")
|
|
103
|
+
return item === resolveTriggerItem;
|
|
104
|
+
else if (typeof item === "string" || typeof resolveTriggerItem === "string")
|
|
105
|
+
return false;
|
|
106
|
+
return compareTokens(item, resolveTriggerItem);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
if (foundSimilarOrShorterTokenizedTriggers)
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
if (!jinjaHasAllSpecializedStopGenerationTriggers)
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
function compareContextTexts(text1, text2, tokenizer) {
|
|
121
|
+
function compare(text1, text2) {
|
|
122
|
+
if (LlamaText.compare(text1, text2))
|
|
123
|
+
return true;
|
|
124
|
+
if (tokenizer != null) {
|
|
125
|
+
const tokenizedText1 = text1.tokenize(tokenizer);
|
|
126
|
+
const tokenizedText2 = text2.tokenize(tokenizer);
|
|
127
|
+
if (tokenizedText1.length === tokenizedText2.length)
|
|
128
|
+
return tokenizedText1.every((token, index) => compareTokens(token, tokenizedText2[index]));
|
|
129
|
+
}
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
const trimmedText1 = text1.trimEnd();
|
|
133
|
+
const trimmedText2 = text2.trimEnd();
|
|
134
|
+
const normalizedText1 = removeLeadingBos(trimmedText1);
|
|
135
|
+
const normalizedText2 = removeLeadingBos(trimmedText2);
|
|
136
|
+
const texts1 = (normalizedText1.length !== trimmedText1.length && tokenizer != null)
|
|
137
|
+
? [trimmedText1, normalizedText1]
|
|
138
|
+
: [normalizedText1];
|
|
139
|
+
const texts2 = (normalizedText2.length !== trimmedText2.length && tokenizer != null)
|
|
140
|
+
? [trimmedText2, normalizedText2]
|
|
141
|
+
: [normalizedText2];
|
|
142
|
+
return texts1.some((text1) => (texts2.some((text2) => (compare(text1, text2)))));
|
|
143
|
+
}
|
|
144
|
+
const testChatHistories = [
|
|
145
|
+
[{
|
|
146
|
+
type: "system",
|
|
147
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
148
|
+
}, {
|
|
149
|
+
type: "user",
|
|
150
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
151
|
+
}, {
|
|
152
|
+
type: "model",
|
|
153
|
+
response: [""]
|
|
154
|
+
}],
|
|
155
|
+
[{
|
|
156
|
+
type: "system",
|
|
157
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
158
|
+
}, {
|
|
159
|
+
type: "user",
|
|
160
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
161
|
+
}, {
|
|
162
|
+
type: "model",
|
|
163
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
164
|
+
}],
|
|
165
|
+
[{
|
|
166
|
+
type: "system",
|
|
167
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
168
|
+
}, {
|
|
169
|
+
type: "user",
|
|
170
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
171
|
+
}, {
|
|
172
|
+
type: "model",
|
|
173
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
174
|
+
}, {
|
|
175
|
+
type: "user",
|
|
176
|
+
text: "Message2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
177
|
+
}, {
|
|
178
|
+
type: "model",
|
|
179
|
+
response: [""]
|
|
180
|
+
}],
|
|
181
|
+
[{
|
|
182
|
+
type: "system",
|
|
183
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
184
|
+
}, {
|
|
185
|
+
type: "user",
|
|
186
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
187
|
+
}, {
|
|
188
|
+
type: "model",
|
|
189
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
190
|
+
}, {
|
|
191
|
+
type: "user",
|
|
192
|
+
text: "Message2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
193
|
+
}, {
|
|
194
|
+
type: "model",
|
|
195
|
+
response: ["Result2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
196
|
+
}]
|
|
197
|
+
];
|
|
198
|
+
function removeLeadingBos(llamaText) {
|
|
199
|
+
if (llamaText.values.length === 0)
|
|
200
|
+
return llamaText;
|
|
201
|
+
const firstValue = llamaText.values[0];
|
|
202
|
+
if (firstValue instanceof SpecialToken && firstValue.value === "BOS")
|
|
203
|
+
return LlamaText(llamaText.values.slice(1));
|
|
204
|
+
return llamaText;
|
|
205
|
+
}
|
|
206
|
+
//# sourceMappingURL=isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isJinjaTemplateEquivalentToSpecializedChatWrapper.js","sourceRoot":"","sources":["../../../src/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,wBAAwB,EAAkC,MAAM,wCAAwC,CAAC;AACjH,OAAO,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAC,sBAAsB,EAAC,MAAM,uCAAuC,CAAC;AAE7E,MAAM,UAAU,iDAAiD,CAC7D,2BAA4D,EAC5D,sBAAmC,EACnC,SAAqB;IAErB,MAAM,kDAAkD,GACpD,2BAA2B,CAAC,8CAA8C,IAAI,IAAI;QAClF,2BAA2B,CAAC,8CAA8C,KAAK,MAAM,CAAC;IAE1F,IAAI;QACA,MAAM,gBAAgB,GAAG,IAAI,w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,EAAE,+BAA+B;SACxC,EAAE;YACC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,sDAAsD;SAC/D,EAAE;YACC,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC,qDAAqD,CAAC;SACpE,EAAE;YACC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,uDAAuD;SAChE,EAAE;YACC,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC,EAAE,CAAC;SACjB,CAAC;IAEF,CAAC;YACG,IAAI,EAAE,QAAQ;YACd,IAAI,EAAE,+BAA+B;SACxC,EAAE;YACC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,sDAAsD;SAC/D,EAAE;YACC,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC,qDAAqD,CAAC;SACpE,EAAE;YACC,IAAI,EAAE,MAAM;YACZ,IAAI,EAAE,uDAAuD;SAChE,EAAE;YACC,IAAI,EAAE,OAAO;YACb,QAAQ,EAAE,CAAC,sDAAsD,CAAC;SACrE,CAAC;CACL,CAAC;AAEF,SAAS,gBAAgB,CAAC,SAAoB;IAC1C,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC;QAC7B,OAAO,SAAS,CAAC;IAErB,MAAM,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEvC,IAAI,UAAU,YAAY,YAAY,IAAI,UAAU,CAAC,KAAK,KAAK,KAAK;QAChE,OAAO,SAAS,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAEhD,OAAO,SAAS,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { LlamaChatWrapper } from "../LlamaChatWrapper.js";
|
|
2
|
+
import { ChatMLChatWrapper } from "../ChatMLChatWrapper.js";
|
|
3
|
+
import { GeneralChatWrapper } from "../GeneralChatWrapper.js";
|
|
4
|
+
import { FalconChatWrapper } from "../FalconChatWrapper.js";
|
|
5
|
+
import { FunctionaryChatWrapper } from "../FunctionaryChatWrapper.js";
|
|
6
|
+
import { AlpacaChatWrapper } from "../AlpacaChatWrapper.js";
|
|
7
|
+
import { GemmaChatWrapper } from "../GemmaChatWrapper.js";
|
|
8
|
+
import { JinjaTemplateChatWrapper } from "../generic/JinjaTemplateChatWrapper.js";
|
|
9
|
+
import { TemplateChatWrapper } from "../generic/TemplateChatWrapper.js";
|
|
10
|
+
import { Tokenizer } from "../../types.js";
|
|
11
|
+
import type { GgufFileInfo } from "../../gguf/types/GgufFileInfoTypes.js";
|
|
12
|
+
export declare const specializedChatWrapperTypeNames: readonly ["general", "llamaChat", "alpacaChat", "functionary", "chatML", "falconChat", "gemma"];
|
|
13
|
+
export type SpecializedChatWrapperTypeName = (typeof specializedChatWrapperTypeNames)[number];
|
|
14
|
+
export declare const templateChatWrapperTypeNames: readonly ["template", "jinjaTemplate"];
|
|
15
|
+
export type TemplateChatWrapperTypeName = (typeof templateChatWrapperTypeNames)[number];
|
|
16
|
+
export declare const resolvableChatWrapperTypeNames: readonly ["auto", "general", "llamaChat", "alpacaChat", "functionary", "chatML", "falconChat", "gemma", "template", "jinjaTemplate"];
|
|
17
|
+
export type ResolvableChatWrapperTypeName = (typeof resolvableChatWrapperTypeNames)[number];
|
|
18
|
+
declare const chatWrappers: {
|
|
19
|
+
readonly general: typeof GeneralChatWrapper;
|
|
20
|
+
readonly llamaChat: typeof LlamaChatWrapper;
|
|
21
|
+
readonly alpacaChat: typeof AlpacaChatWrapper;
|
|
22
|
+
readonly functionary: typeof FunctionaryChatWrapper;
|
|
23
|
+
readonly chatML: typeof ChatMLChatWrapper;
|
|
24
|
+
readonly falconChat: typeof FalconChatWrapper;
|
|
25
|
+
readonly gemma: typeof GemmaChatWrapper;
|
|
26
|
+
readonly template: typeof TemplateChatWrapper;
|
|
27
|
+
readonly jinjaTemplate: typeof JinjaTemplateChatWrapper;
|
|
28
|
+
};
|
|
29
|
+
export type ResolveChatWrapperOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* Resolve to a specific chat wrapper type.
|
|
32
|
+
* You better not set this option unless you need to force a specific chat wrapper type.
|
|
33
|
+
*
|
|
34
|
+
* Defaults to `"auto"`.
|
|
35
|
+
*/
|
|
36
|
+
type?: "auto" | SpecializedChatWrapperTypeName | TemplateChatWrapperTypeName;
|
|
37
|
+
bosString?: string | null;
|
|
38
|
+
filename?: string;
|
|
39
|
+
fileInfo?: GgufFileInfo;
|
|
40
|
+
tokenizer?: Tokenizer;
|
|
41
|
+
customWrapperSettings?: {
|
|
42
|
+
[wrapper in keyof typeof chatWrappers]?: ConstructorParameters<(typeof chatWrappers)[wrapper]>[0];
|
|
43
|
+
};
|
|
44
|
+
warningLogs?: boolean;
|
|
45
|
+
fallbackToOtherWrappersOnJinjaError?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Don't resolve to a Jinja chat wrapper unless `type` is set to a Jinja chat wrapper type.
|
|
48
|
+
*/
|
|
49
|
+
noJinja?: boolean;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Resolve to a chat wrapper instance based on the provided information.
|
|
53
|
+
* The more information provided, the better the resolution will be (except for `type`).
|
|
54
|
+
*
|
|
55
|
+
* It's recommended to not set `type` to a specific chat wrapper in order for the resolution to be more flexible, but it is useful for when
|
|
56
|
+
* you need to provide the ability to force a specific chat wrapper type.
|
|
57
|
+
* Note that when setting `type` to a generic chat wrapper type (such as `"template"` or `"jinjaTemplate"`), the `customWrapperSettings`
|
|
58
|
+
* must contain the necessary settings for that chat wrapper to be created.
|
|
59
|
+
*
|
|
60
|
+
* When loading a Jinja chat template from either `fileInfo` or `customWrapperSettings.jinjaTemplate.template`,
|
|
61
|
+
* if the chat template format is invalid, it fallbacks to resolve other chat wrappers,
|
|
62
|
+
* unless `fallbackToOtherWrappersOnJinjaError` is set to `false` (in which case, it will throw an error).
|
|
63
|
+
*/
|
|
64
|
+
export declare function resolveChatWrapper({ type, bosString, filename, fileInfo, tokenizer, customWrapperSettings, warningLogs, fallbackToOtherWrappersOnJinjaError, noJinja }: ResolveChatWrapperOptions): any;
|
|
65
|
+
export declare function isSpecializedChatWrapperType(type: string): type is SpecializedChatWrapperTypeName;
|
|
66
|
+
export declare function isTemplateChatWrapperType(type: string): type is TemplateChatWrapperTypeName;
|
|
67
|
+
export {};
|