node-llama-cpp 3.0.0-beta.9 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -27
- package/bins/_linux-arm64.moved.txt +1 -0
- package/bins/_linux-armv7l.moved.txt +1 -0
- package/bins/_linux-x64-cuda.moved.txt +1 -0
- package/bins/_linux-x64-vulkan.moved.txt +1 -0
- package/bins/_linux-x64.moved.txt +1 -0
- package/bins/_mac-arm64-metal.moved.txt +1 -0
- package/bins/_mac-x64.moved.txt +1 -0
- package/bins/_win-arm64.moved.txt +1 -0
- package/bins/_win-x64-cuda.moved.txt +1 -0
- package/bins/_win-x64-vulkan.moved.txt +1 -0
- package/bins/_win-x64.moved.txt +1 -0
- package/dist/ChatWrapper.d.ts +19 -39
- package/dist/ChatWrapper.js +129 -72
- package/dist/ChatWrapper.js.map +1 -1
- package/dist/apiDocsIndex.d.ts +1 -0
- package/dist/apiDocsIndex.js +7 -0
- package/dist/apiDocsIndex.js.map +1 -0
- package/dist/bindings/AddonTypes.d.ts +88 -20
- package/dist/bindings/Llama.d.ts +43 -3
- package/dist/bindings/Llama.js +193 -23
- package/dist/bindings/Llama.js.map +1 -1
- package/dist/bindings/consts.d.ts +2 -0
- package/dist/bindings/consts.js +13 -0
- package/dist/bindings/consts.js.map +1 -0
- package/dist/bindings/getLlama.d.ts +123 -18
- package/dist/bindings/getLlama.js +264 -75
- package/dist/bindings/getLlama.js.map +1 -1
- package/dist/bindings/types.d.ts +29 -5
- package/dist/bindings/types.js +51 -2
- package/dist/bindings/types.js.map +1 -1
- package/dist/bindings/utils/MemoryOrchestrator.d.ts +21 -0
- package/dist/bindings/utils/MemoryOrchestrator.js +49 -0
- package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
- package/dist/bindings/utils/asyncEvery.d.ts +5 -0
- package/dist/bindings/utils/asyncEvery.js +15 -0
- package/dist/bindings/utils/asyncEvery.js.map +1 -0
- package/dist/bindings/utils/asyncSome.d.ts +5 -0
- package/dist/bindings/utils/asyncSome.js +27 -0
- package/dist/bindings/utils/asyncSome.js.map +1 -0
- package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +1 -1
- package/dist/bindings/utils/cloneLlamaCppRepo.js +39 -28
- package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -1
- package/dist/bindings/utils/compileLLamaCpp.d.ts +11 -3
- package/dist/bindings/utils/compileLLamaCpp.js +250 -81
- package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
- package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +14 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js +305 -0
- package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
- package/dist/bindings/utils/detectGlibc.d.ts +4 -0
- package/dist/bindings/utils/detectGlibc.js +46 -0
- package/dist/bindings/utils/detectGlibc.js.map +1 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
- package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +14 -6
- package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -1
- package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -1
- package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
- package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
- package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
- package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js +27 -0
- package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
- package/dist/bindings/utils/getPlatform.js.map +1 -1
- package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
- package/dist/bindings/utils/getPlatformInfo.js +28 -0
- package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
- package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
- package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
- package/dist/bindings/utils/hasFileInPath.js +34 -0
- package/dist/bindings/utils/hasFileInPath.js.map +1 -0
- package/dist/bindings/utils/lastBuildInfo.js.map +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +1 -1
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +3 -9
- package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -1
- package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
- package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
- package/dist/bindings/utils/resolveCustomCmakeOptions.js +26 -26
- package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -1
- package/dist/bindings/utils/testBindingBinary.d.ts +1 -0
- package/dist/bindings/utils/testBindingBinary.js +100 -0
- package/dist/bindings/utils/testBindingBinary.js.map +1 -0
- package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
- package/dist/bindings/utils/testCmakeBinary.js +32 -0
- package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
- package/dist/chatWrappers/AlpacaChatWrapper.d.ts +2 -1
- package/dist/chatWrappers/AlpacaChatWrapper.js +10 -2
- package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
- package/dist/chatWrappers/ChatMLChatWrapper.d.ts +2 -14
- package/dist/chatWrappers/ChatMLChatWrapper.js +23 -21
- package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FalconChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/FalconChatWrapper.js +39 -21
- package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
- package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +8 -32
- package/dist/chatWrappers/FunctionaryChatWrapper.js +514 -118
- package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
- package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
- package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
- package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
- package/dist/chatWrappers/GeneralChatWrapper.d.ts +4 -10
- package/dist/chatWrappers/GeneralChatWrapper.js +46 -22
- package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
- package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
- package/dist/chatWrappers/{LlamaChatWrapper.js → Llama2ChatWrapper.js} +37 -20
- package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
- package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +35 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js +277 -0
- package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
- package/dist/chatWrappers/MistralChatWrapper.d.ts +15 -0
- package/dist/chatWrappers/MistralChatWrapper.js +169 -0
- package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +100 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +409 -0
- package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +60 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js +204 -0
- package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +23 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
- package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +57 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +119 -0
- package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
- package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
- package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
- package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +221 -0
- package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
- package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
- package/dist/chatWrappers/utils/jsonDumps.js +18 -0
- package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +95 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js +335 -0
- package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
- package/dist/cli/cli.js +19 -11
- package/dist/cli/cli.js.map +1 -1
- package/dist/cli/commands/ChatCommand.d.ts +16 -7
- package/dist/cli/commands/ChatCommand.js +321 -190
- package/dist/cli/commands/ChatCommand.js.map +1 -1
- package/dist/cli/commands/CompleteCommand.d.ts +31 -0
- package/dist/cli/commands/CompleteCommand.js +402 -0
- package/dist/cli/commands/CompleteCommand.js.map +1 -0
- package/dist/cli/commands/DebugCommand.d.ts +7 -0
- package/dist/cli/commands/DebugCommand.js +54 -0
- package/dist/cli/commands/DebugCommand.js.map +1 -0
- package/dist/cli/commands/InfillCommand.d.ts +33 -0
- package/dist/cli/commands/InfillCommand.js +438 -0
- package/dist/cli/commands/InfillCommand.js.map +1 -0
- package/dist/cli/commands/InitCommand.d.ts +11 -0
- package/dist/cli/commands/InitCommand.js +195 -0
- package/dist/cli/commands/InitCommand.js.map +1 -0
- package/dist/cli/commands/OnPostInstallCommand.js +6 -2
- package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
- package/dist/cli/commands/PullCommand.d.ts +13 -0
- package/dist/cli/commands/PullCommand.js +158 -0
- package/dist/cli/commands/PullCommand.js.map +1 -0
- package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/InspectCommand.js +21 -0
- package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +225 -0
- package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +12 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +149 -0
- package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +202 -0
- package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +18 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +629 -0
- package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
- package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
- package/dist/cli/commands/source/SourceCommand.js +19 -0
- package/dist/cli/commands/source/SourceCommand.js.map +1 -0
- package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
- package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
- package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
- package/dist/cli/commands/{ClearCommand.d.ts → source/commands/ClearCommand.d.ts} +1 -1
- package/dist/cli/commands/{ClearCommand.js → source/commands/ClearCommand.js} +11 -10
- package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
- package/dist/cli/commands/{DownloadCommand.d.ts → source/commands/DownloadCommand.d.ts} +5 -4
- package/dist/cli/commands/source/commands/DownloadCommand.js +217 -0
- package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
- package/dist/cli/projectTemplates.d.ts +7 -0
- package/dist/cli/projectTemplates.js +10 -0
- package/dist/cli/projectTemplates.js.map +1 -0
- package/dist/cli/recommendedModels.d.ts +2 -0
- package/dist/cli/recommendedModels.js +585 -0
- package/dist/cli/recommendedModels.js.map +1 -0
- package/dist/cli/startCreateCli.d.ts +2 -0
- package/dist/cli/startCreateCli.js +26 -0
- package/dist/cli/startCreateCli.js.map +1 -0
- package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
- package/dist/cli/utils/ConsoleInteraction.js +122 -0
- package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/ConsoleTable.d.ts +23 -0
- package/dist/cli/utils/ConsoleTable.js +86 -0
- package/dist/cli/utils/ConsoleTable.js.map +1 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
- package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
- package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
- package/dist/cli/utils/consolePromptQuestion.js +82 -0
- package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
- package/dist/cli/utils/getReadablePath.d.ts +1 -0
- package/dist/cli/utils/getReadablePath.js +14 -0
- package/dist/cli/utils/getReadablePath.js.map +1 -0
- package/dist/cli/utils/interactivelyAskForModel.d.ts +8 -0
- package/dist/cli/utils/interactivelyAskForModel.js +450 -0
- package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
- package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
- package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
- package/dist/cli/utils/printCommonInfoLines.d.ts +9 -0
- package/dist/cli/utils/printCommonInfoLines.js +82 -0
- package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
- package/dist/cli/utils/printInfoLine.d.ts +12 -0
- package/dist/cli/utils/printInfoLine.js +54 -0
- package/dist/cli/utils/printInfoLine.js.map +1 -0
- package/dist/cli/utils/projectTemplates.d.ts +19 -0
- package/dist/cli/utils/projectTemplates.js +47 -0
- package/dist/cli/utils/projectTemplates.js.map +1 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
- package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
- package/dist/cli/utils/resolveCommandGgufPath.d.ts +5 -0
- package/dist/cli/utils/resolveCommandGgufPath.js +72 -0
- package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
- package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
- package/dist/cli/utils/resolveHeaderFlag.js +21 -0
- package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +19 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js +7 -0
- package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
- package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
- package/dist/cli/utils/splitAnsiToLines.js +32 -0
- package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
- package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
- package/dist/commands.d.ts +4 -3
- package/dist/commands.js +6 -3
- package/dist/commands.js.map +1 -1
- package/dist/config.d.ts +35 -4
- package/dist/config.js +58 -17
- package/dist/config.js.map +1 -1
- package/dist/consts.d.ts +4 -0
- package/dist/consts.js +11 -0
- package/dist/consts.js.map +1 -0
- package/dist/evaluator/LlamaChat/LlamaChat.d.ts +151 -41
- package/dist/evaluator/LlamaChat/LlamaChat.js +1289 -437
- package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
- package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
- package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +27 -17
- package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +187 -13
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +280 -53
- package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +40 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +186 -0
- package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +10 -2
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
- package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -1
- package/dist/evaluator/LlamaCompletion.d.ts +168 -0
- package/dist/evaluator/LlamaCompletion.js +470 -0
- package/dist/evaluator/LlamaCompletion.js.map +1 -0
- package/dist/evaluator/LlamaContext/LlamaContext.d.ts +62 -21
- package/dist/evaluator/LlamaContext/LlamaContext.js +501 -120
- package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
- package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js +31 -0
- package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
- package/dist/evaluator/LlamaContext/types.d.ts +177 -16
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
- package/dist/evaluator/LlamaContext/utils/{resolveBatchItemsPrioritizingStrategy.js → resolveBatchItemsPrioritizationStrategy.js} +5 -5
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
- package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
- package/dist/evaluator/LlamaEmbedding.js +53 -0
- package/dist/evaluator/LlamaEmbedding.js.map +1 -0
- package/dist/evaluator/LlamaEmbeddingContext.d.ts +29 -19
- package/dist/evaluator/LlamaEmbeddingContext.js +36 -43
- package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
- package/dist/evaluator/LlamaGrammar.d.ts +16 -13
- package/dist/evaluator/LlamaGrammar.js +17 -10
- package/dist/evaluator/LlamaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +7 -3
- package/dist/evaluator/LlamaGrammarEvaluationState.js +8 -4
- package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -1
- package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +3 -0
- package/dist/evaluator/LlamaJsonSchemaGrammar.js +5 -3
- package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
- package/dist/evaluator/LlamaModel/LlamaModel.d.ts +255 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js +780 -0
- package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
- package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
- package/dist/evaluator/TokenBias.d.ts +34 -0
- package/dist/evaluator/TokenBias.js +65 -0
- package/dist/evaluator/TokenBias.js.map +1 -0
- package/dist/evaluator/TokenMeter.d.ts +45 -0
- package/dist/evaluator/TokenMeter.js +74 -0
- package/dist/evaluator/TokenMeter.js.map +1 -0
- package/dist/gguf/consts.d.ts +4 -0
- package/dist/gguf/consts.js +12 -0
- package/dist/gguf/consts.js.map +1 -0
- package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
- package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
- package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
- package/dist/gguf/fileReaders/GgufFileReader.js +109 -0
- package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
- package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +25 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +92 -0
- package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
- package/dist/gguf/insights/GgufInsights.d.ts +50 -0
- package/dist/gguf/insights/GgufInsights.js +401 -0
- package/dist/gguf/insights/GgufInsights.js.map +1 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +146 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +226 -0
- package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +19 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +78 -0
- package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +15 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +183 -0
- package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
- package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
- package/dist/gguf/insights/utils/scoreLevels.js +16 -0
- package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
- package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
- package/dist/gguf/parser/GgufV2Parser.js +156 -0
- package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
- package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
- package/dist/gguf/parser/GgufV3Parser.js +4 -0
- package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
- package/dist/gguf/parser/parseGguf.d.ts +8 -0
- package/dist/gguf/parser/parseGguf.js +61 -0
- package/dist/gguf/parser/parseGguf.js.map +1 -0
- package/dist/gguf/readGgufFileInfo.d.ts +45 -0
- package/dist/gguf/readGgufFileInfo.js +71 -0
- package/dist/gguf/readGgufFileInfo.js.map +1 -0
- package/dist/gguf/types/GgufFileInfoTypes.d.ts +84 -0
- package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
- package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
- package/dist/gguf/types/GgufMetadataTypes.d.ts +372 -0
- package/dist/gguf/types/GgufMetadataTypes.js +114 -0
- package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
- package/dist/gguf/types/GgufTensorInfoTypes.d.ts +37 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js +33 -0
- package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
- package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
- package/dist/gguf/utils/GgufReadOffset.js +18 -0
- package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
- package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
- package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
- package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
- package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
- package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +1 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js +16 -0
- package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
- package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
- package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
- package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
- package/dist/index.d.ts +39 -14
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/state.d.ts +2 -0
- package/dist/state.js +7 -0
- package/dist/state.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types.d.ts +131 -5
- package/dist/types.js.map +1 -1
- package/dist/utils/DisposeGuard.d.ts +13 -0
- package/dist/utils/DisposeGuard.js +120 -0
- package/dist/utils/DisposeGuard.js.map +1 -0
- package/dist/utils/InsufficientMemoryError.d.ts +3 -0
- package/dist/utils/InsufficientMemoryError.js +6 -0
- package/dist/utils/InsufficientMemoryError.js.map +1 -0
- package/dist/utils/LlamaText.d.ts +73 -26
- package/dist/utils/LlamaText.js +475 -157
- package/dist/utils/LlamaText.js.map +1 -1
- package/dist/utils/LruCache.d.ts +12 -0
- package/dist/utils/LruCache.js +44 -0
- package/dist/utils/LruCache.js.map +1 -0
- package/dist/utils/OverridesObject.d.ts +7 -0
- package/dist/utils/OverridesObject.js +2 -0
- package/dist/utils/OverridesObject.js.map +1 -0
- package/dist/utils/ReplHistory.js +5 -1
- package/dist/utils/ReplHistory.js.map +1 -1
- package/dist/utils/StopGenerationDetector.d.ts +27 -8
- package/dist/utils/StopGenerationDetector.js +108 -22
- package/dist/utils/StopGenerationDetector.js.map +1 -1
- package/dist/utils/ThreadsSplitter.d.ts +32 -0
- package/dist/utils/ThreadsSplitter.js +177 -0
- package/dist/utils/ThreadsSplitter.js.map +1 -0
- package/dist/utils/TokenStreamRegulator.d.ts +10 -4
- package/dist/utils/TokenStreamRegulator.js +102 -10
- package/dist/utils/TokenStreamRegulator.js.map +1 -1
- package/dist/utils/UnsupportedError.d.ts +2 -0
- package/dist/utils/UnsupportedError.js +7 -0
- package/dist/utils/UnsupportedError.js.map +1 -0
- package/dist/utils/appendUserMessageToChatHistory.d.ts +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js +4 -0
- package/dist/utils/appendUserMessageToChatHistory.js.map +1 -1
- package/dist/utils/clearTempFolder.js.map +1 -1
- package/dist/utils/cmake.js +23 -10
- package/dist/utils/cmake.js.map +1 -1
- package/dist/utils/compareTokens.d.ts +1 -1
- package/dist/utils/compareTokens.js.map +1 -1
- package/dist/utils/createModelDownloader.d.ts +199 -0
- package/dist/utils/createModelDownloader.js +405 -0
- package/dist/utils/createModelDownloader.js.map +1 -0
- package/dist/utils/findBestOption.d.ts +4 -0
- package/dist/utils/findBestOption.js +15 -0
- package/dist/utils/findBestOption.js.map +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +1 -0
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +23 -12
- package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
- package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
- package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
- package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
- package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
- package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
- package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
- package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +7 -4
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
- package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
- package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
- package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
- package/dist/utils/gbnfJson/types.d.ts +3 -0
- package/dist/utils/gbnfJson/types.js.map +1 -1
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
- package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
- package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +3 -3
- package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
- package/dist/utils/getBuildDefaults.d.ts +1 -2
- package/dist/utils/getBuildDefaults.js +2 -3
- package/dist/utils/getBuildDefaults.js.map +1 -1
- package/dist/utils/getConsoleLogPrefix.d.ts +1 -1
- package/dist/utils/getConsoleLogPrefix.js +5 -4
- package/dist/utils/getConsoleLogPrefix.js.map +1 -1
- package/dist/utils/getGrammarsFolder.js +1 -1
- package/dist/utils/getGrammarsFolder.js.map +1 -1
- package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
- package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
- package/dist/utils/getReadableContextSize.d.ts +1 -0
- package/dist/utils/getReadableContextSize.js +7 -0
- package/dist/utils/getReadableContextSize.js.map +1 -0
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +15 -11
- package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
- package/dist/utils/gitReleaseBundles.js +68 -1
- package/dist/utils/gitReleaseBundles.js.map +1 -1
- package/dist/utils/isToken.d.ts +2 -0
- package/dist/utils/isToken.js +4 -0
- package/dist/utils/isToken.js.map +1 -0
- package/dist/utils/isUrl.d.ts +1 -0
- package/dist/utils/isUrl.js +15 -0
- package/dist/utils/isUrl.js.map +1 -0
- package/dist/utils/mergeUnionTypes.d.ts +10 -0
- package/dist/utils/mergeUnionTypes.js +2 -0
- package/dist/utils/mergeUnionTypes.js.map +1 -0
- package/dist/utils/modelFileAccesTokens.d.ts +4 -0
- package/dist/utils/modelFileAccesTokens.js +40 -0
- package/dist/utils/modelFileAccesTokens.js.map +1 -0
- package/dist/utils/parseModelFileName.d.ts +1 -0
- package/dist/utils/parseModelFileName.js +6 -1
- package/dist/utils/parseModelFileName.js.map +1 -1
- package/dist/utils/parseTextTemplate.d.ts +66 -0
- package/dist/utils/parseTextTemplate.js +116 -0
- package/dist/utils/parseTextTemplate.js.map +1 -0
- package/dist/utils/prettyPrintObject.d.ts +10 -1
- package/dist/utils/prettyPrintObject.js +61 -15
- package/dist/utils/prettyPrintObject.js.map +1 -1
- package/dist/utils/pushAll.d.ts +6 -0
- package/dist/utils/pushAll.js +11 -0
- package/dist/utils/pushAll.js.map +1 -0
- package/dist/utils/removeNullFields.d.ts +2 -2
- package/dist/utils/removeNullFields.js.map +1 -1
- package/dist/utils/resolveGithubRelease.d.ts +2 -2
- package/dist/utils/resolveGithubRelease.js.map +1 -1
- package/dist/utils/resolveLastTokens.d.ts +2 -0
- package/dist/utils/resolveLastTokens.js +12 -0
- package/dist/utils/resolveLastTokens.js.map +1 -0
- package/dist/utils/runtime.d.ts +4 -0
- package/dist/utils/runtime.js +8 -0
- package/dist/utils/runtime.js.map +1 -0
- package/dist/utils/safeEventCallback.d.ts +6 -0
- package/dist/utils/safeEventCallback.js +29 -0
- package/dist/utils/safeEventCallback.js.map +1 -0
- package/dist/utils/spawnCommand.d.ts +11 -2
- package/dist/utils/spawnCommand.js +55 -7
- package/dist/utils/spawnCommand.js.map +1 -1
- package/dist/utils/tokenizeInput.d.ts +1 -1
- package/dist/utils/tokenizeInput.js +6 -3
- package/dist/utils/tokenizeInput.js.map +1 -1
- package/dist/utils/transformPromisable.d.ts +40 -0
- package/dist/utils/transformPromisable.js +64 -0
- package/dist/utils/transformPromisable.js.map +1 -0
- package/dist/utils/truncateTextAndRoundToWords.d.ts +2 -0
- package/dist/utils/truncateTextAndRoundToWords.js +32 -0
- package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
- package/dist/utils/utilTypes.d.ts +3 -0
- package/dist/utils/utilTypes.js +2 -0
- package/dist/utils/utilTypes.js.map +1 -0
- package/dist/utils/waitForLockfileRelease.js.map +1 -1
- package/dist/utils/withLockfile.js.map +1 -1
- package/dist/utils/withOra.d.ts +2 -0
- package/dist/utils/withOra.js +16 -6
- package/dist/utils/withOra.js.map +1 -1
- package/dist/utils/withProgressLog.d.ts +22 -0
- package/dist/utils/withProgressLog.js +211 -0
- package/dist/utils/withProgressLog.js.map +1 -0
- package/dist/utils/withStatusLogs.js +1 -1
- package/dist/utils/withStatusLogs.js.map +1 -1
- package/dist/utils/wrapAbortSignal.d.ts +1 -0
- package/dist/utils/wrapAbortSignal.js +9 -0
- package/dist/utils/wrapAbortSignal.js.map +1 -0
- package/llama/CMakeLists.txt +134 -5
- package/llama/addon/AddonContext.cpp +629 -0
- package/llama/addon/AddonContext.h +52 -0
- package/llama/addon/AddonGrammar.cpp +39 -0
- package/llama/addon/AddonGrammar.h +19 -0
- package/llama/addon/AddonGrammarEvaluationState.cpp +25 -0
- package/llama/addon/AddonGrammarEvaluationState.h +17 -0
- package/llama/addon/AddonModel.cpp +672 -0
- package/llama/addon/AddonModel.h +61 -0
- package/llama/addon/AddonModelData.cpp +25 -0
- package/llama/addon/AddonModelData.h +15 -0
- package/llama/addon/AddonModelLora.cpp +105 -0
- package/llama/addon/AddonModelLora.h +28 -0
- package/llama/addon/AddonSampler.cpp +513 -0
- package/llama/addon/AddonSampler.h +65 -0
- package/llama/addon/RingBuffer.h +109 -0
- package/llama/addon/addon.cpp +223 -0
- package/llama/addon/addonGlobals.cpp +22 -0
- package/llama/addon/addonGlobals.h +12 -0
- package/llama/addon/globals/addonLog.cpp +136 -0
- package/llama/addon/globals/addonLog.h +21 -0
- package/llama/addon/globals/addonProgress.cpp +15 -0
- package/llama/addon/globals/addonProgress.h +15 -0
- package/llama/addon/globals/getGpuInfo.cpp +108 -0
- package/llama/addon/globals/getGpuInfo.h +6 -0
- package/llama/binariesGithubRelease.json +1 -1
- package/llama/gitRelease.bundle +0 -0
- package/llama/gpuInfo/cuda-gpu-info.cu +120 -0
- package/llama/gpuInfo/cuda-gpu-info.h +10 -0
- package/llama/gpuInfo/metal-gpu-info.h +8 -0
- package/llama/gpuInfo/metal-gpu-info.mm +30 -0
- package/llama/gpuInfo/vulkan-gpu-info.cpp +83 -0
- package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
- package/llama/grammars/README.md +297 -6
- package/llama/grammars/json.gbnf +4 -4
- package/llama/grammars/json_arr.gbnf +4 -4
- package/llama/llama.cpp.info.json +1 -1
- package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
- package/package.json +109 -59
- package/templates/packed/electron-typescript-react.json +1 -0
- package/templates/packed/node-typescript.json +1 -0
- package/dist/AbortError.d.ts +0 -2
- package/dist/AbortError.js +0 -7
- package/dist/AbortError.js.map +0 -1
- package/dist/chatWrappers/LlamaChatWrapper.d.ts +0 -13
- package/dist/chatWrappers/LlamaChatWrapper.js.map +0 -1
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -57
- package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
- package/dist/cli/commands/BuildCommand.d.ts +0 -11
- package/dist/cli/commands/BuildCommand.js +0 -106
- package/dist/cli/commands/BuildCommand.js.map +0 -1
- package/dist/cli/commands/ClearCommand.js.map +0 -1
- package/dist/cli/commands/DownloadCommand.js +0 -169
- package/dist/cli/commands/DownloadCommand.js.map +0 -1
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +0 -22
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +0 -121
- package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -2
- package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
- package/dist/evaluator/LlamaModel.d.ts +0 -120
- package/dist/evaluator/LlamaModel.js +0 -320
- package/dist/evaluator/LlamaModel.js.map +0 -1
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
- package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
- package/dist/utils/parseModelTypeDescription.d.ts +0 -6
- package/dist/utils/parseModelTypeDescription.js +0 -9
- package/dist/utils/parseModelTypeDescription.js.map +0 -1
- package/dist/utils/resolveChatWrapper.d.ts +0 -4
- package/dist/utils/resolveChatWrapper.js +0 -16
- package/dist/utils/resolveChatWrapper.js.map +0 -1
- package/llama/addon.cpp +0 -950
- package/llamaBins/linux-arm64/.buildMetadata.json +0 -1
- package/llamaBins/linux-arm64/llama-addon.node +0 -0
- package/llamaBins/linux-armv7l/.buildMetadata.json +0 -1
- package/llamaBins/linux-armv7l/llama-addon.node +0 -0
- package/llamaBins/linux-x64/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64/llama-addon.node +0 -0
- package/llamaBins/linux-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
- package/llamaBins/mac-arm64-metal/.buildMetadata.json +0 -1
- package/llamaBins/mac-arm64-metal/ggml-metal.metal +0 -6119
- package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
- package/llamaBins/mac-x64/.buildMetadata.json +0 -1
- package/llamaBins/mac-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64/.buildMetadata.json +0 -1
- package/llamaBins/win-x64/llama-addon.exp +0 -0
- package/llamaBins/win-x64/llama-addon.lib +0 -0
- package/llamaBins/win-x64/llama-addon.node +0 -0
- package/llamaBins/win-x64-cuda/.buildMetadata.json +0 -1
- package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
- package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
- /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
|
@@ -0,0 +1,204 @@
|
|
|
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";
|
|
5
|
+
/**
|
|
6
|
+
* A chat wrapper based on a simple template.
|
|
7
|
+
* @example
|
|
8
|
+
* <span v-pre>
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import {TemplateChatWrapper} from "node-llama-cpp";
|
|
12
|
+
*
|
|
13
|
+
* const chatWrapper = new TemplateChatWrapper({
|
|
14
|
+
* template: "{{systemPrompt}}\n{{history}}model: {{completion}}\nuser: ",
|
|
15
|
+
* historyTemplate: {
|
|
16
|
+
* system: "system: {{message}}\n",
|
|
17
|
+
* user: "user: {{message}}\n",
|
|
18
|
+
* model: "model: {{message}}\n"
|
|
19
|
+
* },
|
|
20
|
+
* // functionCallMessageTemplate: { // optional
|
|
21
|
+
* // call: "[[call: {{functionName}}({{functionParams}})]]",
|
|
22
|
+
* // result: " [[result: {{functionCallResult}}]]"
|
|
23
|
+
* // }
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* </span>
|
|
28
|
+
*
|
|
29
|
+
* **<span v-pre>`{{systemPrompt}}`</span>** is optional and is replaced with the first system message
|
|
30
|
+
* (when is does, that system message is not included in the history).
|
|
31
|
+
*
|
|
32
|
+
* **<span v-pre>`{{history}}`</span>** is replaced with the chat history.
|
|
33
|
+
* Each message in the chat history is converted using the template passed to `historyTemplate` for the message role,
|
|
34
|
+
* and all messages are joined together.
|
|
35
|
+
*
|
|
36
|
+
* **<span v-pre>`{{completion}}`</span>** is where the model's response is generated.
|
|
37
|
+
* The text that comes after <span v-pre>`{{completion}}`</span> is used to determine when the model has finished generating the response,
|
|
38
|
+
* and thus is mandatory.
|
|
39
|
+
*
|
|
40
|
+
* **`functionCallMessageTemplate`** is used to specify the format in which functions can be called by the model and
|
|
41
|
+
* how their results are fed to the model after the function call.
|
|
42
|
+
*/
|
|
43
|
+
export class TemplateChatWrapper extends ChatWrapper {
|
|
44
|
+
wrapperName = "Template";
|
|
45
|
+
settings;
|
|
46
|
+
template;
|
|
47
|
+
historyTemplate;
|
|
48
|
+
joinAdjacentMessagesOfTheSameType;
|
|
49
|
+
/** @internal */ _parsedChatTemplate;
|
|
50
|
+
/** @internal */ _parsedChatHistoryTemplate;
|
|
51
|
+
constructor({ template, historyTemplate, functionCallMessageTemplate, joinAdjacentMessagesOfTheSameType = true }) {
|
|
52
|
+
super();
|
|
53
|
+
if (template == null || historyTemplate == null)
|
|
54
|
+
throw new Error("Template chat wrapper settings must have a template and historyTemplate.");
|
|
55
|
+
if (historyTemplate.system == null || historyTemplate.user == null || historyTemplate.model == null)
|
|
56
|
+
throw new Error("Template chat wrapper historyTemplate must have system, user, and model templates.");
|
|
57
|
+
this.template = template;
|
|
58
|
+
this.historyTemplate = historyTemplate;
|
|
59
|
+
this.joinAdjacentMessagesOfTheSameType = joinAdjacentMessagesOfTheSameType;
|
|
60
|
+
this._parsedChatTemplate = parseChatTemplate(template);
|
|
61
|
+
this._parsedChatHistoryTemplate = {
|
|
62
|
+
system: parseChatHistoryTemplate(historyTemplate.system),
|
|
63
|
+
user: parseChatHistoryTemplate(historyTemplate.user),
|
|
64
|
+
model: parseChatHistoryTemplate(historyTemplate.model)
|
|
65
|
+
};
|
|
66
|
+
this.settings = {
|
|
67
|
+
...ChatWrapper.defaultSettings,
|
|
68
|
+
functions: parseFunctionCallMessageTemplate(functionCallMessageTemplate) ?? ChatWrapper.defaultSettings.functions
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
generateContextState({ chatHistory, availableFunctions, documentFunctionParams }) {
|
|
72
|
+
const historyWithFunctions = this.addAvailableFunctionsSystemMessageToHistory(chatHistory, availableFunctions, {
|
|
73
|
+
documentParams: documentFunctionParams
|
|
74
|
+
});
|
|
75
|
+
const resultItems = [];
|
|
76
|
+
const systemTexts = [];
|
|
77
|
+
const userTexts = [];
|
|
78
|
+
const modelTexts = [];
|
|
79
|
+
let currentAggregateFocus = null;
|
|
80
|
+
function flush() {
|
|
81
|
+
if (systemTexts.length > 0 || userTexts.length > 0 || modelTexts.length > 0)
|
|
82
|
+
resultItems.push({
|
|
83
|
+
system: LlamaText.joinValues("\n\n", systemTexts),
|
|
84
|
+
user: LlamaText.joinValues("\n\n", userTexts),
|
|
85
|
+
model: LlamaText.joinValues("\n\n", modelTexts)
|
|
86
|
+
});
|
|
87
|
+
systemTexts.length = 0;
|
|
88
|
+
userTexts.length = 0;
|
|
89
|
+
modelTexts.length = 0;
|
|
90
|
+
}
|
|
91
|
+
for (const item of historyWithFunctions) {
|
|
92
|
+
if (item.type === "system") {
|
|
93
|
+
if (!this.joinAdjacentMessagesOfTheSameType || currentAggregateFocus !== "system")
|
|
94
|
+
flush();
|
|
95
|
+
currentAggregateFocus = "system";
|
|
96
|
+
systemTexts.push(LlamaText.fromJSON(item.text));
|
|
97
|
+
}
|
|
98
|
+
else if (item.type === "user") {
|
|
99
|
+
if (!this.joinAdjacentMessagesOfTheSameType || (currentAggregateFocus !== "system" && currentAggregateFocus !== "user"))
|
|
100
|
+
flush();
|
|
101
|
+
currentAggregateFocus = "user";
|
|
102
|
+
userTexts.push(LlamaText(item.text));
|
|
103
|
+
}
|
|
104
|
+
else if (item.type === "model") {
|
|
105
|
+
if (!this.joinAdjacentMessagesOfTheSameType)
|
|
106
|
+
flush();
|
|
107
|
+
currentAggregateFocus = "model";
|
|
108
|
+
modelTexts.push(this.generateModelResponseText(item.response));
|
|
109
|
+
}
|
|
110
|
+
else
|
|
111
|
+
void item;
|
|
112
|
+
}
|
|
113
|
+
flush();
|
|
114
|
+
const getHistoryItem = (role, text, prefix) => {
|
|
115
|
+
const { messagePrefix, messageSuffix } = this._parsedChatHistoryTemplate[role];
|
|
116
|
+
return LlamaText([
|
|
117
|
+
new SpecialTokensText((prefix ?? "") + messagePrefix),
|
|
118
|
+
text,
|
|
119
|
+
new SpecialTokensText(messageSuffix)
|
|
120
|
+
]);
|
|
121
|
+
};
|
|
122
|
+
const contextText = LlamaText(resultItems.map(({ system, user, model }, index) => {
|
|
123
|
+
const isFirstItem = index === 0;
|
|
124
|
+
const isLastItem = index === resultItems.length - 1;
|
|
125
|
+
const res = LlamaText([
|
|
126
|
+
isFirstItem
|
|
127
|
+
? system.values.length === 0
|
|
128
|
+
? new SpecialTokensText((this._parsedChatTemplate.systemPromptPrefix ?? "") + this._parsedChatTemplate.historyPrefix)
|
|
129
|
+
: this._parsedChatTemplate.systemPromptPrefix != null
|
|
130
|
+
? LlamaText([
|
|
131
|
+
new SpecialTokensText(this._parsedChatTemplate.systemPromptPrefix),
|
|
132
|
+
system,
|
|
133
|
+
new SpecialTokensText(this._parsedChatTemplate.historyPrefix)
|
|
134
|
+
])
|
|
135
|
+
: getHistoryItem("system", system, this._parsedChatTemplate.historyPrefix)
|
|
136
|
+
: system.values.length === 0
|
|
137
|
+
? LlamaText([])
|
|
138
|
+
: getHistoryItem("system", system),
|
|
139
|
+
user.values.length === 0
|
|
140
|
+
? LlamaText([])
|
|
141
|
+
: getHistoryItem("user", user),
|
|
142
|
+
model.values.length === 0
|
|
143
|
+
? LlamaText([])
|
|
144
|
+
: !isLastItem
|
|
145
|
+
? getHistoryItem("model", model)
|
|
146
|
+
: LlamaText([
|
|
147
|
+
new SpecialTokensText(this._parsedChatTemplate.completionPrefix),
|
|
148
|
+
model
|
|
149
|
+
])
|
|
150
|
+
]);
|
|
151
|
+
return LlamaText(res.values.reduce((res, value) => {
|
|
152
|
+
if (value instanceof SpecialTokensText) {
|
|
153
|
+
const lastItem = res[res.length - 1];
|
|
154
|
+
if (lastItem == null || !(lastItem instanceof SpecialTokensText))
|
|
155
|
+
return res.concat([value]);
|
|
156
|
+
return res.slice(0, -1).concat([
|
|
157
|
+
new SpecialTokensText(lastItem.value + value.value)
|
|
158
|
+
]);
|
|
159
|
+
}
|
|
160
|
+
return res.concat([value]);
|
|
161
|
+
}, []));
|
|
162
|
+
}));
|
|
163
|
+
return {
|
|
164
|
+
contextText,
|
|
165
|
+
stopGenerationTriggers: [
|
|
166
|
+
LlamaText(new SpecialToken("EOS")),
|
|
167
|
+
LlamaText(this._parsedChatTemplate.completionSuffix),
|
|
168
|
+
LlamaText(new SpecialTokensText(this._parsedChatTemplate.completionSuffix))
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
function parseChatTemplate(template) {
|
|
174
|
+
const parsedTemplate = parseTextTemplate(template, [{
|
|
175
|
+
text: "{{systemPrompt}}",
|
|
176
|
+
key: "systemPrompt",
|
|
177
|
+
optional: true
|
|
178
|
+
}, {
|
|
179
|
+
text: "{{history}}",
|
|
180
|
+
key: "history"
|
|
181
|
+
}, {
|
|
182
|
+
text: "{{completion}}",
|
|
183
|
+
key: "completion"
|
|
184
|
+
}]);
|
|
185
|
+
if (parsedTemplate.completion.suffix.length == 0)
|
|
186
|
+
throw new Error('Chat template must have text after "{{completion}}"');
|
|
187
|
+
return {
|
|
188
|
+
systemPromptPrefix: parsedTemplate.systemPrompt?.prefix ?? null,
|
|
189
|
+
historyPrefix: parsedTemplate.history.prefix,
|
|
190
|
+
completionPrefix: parsedTemplate.completion.prefix,
|
|
191
|
+
completionSuffix: parsedTemplate.completion.suffix
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
function parseChatHistoryTemplate(template) {
|
|
195
|
+
const parsedTemplate = parseTextTemplate(template, [{
|
|
196
|
+
text: "{{message}}",
|
|
197
|
+
key: "message"
|
|
198
|
+
}]);
|
|
199
|
+
return {
|
|
200
|
+
messagePrefix: parsedTemplate.message.prefix,
|
|
201
|
+
messageSuffix: parsedTemplate.message.suffix
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=TemplateChatWrapper.js.map
|
|
@@ -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,EAAC,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,kCAAkC,CAAC;AACnE,OAAO,EAAyC,gCAAgC,EAAC,MAAM,mDAAmD,CAAC;AAa3I;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAChC,WAAW,GAAG,UAAU,CAAC;IAChB,QAAQ,CAAsB;IAEvC,QAAQ,CAAyC;IACjD,eAAe,CAA0D;IACzE,iCAAiC,CAAU;IAE3D,gBAAgB,CAAkB,mBAAmB,CAAuC;IAC5F,gBAAgB,CAAkB,0BAA0B,CAI1D;IAEF,YAAmB,EACf,QAAQ,EACR,eAAe,EACf,2BAA2B,EAC3B,iCAAiC,GAAG,IAAI,EACf;QACzB,KAAK,EAAE,CAAC;QAER,IAAI,QAAQ,IAAI,IAAI,IAAI,eAAe,IAAI,IAAI;YAC3C,MAAM,IAAI,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;AACN,CAAC;AAED,SAAS,wBAAwB,CAAC,QAAyC;IAIvE,MAAM,cAAc,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;YAChD,IAAI,EAAE,aAAa;YACnB,GAAG,EAAE,SAAS;SACjB,CAAC,CAAC,CAAC;IAEJ,OAAO;QACH,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM;QAC5C,aAAa,EAAE,cAAc,CAAC,OAAO,CAAC,MAAM;KAC/C,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ChatWrapperSettings } from "../../../types.js";
|
|
2
|
+
export declare function parseFunctionCallMessageTemplate(template?: ChatHistoryFunctionCallMessageTemplate): ChatWrapperSettings["functions"] | null;
|
|
3
|
+
/**
|
|
4
|
+
* Template format for how functions can be called by the model and how their results are fed to the model after the function call.
|
|
5
|
+
* Consists of an array with two elements:
|
|
6
|
+
* 1. The function call template.
|
|
7
|
+
* 2. The function call result template.
|
|
8
|
+
*
|
|
9
|
+
* For example:
|
|
10
|
+
* ```ts
|
|
11
|
+
* const template: ChatHistoryFunctionCallMessageTemplate = {
|
|
12
|
+
* call: "[[call: {{functionName}}({{functionParams}})]]",
|
|
13
|
+
* result: " [[result: {{functionCallResult}}]]"
|
|
14
|
+
* };
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* It's mandatory for the call template to have text before <span v-pre>`{{functionName}}`</span> in order for the chat wrapper know when
|
|
18
|
+
* to activate the function calling grammar.
|
|
19
|
+
*/
|
|
20
|
+
export type ChatHistoryFunctionCallMessageTemplate = {
|
|
21
|
+
call: `${string}{{functionName}}${string}{{functionParams}}${string}`;
|
|
22
|
+
result: `${string}{{functionCallResult}}${string}`;
|
|
23
|
+
};
|
|
@@ -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 { call: functionCallTemplate, result: 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;AAGtE,MAAM,UAAU,gCAAgC,CAC5C,QAAiD;IAEjD,IAAI,QAAQ,IAAI,IAAI;QAChB,OAAO,IAAI,CAAC;IAEhB,MAAM,EACF,IAAI,EAAE,oBAAoB,EAC1B,MAAM,EAAE,0BAA0B,EACrC,GAAG,QAAQ,CAAC;IAEb,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,57 @@
|
|
|
1
|
+
import { ChatModelFunctions } from "../../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Generate documentation about the functions that are available for a model to call.
|
|
4
|
+
* Useful for generating a system message with information about the available functions as part of a chat wrapper.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ChatModelFunctionsDocumentationGenerator {
|
|
7
|
+
readonly chatModelFunctions?: ChatModelFunctions;
|
|
8
|
+
readonly hasAnyFunctions: boolean;
|
|
9
|
+
constructor(chatModelFunctions: ChatModelFunctions | undefined);
|
|
10
|
+
/**
|
|
11
|
+
* Example:
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Retrieve the current date
|
|
14
|
+
* function getDate();
|
|
15
|
+
*
|
|
16
|
+
* // Retrieve the current time
|
|
17
|
+
* function getTime(params: {hours: "24" | "12", seconds: boolean});
|
|
18
|
+
* ```
|
|
19
|
+
* @param options
|
|
20
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
21
|
+
*/
|
|
22
|
+
getTypeScriptFunctionSignatures({ documentParams }?: {
|
|
23
|
+
documentParams?: boolean;
|
|
24
|
+
}): string;
|
|
25
|
+
/**
|
|
26
|
+
* Example:
|
|
27
|
+
* ```ts
|
|
28
|
+
* // Retrieve the current date
|
|
29
|
+
* type getDate = () => any;
|
|
30
|
+
*
|
|
31
|
+
* // Retrieve the current time
|
|
32
|
+
* type getTime = (_: {hours: "24" | "12", seconds: boolean}) => any;
|
|
33
|
+
* ```
|
|
34
|
+
* @param options
|
|
35
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
36
|
+
* @param [options.reservedFunctionNames] - Function names that are reserved and cannot be used
|
|
37
|
+
*/
|
|
38
|
+
getTypeScriptFunctionTypes({ documentParams, reservedFunctionNames }?: {
|
|
39
|
+
documentParams?: boolean;
|
|
40
|
+
reservedFunctionNames?: string[];
|
|
41
|
+
}): string;
|
|
42
|
+
/**
|
|
43
|
+
* Example:
|
|
44
|
+
* ```
|
|
45
|
+
* Use the function 'getDate' to: Retrieve the current date
|
|
46
|
+
* {"name": "getDate", "description": "Retrieve the current date"}
|
|
47
|
+
*
|
|
48
|
+
* Use the function 'getTime' to: Retrieve the current time
|
|
49
|
+
* {"name": "getTime", "description": "Retrieve the current time", "parameters": {"type": "object", "properties": {"hours": {"enum": ["24", "12"]}, "seconds": {"type": "boolean"}}}}
|
|
50
|
+
* ```
|
|
51
|
+
* @param options
|
|
52
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
53
|
+
*/
|
|
54
|
+
getLlama3_1FunctionSignatures({ documentParams }?: {
|
|
55
|
+
documentParams?: boolean;
|
|
56
|
+
}): string;
|
|
57
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { getTypeScriptTypeStringForGbnfJsonSchema } from "../../utils/getTypeScriptTypeStringForGbnfJsonSchema.js";
|
|
2
|
+
import { jsonDumps } from "./jsonDumps.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generate documentation about the functions that are available for a model to call.
|
|
5
|
+
* Useful for generating a system message with information about the available functions as part of a chat wrapper.
|
|
6
|
+
*/
|
|
7
|
+
export class ChatModelFunctionsDocumentationGenerator {
|
|
8
|
+
chatModelFunctions;
|
|
9
|
+
hasAnyFunctions;
|
|
10
|
+
constructor(chatModelFunctions) {
|
|
11
|
+
this.chatModelFunctions = chatModelFunctions;
|
|
12
|
+
this.hasAnyFunctions = Object.keys(this.chatModelFunctions ?? {}).length > 0;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Example:
|
|
16
|
+
* ```ts
|
|
17
|
+
* // Retrieve the current date
|
|
18
|
+
* function getDate();
|
|
19
|
+
*
|
|
20
|
+
* // Retrieve the current time
|
|
21
|
+
* function getTime(params: {hours: "24" | "12", seconds: boolean});
|
|
22
|
+
* ```
|
|
23
|
+
* @param options
|
|
24
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
25
|
+
*/
|
|
26
|
+
getTypeScriptFunctionSignatures({ documentParams = true } = {}) {
|
|
27
|
+
const chatModelFunctions = this.chatModelFunctions;
|
|
28
|
+
if (!this.hasAnyFunctions || chatModelFunctions == null)
|
|
29
|
+
return "";
|
|
30
|
+
const functionNames = Object.keys(chatModelFunctions);
|
|
31
|
+
return functionNames
|
|
32
|
+
.map((functionName) => {
|
|
33
|
+
const functionDefinition = chatModelFunctions[functionName];
|
|
34
|
+
let res = "";
|
|
35
|
+
if (functionDefinition?.description != null && functionDefinition.description.trim() !== "")
|
|
36
|
+
res += "// " + functionDefinition.description.split("\n").join("\n// ") + "\n";
|
|
37
|
+
res += "function " + functionName + "(";
|
|
38
|
+
if (documentParams && functionDefinition?.params != null)
|
|
39
|
+
res += "params: " + getTypeScriptTypeStringForGbnfJsonSchema(functionDefinition.params);
|
|
40
|
+
else if (!documentParams && functionDefinition?.params != null)
|
|
41
|
+
res += "params";
|
|
42
|
+
res += ");";
|
|
43
|
+
return res;
|
|
44
|
+
})
|
|
45
|
+
.join("\n\n");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Example:
|
|
49
|
+
* ```ts
|
|
50
|
+
* // Retrieve the current date
|
|
51
|
+
* type getDate = () => any;
|
|
52
|
+
*
|
|
53
|
+
* // Retrieve the current time
|
|
54
|
+
* type getTime = (_: {hours: "24" | "12", seconds: boolean}) => any;
|
|
55
|
+
* ```
|
|
56
|
+
* @param options
|
|
57
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
58
|
+
* @param [options.reservedFunctionNames] - Function names that are reserved and cannot be used
|
|
59
|
+
*/
|
|
60
|
+
getTypeScriptFunctionTypes({ documentParams = true, reservedFunctionNames = [] } = {}) {
|
|
61
|
+
const chatModelFunctions = this.chatModelFunctions;
|
|
62
|
+
if (!this.hasAnyFunctions || chatModelFunctions == null)
|
|
63
|
+
return "";
|
|
64
|
+
const functionNames = Object.keys(chatModelFunctions);
|
|
65
|
+
const reservedFunctionNamesSet = new Set(reservedFunctionNames);
|
|
66
|
+
return functionNames
|
|
67
|
+
.map((functionName) => {
|
|
68
|
+
if (reservedFunctionNamesSet.has(functionName))
|
|
69
|
+
throw new Error(`Function name "${functionName}" is reserved and cannot be used`);
|
|
70
|
+
const functionDefinition = chatModelFunctions[functionName];
|
|
71
|
+
let res = "";
|
|
72
|
+
if (functionDefinition?.description != null && functionDefinition.description.trim() !== "")
|
|
73
|
+
res += "// " + functionDefinition.description.split("\n").join("\n// ") + "\n";
|
|
74
|
+
res += "type " + functionName + " = (";
|
|
75
|
+
if (documentParams && functionDefinition?.params != null)
|
|
76
|
+
res += "_: " + getTypeScriptTypeStringForGbnfJsonSchema(functionDefinition.params);
|
|
77
|
+
res += ") => any;";
|
|
78
|
+
return res;
|
|
79
|
+
})
|
|
80
|
+
.join("\n\n");
|
|
81
|
+
}
|
|
82
|
+
/* eslint-disable max-len */
|
|
83
|
+
/**
|
|
84
|
+
* Example:
|
|
85
|
+
* ```
|
|
86
|
+
* Use the function 'getDate' to: Retrieve the current date
|
|
87
|
+
* {"name": "getDate", "description": "Retrieve the current date"}
|
|
88
|
+
*
|
|
89
|
+
* Use the function 'getTime' to: Retrieve the current time
|
|
90
|
+
* {"name": "getTime", "description": "Retrieve the current time", "parameters": {"type": "object", "properties": {"hours": {"enum": ["24", "12"]}, "seconds": {"type": "boolean"}}}}
|
|
91
|
+
* ```
|
|
92
|
+
* @param options
|
|
93
|
+
* @param [options.documentParams] - Whether to document the parameters of the functions
|
|
94
|
+
*/
|
|
95
|
+
getLlama3_1FunctionSignatures({ documentParams = true } = {}) {
|
|
96
|
+
const chatModelFunctions = this.chatModelFunctions;
|
|
97
|
+
if (!this.hasAnyFunctions || chatModelFunctions == null)
|
|
98
|
+
return "";
|
|
99
|
+
const functionNames = Object.keys(chatModelFunctions);
|
|
100
|
+
return functionNames
|
|
101
|
+
.map((functionName) => {
|
|
102
|
+
const functionDefinition = chatModelFunctions[functionName];
|
|
103
|
+
let res = `Use the function '${functionName}'`;
|
|
104
|
+
const addDescription = functionDefinition?.description != null && functionDefinition.description.trim() !== "";
|
|
105
|
+
if (addDescription)
|
|
106
|
+
res += " to: " + functionDefinition.description.split("\n").join("\n// ") + "\n";
|
|
107
|
+
else
|
|
108
|
+
res += ".\n";
|
|
109
|
+
res += jsonDumps({
|
|
110
|
+
name: functionName,
|
|
111
|
+
...(addDescription ? { description: functionDefinition.description } : {}),
|
|
112
|
+
...(documentParams && functionDefinition?.params != null ? { parameters: functionDefinition.params } : {})
|
|
113
|
+
});
|
|
114
|
+
return res;
|
|
115
|
+
})
|
|
116
|
+
.join("\n\n");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=ChatModelFunctionsDocumentationGenerator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatModelFunctionsDocumentationGenerator.js","sourceRoot":"","sources":["../../../src/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.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I,IAAI,CAAC,CAAC,CAAC,EAAC,UAAU,EAAE,kBAAkB,CAAC,MAAM,EAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3G,CAAC,CAAC;YAEH,OAAO,GAAG,CAAC;QACf,CAAC,CAAC;aACD,IAAI,CAAC,MAAM,CAAC,CAAC;IACtB,CAAC;CAEJ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ChatHistoryItem, ChatModelResponse } from "../../types.js";
|
|
2
|
+
import { LlamaText } from "../../utils/LlamaText.js";
|
|
3
|
+
export declare function chunkChatItems(chatHistory: readonly ChatHistoryItem[], { generateModelResponseText, joinAdjacentMessagesOfTheSameType }: {
|
|
4
|
+
generateModelResponseText: (modelResponse: ChatModelResponse["response"]) => LlamaText;
|
|
5
|
+
joinAdjacentMessagesOfTheSameType?: boolean;
|
|
6
|
+
}): {
|
|
7
|
+
system: LlamaText;
|
|
8
|
+
user: LlamaText;
|
|
9
|
+
model: LlamaText;
|
|
10
|
+
}[];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { LlamaText } from "../../utils/LlamaText.js";
|
|
2
|
+
export function chunkChatItems(chatHistory, { generateModelResponseText, joinAdjacentMessagesOfTheSameType = true }) {
|
|
3
|
+
const resultItems = [];
|
|
4
|
+
let systemTexts = [];
|
|
5
|
+
let userTexts = [];
|
|
6
|
+
let modelTexts = [];
|
|
7
|
+
let currentAggregateFocus = null;
|
|
8
|
+
function flush() {
|
|
9
|
+
if (systemTexts.length > 0 || userTexts.length > 0 || modelTexts.length > 0)
|
|
10
|
+
resultItems.push({
|
|
11
|
+
system: LlamaText.joinValues("\n\n", systemTexts),
|
|
12
|
+
user: LlamaText.joinValues("\n\n", userTexts),
|
|
13
|
+
model: LlamaText.joinValues("\n\n", modelTexts)
|
|
14
|
+
});
|
|
15
|
+
systemTexts = [];
|
|
16
|
+
userTexts = [];
|
|
17
|
+
modelTexts = [];
|
|
18
|
+
}
|
|
19
|
+
for (const item of chatHistory) {
|
|
20
|
+
if (item.type === "system") {
|
|
21
|
+
if (!joinAdjacentMessagesOfTheSameType || currentAggregateFocus !== "system")
|
|
22
|
+
flush();
|
|
23
|
+
currentAggregateFocus = "system";
|
|
24
|
+
systemTexts.push(LlamaText.fromJSON(item.text));
|
|
25
|
+
}
|
|
26
|
+
else if (item.type === "user") {
|
|
27
|
+
if (!joinAdjacentMessagesOfTheSameType || currentAggregateFocus !== "system" && currentAggregateFocus !== "user")
|
|
28
|
+
flush();
|
|
29
|
+
currentAggregateFocus = "user";
|
|
30
|
+
userTexts.push(LlamaText(item.text));
|
|
31
|
+
}
|
|
32
|
+
else if (item.type === "model") {
|
|
33
|
+
if (!joinAdjacentMessagesOfTheSameType)
|
|
34
|
+
flush();
|
|
35
|
+
currentAggregateFocus = "model";
|
|
36
|
+
modelTexts.push(generateModelResponseText(item.response));
|
|
37
|
+
}
|
|
38
|
+
else
|
|
39
|
+
void item;
|
|
40
|
+
}
|
|
41
|
+
flush();
|
|
42
|
+
return resultItems;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=chunkChatItems.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunkChatItems.js","sourceRoot":"","sources":["../../../src/chatWrappers/utils/chunkChatItems.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,SAAS,EAAC,MAAM,0BAA0B,CAAC;AAEnD,MAAM,UAAU,cAAc,CAAC,WAAuC,EAAE,EACpE,yBAAyB,EACzB,iCAAiC,GAAG,IAAI,EAI3C;IACG,MAAM,WAAW,GAIZ,EAAE,CAAC;IAER,IAAI,WAAW,GAAgB,EAAE,CAAC;IAClC,IAAI,SAAS,GAAgB,EAAE,CAAC;IAChC,IAAI,UAAU,GAAgB,EAAE,CAAC;IACjC,IAAI,qBAAqB,GAAuC,IAAI,CAAC;IAErE,SAAS,KAAK;QACV,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,IAAI,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KAAM,IAAqB,CAAC;IACpC,CAAC;IAED,KAAK,EAAE,CAAC;IAER,OAAO,WAAW,CAAC;AACvB,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;
|