@realtimex/node-llama-cpp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +108 -0
- package/dist/ChatWrapper.d.ts +27 -0
- package/dist/ChatWrapper.js +233 -0
- package/dist/ChatWrapper.js.map +1 -0
- package/dist/apiDocsIndex.d.ts +1 -0
- package/dist/apiDocsIndex.js +7 -0
- package/dist/apiDocsIndex.js.map +1 -0
- package/dist/bindings/AddonTypes.d.ts +203 -0
- package/dist/bindings/AddonTypes.js +2 -0
- package/dist/bindings/AddonTypes.js.map +1 -0
- package/dist/bindings/Llama.d.ts +104 -0
- package/dist/bindings/Llama.js +570 -0
- package/dist/bindings/Llama.js.map +1 -0
- package/dist/bindings/consts.d.ts +2 -0
- package/dist/bindings/consts.js +13 -0
- package/dist/bindings/consts.js.map +1 -0
- package/dist/bindings/getLlama.d.ts +297 -0
- package/dist/bindings/getLlama.js +569 -0
- package/dist/bindings/getLlama.js.map +1 -0
- package/dist/bindings/types.d.ts +72 -0
- package/dist/bindings/types.js +105 -0
- package/dist/bindings/types.js.map +1 -0
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +23 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +50 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
- package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
- package/dist/bindings/utils/NoBinaryFoundError.js.map +1 -0
- package/dist/bindings/utils/asyncEvery.d.ts +5 -0
- package/dist/bindings/utils/asyncEvery.js +15 -0
- package/dist/bindings/utils/asyncEvery.js.map +1 -0
- package/dist/bindings/utils/asyncSome.d.ts +5 -0
- package/dist/bindings/utils/asyncSome.js +29 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/binariesGithubRelease.d.ts +6 -0
- package/dist/bindings/utils/binariesGithubRelease.js +15 -0
- package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js +166 -0
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
- package/dist/bindings/utils/compileLLamaCpp.d.ts +22 -0
- package/dist/bindings/utils/compileLLamaCpp.js +526 -0
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +18 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +311 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectBuildTools.d.ts +14 -0
- package/dist/bindings/utils/detectBuildTools.js +149 -0
- package/dist/bindings/utils/detectBuildTools.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +74 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/disposeBeforeExit.d.ts +8 -0
- package/dist/bindings/utils/disposeBeforeExit.js +36 -0
- package/dist/bindings/utils/disposeBeforeExit.js.map +1 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.d.ts +6 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +105 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
- package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
- package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
- package/dist/bindings/utils/getLlamaGpuTypes.d.ts +13 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js +36 -0
- package/dist/bindings/utils/getLlamaGpuTypes.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +40 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.d.ts +2 -0
- package/dist/bindings/utils/getPlatform.js +15 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -0
- package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
- package/dist/bindings/utils/getPlatformInfo.js +28 -0
- package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
- package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
- package/dist/bindings/utils/hasFileInPath.js +34 -0
- package/dist/bindings/utils/hasFileInPath.js.map +1 -0
- package/dist/bindings/utils/lastBuildInfo.d.ts +6 -0
- package/dist/bindings/utils/lastBuildInfo.js +17 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +22 -0
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
- package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.d.ts +1 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js +18 -0
- package/dist/bindings/utils/resolveActualBindingBinaryPath.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
- package/dist/bindings/utils/testBindingBinary.d.ts +2 -0
- package/dist/bindings/utils/testBindingBinary.js +269 -0
- package/dist/bindings/utils/testBindingBinary.js.map +1 -0
- package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
- package/dist/bindings/utils/testCmakeBinary.js +32 -0
- package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
- package/dist/chatWrappers/AlpacaChatWrapper.d.ts +17 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js +33 -0
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +6 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js +85 -0
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.d.ts +37 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js +294 -0
- package/dist/chatWrappers/DeepSeekChatWrapper.js.map +1 -0
- package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
- package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FalconChatWrapper.d.ts +19 -0
- package/dist/chatWrappers/FalconChatWrapper.js +126 -0
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +17 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js +622 -0
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
- package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
- package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/GeneralChatWrapper.d.ts +19 -0
- package/dist/chatWrappers/GeneralChatWrapper.js +140 -0
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/HarmonyChatWrapper.d.ts +78 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js +539 -0
- package/dist/chatWrappers/HarmonyChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/Llama2ChatWrapper.js +95 -0
- package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +32 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +290 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +264 -0
- package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/MistralChatWrapper.js +180 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/QwenChatWrapper.d.ts +36 -0
- package/dist/chatWrappers/QwenChatWrapper.js +344 -0
- package/dist/chatWrappers/QwenChatWrapper.js.map +1 -0
- package/dist/chatWrappers/SeedChatWrapper.d.ts +25 -0
- package/dist/chatWrappers/SeedChatWrapper.js +183 -0
- package/dist/chatWrappers/SeedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +138 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +665 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +76 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +212 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.d.ts +7 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js +30 -0
- package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +24 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.d.ts +25 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js +690 -0
- package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js +66 -0
- package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js.map +1 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.d.ts +6 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js +19 -0
- package/dist/chatWrappers/generic/utils/getFirstValidResult.js.map +1 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.d.ts +2 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js +35 -0
- package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js.map +1 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.d.ts +22 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js +28 -0
- package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +76 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +177 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
- package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
- package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
- package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
- package/dist/chatWrappers/utils/getModelLinageNames.d.ts +2 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js +18 -0
- package/dist/chatWrappers/utils/getModelLinageNames.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +394 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.d.ts +2 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js +9 -0
- package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js.map +1 -0
- package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
- package/dist/chatWrappers/utils/jsonDumps.js +18 -0
- package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +148 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +325 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.d.ts +2 -0
- package/dist/cli/cli.js +45 -0
- package/dist/cli/cli.js.map +1 -0
- package/dist/cli/commands/ChatCommand.d.ts +59 -0
- package/dist/cli/commands/ChatCommand.js +856 -0
- package/dist/cli/commands/ChatCommand.js.map +1 -0
- package/dist/cli/commands/CompleteCommand.d.ts +47 -0
- package/dist/cli/commands/CompleteCommand.js +658 -0
- package/dist/cli/commands/CompleteCommand.js.map +1 -0
- package/dist/cli/commands/DebugCommand.d.ts +7 -0
- package/dist/cli/commands/DebugCommand.js +55 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +49 -0
- package/dist/cli/commands/InfillCommand.js +693 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +12 -0
- package/dist/cli/commands/InitCommand.js +230 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.d.ts +4 -0
- package/dist/cli/commands/OnPostInstallCommand.js +62 -0
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -0
- package/dist/cli/commands/PullCommand.d.ts +13 -0
- package/dist/cli/commands/PullCommand.js +158 -0
- package/dist/cli/commands/PullCommand.js.map +1 -0
- package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/InspectCommand.js +21 -0
- package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +17 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +275 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +13 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +230 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +296 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +26 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +869 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
- package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
- package/dist/cli/commands/source/SourceCommand.js +19 -0
- package/dist/cli/commands/source/SourceCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
- package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/ClearCommand.d.ts +7 -0
- package/dist/cli/commands/source/commands/ClearCommand.js +54 -0
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/DownloadCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js +219 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
- package/dist/cli/projectTemplates.d.ts +7 -0
- package/dist/cli/projectTemplates.js +10 -0
- package/dist/cli/projectTemplates.js.map +1 -0
- package/dist/cli/recommendedModels.d.ts +2 -0
- package/dist/cli/recommendedModels.js +428 -0
- package/dist/cli/recommendedModels.js.map +1 -0
- package/dist/cli/startCreateCli.d.ts +2 -0
- package/dist/cli/startCreateCli.js +26 -0
- package/dist/cli/startCreateCli.js.map +1 -0
- package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
- package/dist/cli/utils/ConsoleInteraction.js +122 -0
- package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/ConsoleTable.d.ts +24 -0
- package/dist/cli/utils/ConsoleTable.js +90 -0
- package/dist/cli/utils/ConsoleTable.js.map +1 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
- package/dist/cli/utils/consolePromptQuestion.js +81 -0
- package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
- package/dist/cli/utils/getReadablePath.d.ts +1 -0
- package/dist/cli/utils/getReadablePath.js +14 -0
- package/dist/cli/utils/getReadablePath.js.map +1 -0
- package/dist/cli/utils/interactivelyAskForModel.d.ts +13 -0
- package/dist/cli/utils/interactivelyAskForModel.js +485 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.d.ts +1 -0
- package/dist/cli/utils/isRunningUnderRosetta.js +20 -0
- package/dist/cli/utils/isRunningUnderRosetta.js.map +1 -0
- package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
- package/dist/cli/utils/packageJsonConfig.d.ts +6 -0
- package/dist/cli/utils/packageJsonConfig.js +51 -0
- package/dist/cli/utils/packageJsonConfig.js.map +1 -0
- package/dist/cli/utils/packageManager.d.ts +1 -0
- package/dist/cli/utils/packageManager.js +15 -0
- package/dist/cli/utils/packageManager.js.map +1 -0
- package/dist/cli/utils/parseXtcArg.d.ts +5 -0
- package/dist/cli/utils/parseXtcArg.js +16 -0
- package/dist/cli/utils/parseXtcArg.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +12 -0
- package/dist/cli/utils/printCommonInfoLines.js +163 -0
- package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
- package/dist/cli/utils/printInfoLine.d.ts +12 -0
- package/dist/cli/utils/printInfoLine.js +54 -0
- package/dist/cli/utils/printInfoLine.js.map +1 -0
- package/dist/cli/utils/printModelDestination.d.ts +2 -0
- package/dist/cli/utils/printModelDestination.js +11 -0
- package/dist/cli/utils/printModelDestination.js.map +1 -0
- package/dist/cli/utils/projectTemplates.d.ts +19 -0
- package/dist/cli/utils/projectTemplates.js +47 -0
- package/dist/cli/utils/projectTemplates.js.map +1 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +19 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +123 -0
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
- package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
- package/dist/cli/utils/resolveHeaderFlag.js +21 -0
- package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +14 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +12 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/resolveNpmrcConfig.d.ts +18 -0
- package/dist/cli/utils/resolveNpmrcConfig.js +129 -0
- package/dist/cli/utils/resolveNpmrcConfig.js.map +1 -0
- package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
- package/dist/cli/utils/splitAnsiToLines.js +32 -0
- package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
- package/dist/cli/utils/toBytes.d.ts +1 -0
- package/dist/cli/utils/toBytes.js +5 -0
- package/dist/cli/utils/toBytes.js.map +1 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
- package/dist/commands.d.ts +6 -0
- package/dist/commands.js +9 -0
- package/dist/commands.js.map +1 -0
- package/dist/config.d.ts +79 -0
- package/dist/config.js +127 -0
- package/dist/config.js.map +1 -0
- package/dist/consts.d.ts +4 -0
- package/dist/consts.js +11 -0
- package/dist/consts.js.map +1 -0
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +500 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js +2696 -0
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +260 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +520 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +628 -0
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +45 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +191 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +15 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +16 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
- package/dist/evaluator/LlamaCompletion.d.ts +219 -0
- package/dist/evaluator/LlamaCompletion.js +498 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +336 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js +1919 -0
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.d.ts +27 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js +130 -0
- package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +39 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.d.ts +55 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js +20 -0
- package/dist/evaluator/LlamaContext/TokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.d.ts +56 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js +266 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.d.ts +58 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js +138 -0
- package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +602 -0
- package/dist/evaluator/LlamaContext/types.js +2 -0
- package/dist/evaluator/LlamaContext/types.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js +16 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.d.ts +5 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js +42 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.d.ts +1 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js +18 -0
- package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js +13 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
- package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
- package/dist/evaluator/LlamaEmbedding.js +53 -0
- package/dist/evaluator/LlamaEmbedding.js.map +1 -0
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +52 -0
- package/dist/evaluator/LlamaEmbeddingContext.js +86 -0
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
- package/dist/evaluator/LlamaGrammar.d.ts +39 -0
- package/dist/evaluator/LlamaGrammar.js +72 -0
- package/dist/evaluator/LlamaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +19 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js +29 -0
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +17 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +35 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +344 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +853 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
- package/dist/evaluator/LlamaRankingContext.d.ts +91 -0
- package/dist/evaluator/LlamaRankingContext.js +178 -0
- package/dist/evaluator/LlamaRankingContext.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +37 -0
- package/dist/evaluator/TokenBias.js +68 -0
- package/dist/evaluator/TokenBias.js.map +1 -0
- package/dist/evaluator/TokenMeter.d.ts +45 -0
- package/dist/evaluator/TokenMeter.js +74 -0
- package/dist/evaluator/TokenMeter.js.map +1 -0
- package/dist/evaluator/utils/chunkDocument.d.ts +86 -0
- package/dist/evaluator/utils/chunkDocument.js +212 -0
- package/dist/evaluator/utils/chunkDocument.js.map +1 -0
- package/dist/gguf/consts.d.ts +4 -0
- package/dist/gguf/consts.js +12 -0
- package/dist/gguf/consts.js.map +1 -0
- package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
- package/dist/gguf/fileReaders/GgufFileReader.js +106 -0
- package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +28 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +94 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +78 -0
- package/dist/gguf/insights/GgufInsights.js +854 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +203 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +284 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsTokens.d.ts +5 -0
- package/dist/gguf/insights/GgufInsightsTokens.js +40 -0
- package/dist/gguf/insights/GgufInsightsTokens.js.map +1 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.d.ts +5 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js +7 -0
- package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +33 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +117 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +20 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +251 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
- package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
- package/dist/gguf/insights/utils/scoreLevels.js +16 -0
- package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
- package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
- package/dist/gguf/parser/GgufV2Parser.js +184 -0
- package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
- package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
- package/dist/gguf/parser/GgufV3Parser.js +4 -0
- package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
- package/dist/gguf/parser/parseGguf.d.ts +8 -0
- package/dist/gguf/parser/parseGguf.js +61 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -0
- package/dist/gguf/readGgufFileInfo.d.ts +54 -0
- package/dist/gguf/readGgufFileInfo.js +82 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +85 -0
- package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
- package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
- package/dist/gguf/types/GgufMetadataTypes.d.ts +480 -0
- package/dist/gguf/types/GgufMetadataTypes.js +194 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +63 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +54 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
- package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
- package/dist/gguf/utils/GgufReadOffset.js +18 -0
- package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
- package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
- package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
- package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.d.ts +1 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js +27 -0
- package/dist/gguf/utils/getGgufMetadataKeyValue.js.map +1 -0
- package/dist/gguf/utils/ggufQuantNames.d.ts +2 -0
- package/dist/gguf/utils/ggufQuantNames.js +42 -0
- package/dist/gguf/utils/ggufQuantNames.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +2 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +18 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +38 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
- package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js +64 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/state.d.ts +6 -0
- package/dist/state.js +22 -0
- package/dist/state.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +408 -0
- package/dist/types.js +13 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/DisposeGuard.d.ts +13 -0
- package/dist/utils/DisposeGuard.js +120 -0
- package/dist/utils/DisposeGuard.js.map +1 -0
- package/dist/utils/InsufficientMemoryError.d.ts +3 -0
- package/dist/utils/InsufficientMemoryError.js +6 -0
- package/dist/utils/InsufficientMemoryError.js.map +1 -0
- package/dist/utils/LlamaText.d.ts +92 -0
- package/dist/utils/LlamaText.js +527 -0
- package/dist/utils/LlamaText.js.map +1 -0
- package/dist/utils/LruCache.d.ts +12 -0
- package/dist/utils/LruCache.js +44 -0
- package/dist/utils/LruCache.js.map +1 -0
- package/dist/utils/OpenAIFormat.d.ts +177 -0
- package/dist/utils/OpenAIFormat.js +488 -0
- package/dist/utils/OpenAIFormat.js.map +1 -0
- package/dist/utils/OverridesObject.d.ts +7 -0
- package/dist/utils/OverridesObject.js +2 -0
- package/dist/utils/OverridesObject.js.map +1 -0
- package/dist/utils/ReplHistory.d.ts +9 -0
- package/dist/utils/ReplHistory.js +72 -0
- package/dist/utils/ReplHistory.js.map +1 -0
- package/dist/utils/StopGenerationDetector.d.ts +47 -0
- package/dist/utils/StopGenerationDetector.js +291 -0
- package/dist/utils/StopGenerationDetector.js.map +1 -0
- package/dist/utils/ThreadsSplitter.d.ts +32 -0
- package/dist/utils/ThreadsSplitter.js +177 -0
- package/dist/utils/ThreadsSplitter.js.map +1 -0
- package/dist/utils/TokenStreamRegulator.d.ts +38 -0
- package/dist/utils/TokenStreamRegulator.js +200 -0
- package/dist/utils/TokenStreamRegulator.js.map +1 -0
- package/dist/utils/UnsupportedError.d.ts +2 -0
- package/dist/utils/UnsupportedError.js +7 -0
- package/dist/utils/UnsupportedError.js.map +1 -0
- package/dist/utils/appendUserMessageToChatHistory.d.ts +6 -0
- package/dist/utils/appendUserMessageToChatHistory.js +22 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
- package/dist/utils/clearTempFolder.d.ts +1 -0
- package/dist/utils/clearTempFolder.js +16 -0
- package/dist/utils/clearTempFolder.js.map +1 -0
- package/dist/utils/cmake.d.ts +10 -0
- package/dist/utils/cmake.js +146 -0
- package/dist/utils/cmake.js.map +1 -0
- package/dist/utils/compareTokens.d.ts +2 -0
- package/dist/utils/compareTokens.js +4 -0
- package/dist/utils/compareTokens.js.map +1 -0
- package/dist/utils/createModelDownloader.d.ts +262 -0
- package/dist/utils/createModelDownloader.js +486 -0
- package/dist/utils/createModelDownloader.js.map +1 -0
- package/dist/utils/findBestOption.d.ts +4 -0
- package/dist/utils/findBestOption.js +15 -0
- package/dist/utils/findBestOption.js.map +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +20 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +85 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +19 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +60 -0
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -0
- package/dist/utils/gbnfJson/GbnfTerminal.d.ts +11 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js +54 -0
- package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js +53 -0
- package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +18 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +83 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.d.ts +7 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js +17 -0
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.d.ts +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js +90 -0
- package/dist/utils/gbnfJson/terminals/GbnfFormatString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js +23 -0
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js +24 -0
- package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +5 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js +11 -0
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js +22 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +28 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +88 -0
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js +34 -0
- package/dist/utils/gbnfJson/terminals/GbnfRef.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +15 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +86 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +12 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js +43 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.d.ts +8 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js +26 -0
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +13 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +67 -0
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +30 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +72 -0
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -0
- package/dist/utils/gbnfJson/types.d.ts +213 -0
- package/dist/utils/gbnfJson/types.js +30 -0
- package/dist/utils/gbnfJson/types.js.map +1 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
- package/dist/utils/gbnfJson/utils/defsScope.d.ts +7 -0
- package/dist/utils/gbnfJson/utils/defsScope.js +17 -0
- package/dist/utils/gbnfJson/utils/defsScope.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +143 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.d.ts +5 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js +16 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js.map +1 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +8 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +242 -0
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -0
- package/dist/utils/getBuildDefaults.d.ts +5 -0
- package/dist/utils/getBuildDefaults.js +9 -0
- package/dist/utils/getBuildDefaults.js.map +1 -0
- package/dist/utils/getChatWrapperSegmentDefinition.d.ts +2 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js +9 -0
- package/dist/utils/getChatWrapperSegmentDefinition.js.map +1 -0
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
- package/dist/utils/getConsoleLogPrefix.js +10 -0
- package/dist/utils/getConsoleLogPrefix.js.map +1 -0
- package/dist/utils/getFirstWritableDir.d.ts +8 -0
- package/dist/utils/getFirstWritableDir.js +60 -0
- package/dist/utils/getFirstWritableDir.js.map +1 -0
- package/dist/utils/getGrammarsFolder.d.ts +2 -0
- package/dist/utils/getGrammarsFolder.js +19 -0
- package/dist/utils/getGrammarsFolder.js.map +1 -0
- package/dist/utils/getLlamaClasses.d.ts +9 -0
- package/dist/utils/getLlamaClasses.js +14 -0
- package/dist/utils/getLlamaClasses.js.map +1 -0
- package/dist/utils/getModuleVersion.d.ts +1 -0
- package/dist/utils/getModuleVersion.js +13 -0
- package/dist/utils/getModuleVersion.js.map +1 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
- package/dist/utils/getReadableContextSize.d.ts +1 -0
- package/dist/utils/getReadableContextSize.js +7 -0
- package/dist/utils/getReadableContextSize.js.map +1 -0
- package/dist/utils/getTempDir.d.ts +10 -0
- package/dist/utils/getTempDir.js +121 -0
- package/dist/utils/getTempDir.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +205 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gitReleaseBundles.d.ts +2 -0
- package/dist/utils/gitReleaseBundles.js +132 -0
- package/dist/utils/gitReleaseBundles.js.map +1 -0
- package/dist/utils/hashString.d.ts +1 -0
- package/dist/utils/hashString.js +8 -0
- package/dist/utils/hashString.js.map +1 -0
- package/dist/utils/includesText.d.ts +1 -0
- package/dist/utils/includesText.js +12 -0
- package/dist/utils/includesText.js.map +1 -0
- package/dist/utils/isLockfileActive.d.ts +4 -0
- package/dist/utils/isLockfileActive.js +12 -0
- package/dist/utils/isLockfileActive.js.map +1 -0
- package/dist/utils/isToken.d.ts +2 -0
- package/dist/utils/isToken.js +4 -0
- package/dist/utils/isToken.js.map +1 -0
- package/dist/utils/isUrl.d.ts +1 -0
- package/dist/utils/isUrl.js +15 -0
- package/dist/utils/isUrl.js.map +1 -0
- package/dist/utils/mergeUnionTypes.d.ts +10 -0
- package/dist/utils/mergeUnionTypes.js +2 -0
- package/dist/utils/mergeUnionTypes.js.map +1 -0
- package/dist/utils/modelDownloadEndpoints.d.ts +13 -0
- package/dist/utils/modelDownloadEndpoints.js +27 -0
- package/dist/utils/modelDownloadEndpoints.js.map +1 -0
- package/dist/utils/modelFileAccessTokens.d.ts +5 -0
- package/dist/utils/modelFileAccessTokens.js +41 -0
- package/dist/utils/modelFileAccessTokens.js.map +1 -0
- package/dist/utils/optionsMatrix.d.ts +58 -0
- package/dist/utils/optionsMatrix.js +97 -0
- package/dist/utils/optionsMatrix.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +15 -0
- package/dist/utils/parseModelFileName.js +132 -0
- package/dist/utils/parseModelFileName.js.map +1 -0
- package/dist/utils/parseModelUri.d.ts +40 -0
- package/dist/utils/parseModelUri.js +346 -0
- package/dist/utils/parseModelUri.js.map +1 -0
- package/dist/utils/parseTextTemplate.d.ts +66 -0
- package/dist/utils/parseTextTemplate.js +116 -0
- package/dist/utils/parseTextTemplate.js.map +1 -0
- package/dist/utils/prettyPrintObject.d.ts +10 -0
- package/dist/utils/prettyPrintObject.js +84 -0
- package/dist/utils/prettyPrintObject.js.map +1 -0
- package/dist/utils/pushAll.d.ts +6 -0
- package/dist/utils/pushAll.js +11 -0
- package/dist/utils/pushAll.js.map +1 -0
- package/dist/utils/removeNullFields.d.ts +2 -0
- package/dist/utils/removeNullFields.js +17 -0
- package/dist/utils/removeNullFields.js.map +1 -0
- package/dist/utils/resolveGithubRelease.d.ts +2 -0
- package/dist/utils/resolveGithubRelease.js +77 -0
- package/dist/utils/resolveGithubRelease.js.map +1 -0
- package/dist/utils/resolveLastTokens.d.ts +2 -0
- package/dist/utils/resolveLastTokens.js +12 -0
- package/dist/utils/resolveLastTokens.js.map +1 -0
- package/dist/utils/resolveModelDestination.d.ts +16 -0
- package/dist/utils/resolveModelDestination.js +54 -0
- package/dist/utils/resolveModelDestination.js.map +1 -0
- package/dist/utils/resolveModelFile.d.ts +142 -0
- package/dist/utils/resolveModelFile.js +201 -0
- package/dist/utils/resolveModelFile.js.map +1 -0
- package/dist/utils/runtime.d.ts +4 -0
- package/dist/utils/runtime.js +8 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/safeEventCallback.d.ts +6 -0
- package/dist/utils/safeEventCallback.js +29 -0
- package/dist/utils/safeEventCallback.js.map +1 -0
- package/dist/utils/signalSleep.d.ts +1 -0
- package/dist/utils/signalSleep.js +20 -0
- package/dist/utils/signalSleep.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -0
- package/dist/utils/spawnCommand.js +89 -0
- package/dist/utils/spawnCommand.js.map +1 -0
- package/dist/utils/tokenizeInput.d.ts +3 -0
- package/dist/utils/tokenizeInput.js +14 -0
- package/dist/utils/tokenizeInput.js.map +1 -0
- package/dist/utils/tokenizerUtils.d.ts +12 -0
- package/dist/utils/tokenizerUtils.js +32 -0
- package/dist/utils/tokenizerUtils.js.map +1 -0
- package/dist/utils/transformPromisable.d.ts +54 -0
- package/dist/utils/transformPromisable.js +95 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +11 -0
- package/dist/utils/truncateTextAndRoundToWords.js +110 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
- package/dist/utils/utilTypes.d.ts +18 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.d.ts +5 -0
- package/dist/utils/waitForLockfileRelease.js +19 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -0
- package/dist/utils/withLockfile.d.ts +7 -0
- package/dist/utils/withLockfile.js +44 -0
- package/dist/utils/withLockfile.js.map +1 -0
- package/dist/utils/withOra.d.ts +7 -0
- package/dist/utils/withOra.js +37 -0
- package/dist/utils/withOra.js.map +1 -0
- package/dist/utils/withProgressLog.d.ts +22 -0
- package/dist/utils/withProgressLog.js +211 -0
- package/dist/utils/withProgressLog.js.map +1 -0
- package/dist/utils/withStatusLogs.d.ts +6 -0
- package/dist/utils/withStatusLogs.js +25 -0
- package/dist/utils/withStatusLogs.js.map +1 -0
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +14 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/.clang-format +46 -0
- package/llama/CMakeLists.txt +141 -0
- package/llama/addon/AddonContext.cpp +1181 -0
- package/llama/addon/AddonContext.h +85 -0
- package/llama/addon/AddonGrammar.cpp +92 -0
- package/llama/addon/AddonGrammar.h +22 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +36 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +691 -0
- package/llama/addon/AddonModel.h +64 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +103 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +669 -0
- package/llama/addon/AddonSampler.h +75 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +330 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +143 -0
- package/llama/addon/globals/addonLog.h +24 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +146 -0
- package/llama/addon/globals/getGpuInfo.h +11 -0
- package/llama/addon/globals/getMemoryInfo.cpp +63 -0
- package/llama/addon/globals/getMemoryInfo.h +4 -0
- package/llama/addon/globals/getSwapInfo.cpp +69 -0
- package/llama/addon/globals/getSwapInfo.h +4 -0
- package/llama/binariesGithubRelease.json +3 -0
- package/llama/cmake/addVariantSuffix.cmake +21 -0
- package/llama/cmake/win32.ensureNinjaPath.cmake +68 -0
- package/llama/cmake/win32.ensureNodeLib.cmake +34 -0
- package/llama/cmake/win32.llvmApplyGnuModeAdaptations.cmake +12 -0
- package/llama/cmake/win32.llvmEnsureCmakeAr.cmake +37 -0
- package/llama/cmake/win32.llvmUseGnuModeCompilers.cmake +87 -0
- package/llama/cmake/win32.programFilesPaths.cmake +35 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +207 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/package.json +5 -0
- package/llama/profiles/llvm.win32.host-arm64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-arm64.cmake +14 -0
- package/llama/profiles/llvm.win32.host-x64.target-x64.cmake +14 -0
- package/llama/toolchains/darwin.host-x64.target-arm64.cmake +8 -0
- package/llama/toolchains/linux.host-arm64.target-x64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm64.cmake +5 -0
- package/llama/toolchains/linux.host-x64.target-arm71.cmake +5 -0
- package/llama/toolchains/llvm.win32.host-x64.target-x64.cmake +20 -0
- package/llama/toolchains/win32.host-arm64.target-arm64.cmake +21 -0
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +21 -0
- package/llama/xpack/package.json +10 -0
- package/package.json +241 -0
- package/templates/README.md +6 -0
- package/templates/package.json +10 -0
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
|
@@ -0,0 +1,665 @@
|
|
|
1
|
+
import { Template } from "@huggingface/jinja";
|
|
2
|
+
import { splitText } from "lifecycle-utils";
|
|
3
|
+
import { SpecialToken, LlamaText, SpecialTokensText } from "../../utils/LlamaText.js";
|
|
4
|
+
import { ChatWrapper } from "../../ChatWrapper.js";
|
|
5
|
+
import { fromChatHistoryToIntermediateOpenAiMessages, fromIntermediateToCompleteOpenAiMessages } from "../../utils/OpenAIFormat.js";
|
|
6
|
+
import { removeUndefinedFields } from "../../utils/removeNullFields.js";
|
|
7
|
+
import { jsonDumps } from "../utils/jsonDumps.js";
|
|
8
|
+
import { tryMatrix } from "../../utils/optionsMatrix.js";
|
|
9
|
+
import { parseFunctionCallMessageTemplate } from "./utils/chatHistoryFunctionCallMessageTemplate.js";
|
|
10
|
+
import { templateSegmentOptionsToChatWrapperSettings } from "./utils/templateSegmentOptionsToChatWrapperSettings.js";
|
|
11
|
+
import { UniqueIdGenerator } from "./utils/UniqueIdGenerator.js";
|
|
12
|
+
import { detectNeedToWrapFunctionArgumentsWithMap, extractFunctionCallSettingsFromJinjaTemplate } from "./utils/extractFunctionCallSettingsFromJinjaTemplate.js";
|
|
13
|
+
import { squashChatHistoryItems } from "./utils/squashChatHistoryItems.js";
|
|
14
|
+
import { extractSegmentSettingsFromTokenizerAndChatTemplate } from "./utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js";
|
|
15
|
+
const defaultConvertUnsupportedSystemMessagesToUserMessagesFormat = {
|
|
16
|
+
format: "### System message\n\n{{message}}\n\n----"
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A chat wrapper based on a Jinja template.
|
|
20
|
+
* Useful for using the original model's Jinja template as-is without any additional conversion work to chat with a model.
|
|
21
|
+
*
|
|
22
|
+
* If you want to create a new chat wrapper from scratch, using this chat wrapper is not recommended, and instead you better inherit
|
|
23
|
+
* from the `ChatWrapper` class and implement a custom chat wrapper of your own in TypeScript.
|
|
24
|
+
*
|
|
25
|
+
* For a simpler way to create a chat wrapper, see the `TemplateChatWrapper` class.
|
|
26
|
+
* @example
|
|
27
|
+
* <span v-pre>
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* import {JinjaTemplateChatWrapper} from "node-llama-cpp";
|
|
31
|
+
*
|
|
32
|
+
* const chatWrapper = new JinjaTemplateChatWrapper({
|
|
33
|
+
* template: "<Jinja template here>",
|
|
34
|
+
* // functionCallMessageTemplate: { // optional
|
|
35
|
+
* // call: "[[call: {{functionName}}({{functionParams}})]]",
|
|
36
|
+
* // result: " [[result: {{functionCallResult}}]]"
|
|
37
|
+
* // },
|
|
38
|
+
* // segments: {
|
|
39
|
+
* // thoughtTemplate: "<think>{{content}}</think>",
|
|
40
|
+
* // reopenThoughtAfterFunctionCalls: true
|
|
41
|
+
* // }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* </span>
|
|
46
|
+
*/
|
|
47
|
+
export class JinjaTemplateChatWrapper extends ChatWrapper {
|
|
48
|
+
wrapperName = "JinjaTemplate";
|
|
49
|
+
settings;
|
|
50
|
+
template;
|
|
51
|
+
modelRoleName;
|
|
52
|
+
userRoleName;
|
|
53
|
+
systemRoleName;
|
|
54
|
+
convertUnsupportedSystemMessagesToUserMessages;
|
|
55
|
+
joinAdjacentMessagesOfTheSameType;
|
|
56
|
+
trimLeadingWhitespaceInResponses;
|
|
57
|
+
additionalRenderParameters;
|
|
58
|
+
/** @internal */ _jinjaTemplate;
|
|
59
|
+
/** @internal */ _usingJinjaFunctionCallTemplate = false;
|
|
60
|
+
/** @internal */ _stringifyFunctionParams = false;
|
|
61
|
+
/** @internal */ _wrapFunctionParamsInsideMapKey;
|
|
62
|
+
/** @internal */ _stringifyFunctionResult = false;
|
|
63
|
+
/** @internal */ _combineJinjaModelMessageAndToolCalls = true;
|
|
64
|
+
/** @internal */ _endJinjaMessagesWithUserMessage = false;
|
|
65
|
+
/**
|
|
66
|
+
* @param options
|
|
67
|
+
*/
|
|
68
|
+
constructor(options) {
|
|
69
|
+
super();
|
|
70
|
+
const { template, modelRoleName = "assistant", userRoleName = "user", systemRoleName = "system", convertUnsupportedSystemMessagesToUserMessages = defaultConvertUnsupportedSystemMessagesToUserMessagesFormat, functionCallMessageTemplate = "auto", joinAdjacentMessagesOfTheSameType = true, trimLeadingWhitespaceInResponses = true, additionalRenderParameters, segments, tokenizer, _requireFunctionCallSettingsExtraction = false, _functionCallExtractionExamineNonFirst = false } = options;
|
|
71
|
+
if (template == null)
|
|
72
|
+
throw new Error("template cannot be null");
|
|
73
|
+
this.template = template;
|
|
74
|
+
this.modelRoleName = modelRoleName;
|
|
75
|
+
this.userRoleName = userRoleName;
|
|
76
|
+
this.systemRoleName = systemRoleName;
|
|
77
|
+
this.convertUnsupportedSystemMessagesToUserMessages =
|
|
78
|
+
resolveConvertUnsupportedSystemMessagesToUserMessagesOption(convertUnsupportedSystemMessagesToUserMessages);
|
|
79
|
+
this.joinAdjacentMessagesOfTheSameType = joinAdjacentMessagesOfTheSameType;
|
|
80
|
+
this.trimLeadingWhitespaceInResponses = trimLeadingWhitespaceInResponses;
|
|
81
|
+
this.additionalRenderParameters = additionalRenderParameters;
|
|
82
|
+
if (this.convertUnsupportedSystemMessagesToUserMessages != null && !this.convertUnsupportedSystemMessagesToUserMessages.format.includes("{{message}}"))
|
|
83
|
+
throw new Error('convertUnsupportedSystemMessagesToUserMessages format must include "{{message}}"');
|
|
84
|
+
this._jinjaTemplate = new Template(this.template);
|
|
85
|
+
this.settings = {
|
|
86
|
+
...ChatWrapper.defaultSettings,
|
|
87
|
+
segments: templateSegmentOptionsToChatWrapperSettings(segments)
|
|
88
|
+
};
|
|
89
|
+
const { supportsSystemMessages, needsToEndJinjaMessagesWithUserMessage } = this._runSanityTest();
|
|
90
|
+
this.settings = {
|
|
91
|
+
...this.settings,
|
|
92
|
+
supportsSystemMessages,
|
|
93
|
+
segments: {
|
|
94
|
+
...this.settings.segments,
|
|
95
|
+
...extractSegmentSettingsFromTokenizerAndChatTemplate(this.template, tokenizer)
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
if (needsToEndJinjaMessagesWithUserMessage)
|
|
99
|
+
this._endJinjaMessagesWithUserMessage = true;
|
|
100
|
+
let functionCallSettings = parseFunctionCallMessageTemplate((functionCallMessageTemplate === "auto" || functionCallMessageTemplate === "noJinja")
|
|
101
|
+
? undefined
|
|
102
|
+
: functionCallMessageTemplate);
|
|
103
|
+
if (functionCallSettings == null && functionCallMessageTemplate !== "noJinja") {
|
|
104
|
+
try {
|
|
105
|
+
const renderTemplate = ({ chatHistory, functions, additionalParams, stringifyFunctionParams, stringifyFunctionResults, combineModelMessageAndToolCalls, squashModelTextResponses = true }) => {
|
|
106
|
+
const render = (convertSystemMessagesToUserMessagesFormat, wipeFunctionCallIds) => {
|
|
107
|
+
let inputChatHistory = chatHistory;
|
|
108
|
+
if (this._wrapFunctionParamsInsideMapKey != null)
|
|
109
|
+
inputChatHistory = inputChatHistory.map((item) => {
|
|
110
|
+
if (item.type !== "model")
|
|
111
|
+
return item;
|
|
112
|
+
return {
|
|
113
|
+
...item,
|
|
114
|
+
response: item.response.map((response) => {
|
|
115
|
+
if (typeof response === "string" || response.type !== "functionCall")
|
|
116
|
+
return response;
|
|
117
|
+
return {
|
|
118
|
+
...response,
|
|
119
|
+
params: { [this._wrapFunctionParamsInsideMapKey]: response.params }
|
|
120
|
+
};
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
const { messages: intermediateMessages, tools } = fromChatHistoryToIntermediateOpenAiMessages({
|
|
125
|
+
chatHistory: this._transformChatHistory(inputChatHistory, {
|
|
126
|
+
convertSystemMessagesToUserMessagesFormat,
|
|
127
|
+
joinAdjacentMessagesOfTheSameType: !squashModelTextResponses
|
|
128
|
+
? false
|
|
129
|
+
: undefined
|
|
130
|
+
}).transformedHistory,
|
|
131
|
+
chatWrapperSettings: this.settings,
|
|
132
|
+
useRawValues: false,
|
|
133
|
+
functions,
|
|
134
|
+
stringifyFunctionParams,
|
|
135
|
+
stringifyFunctionResults,
|
|
136
|
+
combineModelMessageAndToolCalls,
|
|
137
|
+
squashModelTextResponses
|
|
138
|
+
});
|
|
139
|
+
const messages = fromIntermediateToCompleteOpenAiMessages(intermediateMessages)
|
|
140
|
+
.map((item) => {
|
|
141
|
+
if (!wipeFunctionCallIds)
|
|
142
|
+
return item;
|
|
143
|
+
if (item.role === "assistant" && item["tool_calls"] != null && item["tool_calls"].length > 0) {
|
|
144
|
+
for (const toolCall of item["tool_calls"]) {
|
|
145
|
+
if (wipeFunctionCallIds === "align")
|
|
146
|
+
toolCall.id = "fc_1_0001";
|
|
147
|
+
else
|
|
148
|
+
delete toolCall.id;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
else if (item.role === "tool") {
|
|
152
|
+
if (wipeFunctionCallIds === "align")
|
|
153
|
+
item["tool_call_id"] = "fc_1_0001";
|
|
154
|
+
else
|
|
155
|
+
delete item["tool_call_id"];
|
|
156
|
+
}
|
|
157
|
+
return item;
|
|
158
|
+
});
|
|
159
|
+
const lastJinjaItem = messages.at(-1);
|
|
160
|
+
let eraseRenderedJinjaFromId;
|
|
161
|
+
if (this._endJinjaMessagesWithUserMessage && lastJinjaItem?.role === this.modelRoleName &&
|
|
162
|
+
typeof lastJinjaItem.content === "string" &&
|
|
163
|
+
lastJinjaItem.content.length > 0 &&
|
|
164
|
+
(lastJinjaItem["tool_calls"] == null ||
|
|
165
|
+
lastJinjaItem["tool_calls"]?.length === 0)) {
|
|
166
|
+
eraseRenderedJinjaFromId = lastJinjaItem.content;
|
|
167
|
+
messages.push({
|
|
168
|
+
role: this.userRoleName,
|
|
169
|
+
content: idsGenerator.generateId()
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
let res = this._jinjaTemplate.render({
|
|
173
|
+
...(this.additionalRenderParameters == null
|
|
174
|
+
? {}
|
|
175
|
+
: structuredClone(this.additionalRenderParameters)),
|
|
176
|
+
...additionalParams,
|
|
177
|
+
messages,
|
|
178
|
+
...removeUndefinedFields({ tools })
|
|
179
|
+
});
|
|
180
|
+
if (eraseRenderedJinjaFromId != null) {
|
|
181
|
+
const eraseIndex = res.lastIndexOf(eraseRenderedJinjaFromId);
|
|
182
|
+
if (eraseIndex >= 0)
|
|
183
|
+
res = res.slice(0, eraseIndex + eraseRenderedJinjaFromId.length);
|
|
184
|
+
}
|
|
185
|
+
// attempt to remove the ID pattern from the output
|
|
186
|
+
if (wipeFunctionCallIds === "align")
|
|
187
|
+
res = res
|
|
188
|
+
.replaceAll(/,\s*"(tool_call_id|call_id|id)":\s*"fc_1_0001"/g, "")
|
|
189
|
+
.replaceAll(/"(tool_call_id|call_id|id)":\s*"fc_1_0001"\s*,/g, "");
|
|
190
|
+
return res;
|
|
191
|
+
};
|
|
192
|
+
return tryMatrix({
|
|
193
|
+
convertSystemMessagesToUserMessagesFormat: getConvertUnsupportedSystemMessagesToUserMessagesTryOptions(this.convertUnsupportedSystemMessagesToUserMessages),
|
|
194
|
+
wipeFunctionCallIds: [true, "align", false]
|
|
195
|
+
}, ({ convertSystemMessagesToUserMessagesFormat, wipeFunctionCallIds }) => {
|
|
196
|
+
return render(convertSystemMessagesToUserMessagesFormat, wipeFunctionCallIds);
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
const idsGenerator = new UniqueIdGenerator(this.template + this.modelRoleName + this.userRoleName + this.systemRoleName +
|
|
200
|
+
(this.convertUnsupportedSystemMessagesToUserMessages?.format ?? ""));
|
|
201
|
+
this._wrapFunctionParamsInsideMapKey = detectNeedToWrapFunctionArgumentsWithMap({ idsGenerator, renderTemplate });
|
|
202
|
+
const extractedSettings = extractFunctionCallSettingsFromJinjaTemplate({
|
|
203
|
+
idsGenerator,
|
|
204
|
+
renderTemplate,
|
|
205
|
+
examineNonFirstFunctionCall: _functionCallExtractionExamineNonFirst
|
|
206
|
+
});
|
|
207
|
+
functionCallSettings = extractedSettings.settings;
|
|
208
|
+
if (functionCallSettings != null) {
|
|
209
|
+
this._usingJinjaFunctionCallTemplate = true;
|
|
210
|
+
this._stringifyFunctionParams = extractedSettings.stringifyParams;
|
|
211
|
+
this._stringifyFunctionResult = extractedSettings.stringifyResult;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
catch (err) {
|
|
215
|
+
// do nothing
|
|
216
|
+
}
|
|
217
|
+
if (functionCallSettings == null && _requireFunctionCallSettingsExtraction)
|
|
218
|
+
throw new Error("failed to extract function call settings from the Jinja template");
|
|
219
|
+
}
|
|
220
|
+
this.settings = {
|
|
221
|
+
...this.settings,
|
|
222
|
+
functions: functionCallSettings ?? ChatWrapper.defaultSettings.functions
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Whether the function call syntax settings were extracted from the given Jinja template.
|
|
227
|
+
*
|
|
228
|
+
* The function call syntax settings can be accessed using the `.settings.functions` property.
|
|
229
|
+
*/
|
|
230
|
+
get usingJinjaFunctionCallTemplate() {
|
|
231
|
+
return this._usingJinjaFunctionCallTemplate;
|
|
232
|
+
}
|
|
233
|
+
generateContextState({ chatHistory, availableFunctions, documentFunctionParams }) {
|
|
234
|
+
const { contextText, stopGenerationTriggers, ignoreStartText, functionCall, transformedSystemMessagesToUserMessages } = this._generateContextState({
|
|
235
|
+
chatHistory, availableFunctions, documentFunctionParams,
|
|
236
|
+
endJinjaMessagesWithUserMessage: this._endJinjaMessagesWithUserMessage
|
|
237
|
+
});
|
|
238
|
+
return { contextText, stopGenerationTriggers, ignoreStartText, functionCall, transformedSystemMessagesToUserMessages };
|
|
239
|
+
}
|
|
240
|
+
addAvailableFunctionsSystemMessageToHistory(history, availableFunctions, options = {}) {
|
|
241
|
+
if (this._usingJinjaFunctionCallTemplate)
|
|
242
|
+
return history;
|
|
243
|
+
return super.addAvailableFunctionsSystemMessageToHistory(history, availableFunctions, options);
|
|
244
|
+
}
|
|
245
|
+
generateFunctionCall(name, params) {
|
|
246
|
+
if (!this._stringifyFunctionParams)
|
|
247
|
+
return super.generateFunctionCall(name, params);
|
|
248
|
+
const emptyCallParamsPlaceholder = this.settings.functions.call.emptyCallParamsPlaceholder;
|
|
249
|
+
return LlamaText([
|
|
250
|
+
this.settings.functions.call.prefix,
|
|
251
|
+
name,
|
|
252
|
+
this.settings.functions.call.paramsPrefix,
|
|
253
|
+
(params === undefined
|
|
254
|
+
? (emptyCallParamsPlaceholder === undefined || emptyCallParamsPlaceholder === "")
|
|
255
|
+
? ""
|
|
256
|
+
: JSON.stringify(jsonDumps(emptyCallParamsPlaceholder))
|
|
257
|
+
: JSON.stringify(jsonDumps(params))),
|
|
258
|
+
this.settings.functions.call.suffix
|
|
259
|
+
]);
|
|
260
|
+
}
|
|
261
|
+
generateFunctionCallResult(functionName, functionParams, result) {
|
|
262
|
+
const resolveParameters = (text) => {
|
|
263
|
+
return LlamaText(text)
|
|
264
|
+
.mapValues((value) => {
|
|
265
|
+
if (typeof value !== "string")
|
|
266
|
+
return value;
|
|
267
|
+
const funcParamsText = functionParams === undefined
|
|
268
|
+
? ""
|
|
269
|
+
: jsonDumps(functionParams);
|
|
270
|
+
return value
|
|
271
|
+
.replaceAll("{{functionName}}", functionName)
|
|
272
|
+
.replaceAll("{{functionParams}}", (this._stringifyFunctionParams && funcParamsText !== "")
|
|
273
|
+
? JSON.stringify(funcParamsText)
|
|
274
|
+
: funcParamsText);
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
const resultText = result === undefined
|
|
278
|
+
? "void"
|
|
279
|
+
: jsonDumps(result);
|
|
280
|
+
return LlamaText([
|
|
281
|
+
resolveParameters(this.settings.functions.result.prefix),
|
|
282
|
+
((this._stringifyFunctionResult && result !== undefined)
|
|
283
|
+
? JSON.stringify(resultText)
|
|
284
|
+
: resultText),
|
|
285
|
+
resolveParameters(this.settings.functions.result.suffix)
|
|
286
|
+
]);
|
|
287
|
+
}
|
|
288
|
+
/** @internal */
|
|
289
|
+
_generateContextState({ chatHistory, availableFunctions, documentFunctionParams, endJinjaMessagesWithUserMessage }) {
|
|
290
|
+
return tryMatrix({
|
|
291
|
+
convertSystemMessagesToUserMessagesFormat: getConvertUnsupportedSystemMessagesToUserMessagesTryOptions(this.convertUnsupportedSystemMessagesToUserMessages),
|
|
292
|
+
endJinjaMessagesWithUserMessage: endJinjaMessagesWithUserMessage == null
|
|
293
|
+
? [false, true]
|
|
294
|
+
: [endJinjaMessagesWithUserMessage],
|
|
295
|
+
useMessagesWithEmbeddedTools: this._usingJinjaFunctionCallTemplate
|
|
296
|
+
? [undefined, true]
|
|
297
|
+
: [undefined]
|
|
298
|
+
}, ({ useMessagesWithEmbeddedTools, endJinjaMessagesWithUserMessage, convertSystemMessagesToUserMessagesFormat }) => {
|
|
299
|
+
return this._generateContextText(chatHistory, {
|
|
300
|
+
convertSystemMessagesToUserMessagesFormat, availableFunctions, documentFunctionParams,
|
|
301
|
+
endJinjaMessagesWithUserMessage,
|
|
302
|
+
useMessagesWithEmbeddedTools
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/** @internal */
|
|
307
|
+
_transformChatHistory(history, { convertSystemMessagesToUserMessagesFormat, availableFunctions, documentFunctionParams = true, joinAdjacentMessagesOfTheSameType = this.joinAdjacentMessagesOfTheSameType }) {
|
|
308
|
+
const historyWithFunctions = this.addAvailableFunctionsSystemMessageToHistory(history, availableFunctions, {
|
|
309
|
+
documentParams: documentFunctionParams
|
|
310
|
+
});
|
|
311
|
+
let transformedSystemMessagesToUserMessages = false;
|
|
312
|
+
const transformedHistory = convertSystemMessagesToUserMessagesFormat == null
|
|
313
|
+
? historyWithFunctions
|
|
314
|
+
: historyWithFunctions.map((item) => {
|
|
315
|
+
if (item.type === "system") {
|
|
316
|
+
transformedSystemMessagesToUserMessages = true;
|
|
317
|
+
return {
|
|
318
|
+
type: "user",
|
|
319
|
+
text: LlamaText.joinValues(LlamaText.fromJSON(item.text), convertSystemMessagesToUserMessagesFormat.split("{{message}}")).toString()
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
return item;
|
|
323
|
+
});
|
|
324
|
+
return {
|
|
325
|
+
transformedHistory: joinAdjacentMessagesOfTheSameType
|
|
326
|
+
? squashChatHistoryItems(transformedHistory)
|
|
327
|
+
: transformedHistory,
|
|
328
|
+
transformedSystemMessagesToUserMessages
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/** @internal */
|
|
332
|
+
_generateContextText(history, { convertSystemMessagesToUserMessagesFormat, availableFunctions, documentFunctionParams = true, endJinjaMessagesWithUserMessage, useMessagesWithEmbeddedTools = false }) {
|
|
333
|
+
const { transformedSystemMessagesToUserMessages, transformedHistory } = this._transformChatHistory(history, { convertSystemMessagesToUserMessagesFormat, availableFunctions, documentFunctionParams });
|
|
334
|
+
const generateMessagesWithEmbeddedTools = (chatHistory) => ({
|
|
335
|
+
messages: chatHistory.map((item) => {
|
|
336
|
+
if (item.type === "system")
|
|
337
|
+
return {
|
|
338
|
+
role: "system",
|
|
339
|
+
content: LlamaText.fromJSON(item.text)
|
|
340
|
+
};
|
|
341
|
+
else if (item.type === "user")
|
|
342
|
+
return {
|
|
343
|
+
role: "user",
|
|
344
|
+
content: LlamaText(item.text)
|
|
345
|
+
};
|
|
346
|
+
else if (item.type === "model")
|
|
347
|
+
return {
|
|
348
|
+
role: "assistant",
|
|
349
|
+
content: this.generateModelResponseText(item.response)
|
|
350
|
+
};
|
|
351
|
+
void item;
|
|
352
|
+
return { role: "user", content: LlamaText("") };
|
|
353
|
+
}),
|
|
354
|
+
tools: undefined
|
|
355
|
+
});
|
|
356
|
+
const generateMessagesWithTools = (chatHistory) => {
|
|
357
|
+
if (this._wrapFunctionParamsInsideMapKey != null)
|
|
358
|
+
chatHistory = chatHistory.map((item) => {
|
|
359
|
+
if (item.type !== "model")
|
|
360
|
+
return item;
|
|
361
|
+
return {
|
|
362
|
+
...item,
|
|
363
|
+
response: item.response.map((response) => {
|
|
364
|
+
if (typeof response === "string" || response.type !== "functionCall")
|
|
365
|
+
return response;
|
|
366
|
+
return {
|
|
367
|
+
...response,
|
|
368
|
+
params: { [this._wrapFunctionParamsInsideMapKey]: response.params }
|
|
369
|
+
};
|
|
370
|
+
})
|
|
371
|
+
};
|
|
372
|
+
});
|
|
373
|
+
return fromChatHistoryToIntermediateOpenAiMessages({
|
|
374
|
+
chatHistory,
|
|
375
|
+
chatWrapperSettings: this.settings,
|
|
376
|
+
useRawValues: false,
|
|
377
|
+
functions: (availableFunctions != null && !documentFunctionParams)
|
|
378
|
+
? Object.fromEntries(Object.entries(availableFunctions)
|
|
379
|
+
.map(([funcName, { description, ...func }]) => [funcName, func]))
|
|
380
|
+
: availableFunctions,
|
|
381
|
+
stringifyFunctionParams: this._stringifyFunctionParams,
|
|
382
|
+
stringifyFunctionResults: this._stringifyFunctionResult,
|
|
383
|
+
combineModelMessageAndToolCalls: this._combineJinjaModelMessageAndToolCalls
|
|
384
|
+
});
|
|
385
|
+
};
|
|
386
|
+
const lastItemIsModelMessage = transformedHistory.at(-1)?.type === "model";
|
|
387
|
+
const { messages: intermediateMessages, tools } = this._usingJinjaFunctionCallTemplate
|
|
388
|
+
? useMessagesWithEmbeddedTools
|
|
389
|
+
? {
|
|
390
|
+
messages: generateMessagesWithEmbeddedTools(transformedHistory).messages,
|
|
391
|
+
tools: generateMessagesWithTools(transformedHistory).tools
|
|
392
|
+
}
|
|
393
|
+
: generateMessagesWithTools(transformedHistory)
|
|
394
|
+
: generateMessagesWithEmbeddedTools(transformedHistory);
|
|
395
|
+
const idsGenerator = new UniqueIdGenerator(this.template + this.modelRoleName + this.userRoleName + this.systemRoleName +
|
|
396
|
+
(convertSystemMessagesToUserMessagesFormat ?? "") +
|
|
397
|
+
intermediateMessages.map(({ content }) => (content?.toString() ?? "")).join("\n\n"));
|
|
398
|
+
const jinjaItems = [];
|
|
399
|
+
const jinjaRoleMap = {
|
|
400
|
+
system: this.systemRoleName,
|
|
401
|
+
user: this.userRoleName,
|
|
402
|
+
assistant: this.modelRoleName,
|
|
403
|
+
tool: "tool"
|
|
404
|
+
};
|
|
405
|
+
const idToContent = new Map();
|
|
406
|
+
const modelMessageIds = new Set();
|
|
407
|
+
const messageIds = new Set();
|
|
408
|
+
for (const intermediateMessage of intermediateMessages) {
|
|
409
|
+
if (intermediateMessage.content == null) {
|
|
410
|
+
jinjaItems.push({
|
|
411
|
+
...intermediateMessage,
|
|
412
|
+
role: jinjaRoleMap[intermediateMessage.role] ?? intermediateMessage.role
|
|
413
|
+
});
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
const id = idsGenerator.generateId(intermediateMessage.role === "tool");
|
|
417
|
+
messageIds.add(id);
|
|
418
|
+
idToContent.set(id, LlamaText(intermediateMessage.content));
|
|
419
|
+
jinjaItems.push({
|
|
420
|
+
...intermediateMessage,
|
|
421
|
+
role: jinjaRoleMap[intermediateMessage.role] ?? intermediateMessage.role,
|
|
422
|
+
content: id
|
|
423
|
+
});
|
|
424
|
+
if (intermediateMessage.role === "assistant" || intermediateMessage.role === "tool")
|
|
425
|
+
modelMessageIds.add(id);
|
|
426
|
+
}
|
|
427
|
+
const bosTokenId = idsGenerator.generateId();
|
|
428
|
+
const eosTokenId = idsGenerator.generateId();
|
|
429
|
+
const eotTokenId = idsGenerator.generateId();
|
|
430
|
+
idToContent.set(bosTokenId, new SpecialToken("BOS"));
|
|
431
|
+
idToContent.set(eosTokenId, new SpecialToken("EOS"));
|
|
432
|
+
idToContent.set(eotTokenId, new SpecialToken("EOT"));
|
|
433
|
+
const lastJinjaItem = jinjaItems.at(-1);
|
|
434
|
+
let eraseRenderedJinjaFromId;
|
|
435
|
+
if (endJinjaMessagesWithUserMessage && lastJinjaItem?.role === this.modelRoleName &&
|
|
436
|
+
typeof lastJinjaItem.content === "string" &&
|
|
437
|
+
lastJinjaItem.content.length > 0 &&
|
|
438
|
+
(lastJinjaItem["tool_calls"] == null ||
|
|
439
|
+
lastJinjaItem["tool_calls"]?.length === 0)) {
|
|
440
|
+
eraseRenderedJinjaFromId = lastJinjaItem.content;
|
|
441
|
+
jinjaItems.push({
|
|
442
|
+
role: this.userRoleName,
|
|
443
|
+
content: idsGenerator.generateId()
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
const renderJinjaText = () => {
|
|
447
|
+
let res = tryMatrix({
|
|
448
|
+
options: [{}, { "add_generation_prompt": true }]
|
|
449
|
+
}, ({ options }) => (this._jinjaTemplate.render({
|
|
450
|
+
...(this.additionalRenderParameters == null
|
|
451
|
+
? {}
|
|
452
|
+
: structuredClone(this.additionalRenderParameters)),
|
|
453
|
+
messages: jinjaItems,
|
|
454
|
+
...removeUndefinedFields({ tools }),
|
|
455
|
+
"bos_token": bosTokenId,
|
|
456
|
+
"eos_token": eosTokenId,
|
|
457
|
+
"eot_token": eotTokenId,
|
|
458
|
+
...options
|
|
459
|
+
})));
|
|
460
|
+
if (eraseRenderedJinjaFromId != null) {
|
|
461
|
+
const eraseIndex = res.lastIndexOf(eraseRenderedJinjaFromId);
|
|
462
|
+
if (eraseIndex >= 0)
|
|
463
|
+
res = res.slice(0, eraseIndex + eraseRenderedJinjaFromId.length);
|
|
464
|
+
}
|
|
465
|
+
return res;
|
|
466
|
+
};
|
|
467
|
+
const validateThatAllMessageIdsAreUsed = (parts) => {
|
|
468
|
+
const messageIdsLeft = new Set(messageIds);
|
|
469
|
+
for (const part of parts) {
|
|
470
|
+
if (typeof part === "string")
|
|
471
|
+
continue;
|
|
472
|
+
messageIdsLeft.delete(part.separator);
|
|
473
|
+
}
|
|
474
|
+
if (messageIdsLeft.size !== 0)
|
|
475
|
+
throw new Error("Some input messages are not present in the generated Jinja template output");
|
|
476
|
+
};
|
|
477
|
+
const renderJinjaAndSplitIntoParts = () => {
|
|
478
|
+
const splitJinjaParts = splitText(renderJinjaText(), [...idToContent.keys()]);
|
|
479
|
+
if (lastItemIsModelMessage) {
|
|
480
|
+
let lastModelResponseIndex = -1;
|
|
481
|
+
for (let i = splitJinjaParts.length - 1; i >= 0; i--) {
|
|
482
|
+
const part = splitJinjaParts[i];
|
|
483
|
+
if (part == null || typeof part === "string")
|
|
484
|
+
continue;
|
|
485
|
+
if (modelMessageIds.has(part.separator)) {
|
|
486
|
+
lastModelResponseIndex = i;
|
|
487
|
+
break;
|
|
488
|
+
}
|
|
489
|
+
else if (messageIds.has(part.separator)) {
|
|
490
|
+
validateThatAllMessageIdsAreUsed(splitJinjaParts);
|
|
491
|
+
throw new Error("Last message was expected to be a model message, but it was not");
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
if (lastModelResponseIndex < 0) {
|
|
495
|
+
validateThatAllMessageIdsAreUsed(splitJinjaParts);
|
|
496
|
+
throw new Error("A model message was expected to be the last message, but it was not found");
|
|
497
|
+
}
|
|
498
|
+
return {
|
|
499
|
+
splitJinjaParts: splitJinjaParts.slice(0, lastModelResponseIndex + 1),
|
|
500
|
+
stopGenerationJinjaParts: splitJinjaParts.slice(lastModelResponseIndex + 1)
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
return {
|
|
504
|
+
splitJinjaParts,
|
|
505
|
+
stopGenerationJinjaParts: []
|
|
506
|
+
};
|
|
507
|
+
};
|
|
508
|
+
const { splitJinjaParts, stopGenerationJinjaParts } = renderJinjaAndSplitIntoParts();
|
|
509
|
+
const messageIdsLeftToProcess = new Set(messageIds);
|
|
510
|
+
const contextText = LlamaText(splitJinjaParts.map((part) => {
|
|
511
|
+
if (typeof part === "string")
|
|
512
|
+
return new SpecialTokensText(part); // things that are not message content can be tokenized with special tokens
|
|
513
|
+
const message = idToContent.get(part.separator);
|
|
514
|
+
if (message == null)
|
|
515
|
+
throw new Error(`Message with id "${part.separator}" not found`);
|
|
516
|
+
messageIdsLeftToProcess.delete(part.separator);
|
|
517
|
+
return message;
|
|
518
|
+
}));
|
|
519
|
+
if (messageIdsLeftToProcess.size !== 0)
|
|
520
|
+
throw new Error("Some input messages are not present in the generated Jinja template output");
|
|
521
|
+
return {
|
|
522
|
+
contextText,
|
|
523
|
+
ignoreStartText: !this.trimLeadingWhitespaceInResponses
|
|
524
|
+
? []
|
|
525
|
+
: [
|
|
526
|
+
// ignore up to 4 leading spaces
|
|
527
|
+
...Array(4).fill(0)
|
|
528
|
+
.map((_, index) => LlamaText(" ".repeat(index + 1))),
|
|
529
|
+
LlamaText("\t"),
|
|
530
|
+
LlamaText("\t\t"),
|
|
531
|
+
LlamaText("\t "),
|
|
532
|
+
LlamaText(" \t")
|
|
533
|
+
],
|
|
534
|
+
stopGenerationTriggers: [
|
|
535
|
+
LlamaText(new SpecialToken("EOS")),
|
|
536
|
+
...(stopGenerationJinjaParts.length === 0
|
|
537
|
+
? []
|
|
538
|
+
: [
|
|
539
|
+
LlamaText(stopGenerationJinjaParts.map((part) => {
|
|
540
|
+
if (typeof part === "string")
|
|
541
|
+
return new SpecialTokensText(part);
|
|
542
|
+
const message = idToContent.get(part.separator);
|
|
543
|
+
if (message == null)
|
|
544
|
+
throw new Error(`Message with id "${part.separator}" not found`);
|
|
545
|
+
return message;
|
|
546
|
+
}))
|
|
547
|
+
])
|
|
548
|
+
],
|
|
549
|
+
transformedSystemMessagesToUserMessages,
|
|
550
|
+
endJinjaMessagesWithUserMessage
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Validate that this Jinja template can be rendered
|
|
555
|
+
* @internal
|
|
556
|
+
*/
|
|
557
|
+
_runSanityTest(needsToEndJinjaMessagesWithUserMessage = false) {
|
|
558
|
+
try {
|
|
559
|
+
let supportsSystemMessages = true;
|
|
560
|
+
for (const chatHistory of chatHistoriesForSanityTest) {
|
|
561
|
+
const { transformedSystemMessagesToUserMessages, endJinjaMessagesWithUserMessage: endedJinjaMessagesWithUserMessage } = this._generateContextState({
|
|
562
|
+
chatHistory,
|
|
563
|
+
endJinjaMessagesWithUserMessage: needsToEndJinjaMessagesWithUserMessage
|
|
564
|
+
? true
|
|
565
|
+
: undefined
|
|
566
|
+
});
|
|
567
|
+
if (transformedSystemMessagesToUserMessages)
|
|
568
|
+
supportsSystemMessages = false;
|
|
569
|
+
if (!needsToEndJinjaMessagesWithUserMessage && endedJinjaMessagesWithUserMessage) {
|
|
570
|
+
if (chatHistory !== chatHistoriesForSanityTest[0])
|
|
571
|
+
// validate tha this doesn't break the template
|
|
572
|
+
return this._runSanityTest(true);
|
|
573
|
+
else
|
|
574
|
+
needsToEndJinjaMessagesWithUserMessage = true;
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
return { supportsSystemMessages, needsToEndJinjaMessagesWithUserMessage };
|
|
578
|
+
}
|
|
579
|
+
catch (err) {
|
|
580
|
+
throw new Error("The provided Jinja template failed the sanity test: " + String(err) + ". Inspect the Jinja template to find out what went wrong");
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
function resolveConvertUnsupportedSystemMessagesToUserMessagesOption(convertUnsupportedSystemMessagesToUserMessages) {
|
|
585
|
+
if (convertUnsupportedSystemMessagesToUserMessages === false)
|
|
586
|
+
return undefined;
|
|
587
|
+
if (convertUnsupportedSystemMessagesToUserMessages === true)
|
|
588
|
+
return {
|
|
589
|
+
...defaultConvertUnsupportedSystemMessagesToUserMessagesFormat,
|
|
590
|
+
use: "always"
|
|
591
|
+
};
|
|
592
|
+
if (convertUnsupportedSystemMessagesToUserMessages === "auto")
|
|
593
|
+
return {
|
|
594
|
+
...defaultConvertUnsupportedSystemMessagesToUserMessagesFormat,
|
|
595
|
+
use: "ifNeeded"
|
|
596
|
+
};
|
|
597
|
+
if (typeof convertUnsupportedSystemMessagesToUserMessages === "object")
|
|
598
|
+
return {
|
|
599
|
+
...convertUnsupportedSystemMessagesToUserMessages,
|
|
600
|
+
use: convertUnsupportedSystemMessagesToUserMessages.use ?? "ifNeeded"
|
|
601
|
+
};
|
|
602
|
+
return { ...defaultConvertUnsupportedSystemMessagesToUserMessagesFormat, use: "ifNeeded" };
|
|
603
|
+
}
|
|
604
|
+
function getConvertUnsupportedSystemMessagesToUserMessagesTryOptions(convertUnsupportedSystemMessagesToUserMessages) {
|
|
605
|
+
if (convertUnsupportedSystemMessagesToUserMessages == null)
|
|
606
|
+
return [undefined];
|
|
607
|
+
else if (convertUnsupportedSystemMessagesToUserMessages.use === "always")
|
|
608
|
+
return [convertUnsupportedSystemMessagesToUserMessages.format];
|
|
609
|
+
return [undefined, convertUnsupportedSystemMessagesToUserMessages.format];
|
|
610
|
+
}
|
|
611
|
+
const chatHistoriesForSanityTest = [
|
|
612
|
+
[{
|
|
613
|
+
type: "system",
|
|
614
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
615
|
+
}, {
|
|
616
|
+
type: "user",
|
|
617
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
618
|
+
}, {
|
|
619
|
+
type: "model",
|
|
620
|
+
response: [""]
|
|
621
|
+
}],
|
|
622
|
+
[{
|
|
623
|
+
type: "system",
|
|
624
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
625
|
+
}, {
|
|
626
|
+
type: "user",
|
|
627
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
628
|
+
}, {
|
|
629
|
+
type: "model",
|
|
630
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
631
|
+
}],
|
|
632
|
+
[{
|
|
633
|
+
type: "system",
|
|
634
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
635
|
+
}, {
|
|
636
|
+
type: "user",
|
|
637
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
638
|
+
}, {
|
|
639
|
+
type: "model",
|
|
640
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
641
|
+
}, {
|
|
642
|
+
type: "user",
|
|
643
|
+
text: "Message2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
644
|
+
}, {
|
|
645
|
+
type: "model",
|
|
646
|
+
response: [""]
|
|
647
|
+
}],
|
|
648
|
+
[{
|
|
649
|
+
type: "system",
|
|
650
|
+
text: "System message ~!@#$%^&*()\n*"
|
|
651
|
+
}, {
|
|
652
|
+
type: "user",
|
|
653
|
+
text: "Message 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
654
|
+
}, {
|
|
655
|
+
type: "model",
|
|
656
|
+
response: ["Result 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
657
|
+
}, {
|
|
658
|
+
type: "user",
|
|
659
|
+
text: "Message2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"
|
|
660
|
+
}, {
|
|
661
|
+
type: "model",
|
|
662
|
+
response: ["Result2 1234567890!@#$%^&*()_+-=[]{}|\\:;\"',./<>?`~"]
|
|
663
|
+
}]
|
|
664
|
+
];
|
|
665
|
+
//# sourceMappingURL=JinjaTemplateChatWrapper.js.map
|