@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,177 @@
|
|
|
1
|
+
import { ChatHistoryItem, ChatModelFunctions, ChatWrapperSettings } from "../types.js";
|
|
2
|
+
import { ChatWrapper } from "../ChatWrapper.js";
|
|
3
|
+
import { LlamaChatResponseFunctionCall } from "../evaluator/LlamaChat/LlamaChat.js";
|
|
4
|
+
import { TokenBias } from "../evaluator/TokenBias.js";
|
|
5
|
+
import { LlamaGrammar } from "../evaluator/LlamaGrammar.js";
|
|
6
|
+
import { Llama } from "../bindings/Llama.js";
|
|
7
|
+
import { LlamaModel } from "../evaluator/LlamaModel/LlamaModel.js";
|
|
8
|
+
import { GbnfJsonSchema } from "./gbnfJson/types.js";
|
|
9
|
+
import { LlamaText } from "./LlamaText.js";
|
|
10
|
+
export declare class OpenAIFormat {
|
|
11
|
+
readonly chatWrapper: ChatWrapper;
|
|
12
|
+
constructor({ chatWrapper }: {
|
|
13
|
+
chatWrapper: ChatWrapper;
|
|
14
|
+
});
|
|
15
|
+
/**
|
|
16
|
+
* Convert `node-llama-cpp`'s chat history to OpenAI format.
|
|
17
|
+
*
|
|
18
|
+
* Note that this conversion is lossy, as OpenAI's format is more limited than `node-llama-cpp`'s.
|
|
19
|
+
*/
|
|
20
|
+
toOpenAiChat<Functions extends ChatModelFunctions>({ chatHistory, functionCalls, functions, useRawValues }: {
|
|
21
|
+
chatHistory: ChatHistoryItem[];
|
|
22
|
+
functionCalls?: LlamaChatResponseFunctionCall<Functions>[];
|
|
23
|
+
functions?: Functions;
|
|
24
|
+
useRawValues?: boolean;
|
|
25
|
+
}): OpenAiChatCreationOptions;
|
|
26
|
+
fromOpenAiChat<Functions extends ChatModelFunctions = ChatModelFunctions>(options: OpenAiChatCreationOptions, { llama, model }?: {
|
|
27
|
+
llama?: Llama;
|
|
28
|
+
model?: LlamaModel;
|
|
29
|
+
}): Promise<{
|
|
30
|
+
chatHistory: ChatHistoryItem[];
|
|
31
|
+
functionCalls?: LlamaChatResponseFunctionCall<ChatModelFunctions>[];
|
|
32
|
+
functions?: Functions;
|
|
33
|
+
tokenBias?: TokenBias;
|
|
34
|
+
maxTokens?: number;
|
|
35
|
+
maxParallelFunctionCalls?: number;
|
|
36
|
+
grammar?: LlamaGrammar;
|
|
37
|
+
seed?: number;
|
|
38
|
+
customStopTriggers?: string[];
|
|
39
|
+
temperature?: number;
|
|
40
|
+
minP?: number;
|
|
41
|
+
topK?: number;
|
|
42
|
+
topP?: number;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
export declare function fromIntermediateToCompleteOpenAiMessages(messages: IntermediateOpenAiMessage[]): (OpenAiChatSystemMessage | OpenAiChatUserMessage | OpenAiChatToolMessage | OpenAiChatAssistantMessage | {
|
|
46
|
+
content: string;
|
|
47
|
+
role: "assistant";
|
|
48
|
+
tool_calls?: Array<{
|
|
49
|
+
id: string;
|
|
50
|
+
type: "function";
|
|
51
|
+
function: {
|
|
52
|
+
name: string;
|
|
53
|
+
arguments: string | any;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
})[];
|
|
57
|
+
export declare function fromChatHistoryToIntermediateOpenAiMessages<Functions extends ChatModelFunctions>({ chatHistory, chatWrapperSettings, functionCalls, functions, useRawValues, combineModelMessageAndToolCalls, stringifyFunctionParams, stringifyFunctionResults, squashModelTextResponses }: {
|
|
58
|
+
chatHistory: readonly ChatHistoryItem[];
|
|
59
|
+
chatWrapperSettings: ChatWrapperSettings;
|
|
60
|
+
functionCalls?: LlamaChatResponseFunctionCall<Functions>[];
|
|
61
|
+
functions?: Functions;
|
|
62
|
+
useRawValues?: boolean;
|
|
63
|
+
combineModelMessageAndToolCalls?: boolean;
|
|
64
|
+
stringifyFunctionParams?: boolean;
|
|
65
|
+
stringifyFunctionResults?: boolean;
|
|
66
|
+
squashModelTextResponses?: boolean;
|
|
67
|
+
}): IntermediateOpenAiConversionFromChatHistory;
|
|
68
|
+
export type IntermediateOpenAiConversionFromChatHistory = {
|
|
69
|
+
messages: IntermediateOpenAiMessage[];
|
|
70
|
+
tools?: OpenAiChatTool[];
|
|
71
|
+
};
|
|
72
|
+
export type OpenAiChatCreationOptions = {
|
|
73
|
+
messages: OpenAiChatMessage[];
|
|
74
|
+
tools?: OpenAiChatTool[];
|
|
75
|
+
"tool_choice"?: "none" | "auto";
|
|
76
|
+
"logit_bias"?: Record<string, number> | null;
|
|
77
|
+
"max_completion_tokens"?: number | null;
|
|
78
|
+
/** Overridden by `"max_completion_tokens"` */
|
|
79
|
+
"max_tokens"?: number | null;
|
|
80
|
+
"parallel_tool_calls"?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Only used when a Llama instance is provided.
|
|
83
|
+
* A llama instance is provided through a context sequence.
|
|
84
|
+
*/
|
|
85
|
+
"response_format"?: {
|
|
86
|
+
type: "text";
|
|
87
|
+
} | {
|
|
88
|
+
type: "json_schema";
|
|
89
|
+
"json_schema": {
|
|
90
|
+
name: string;
|
|
91
|
+
description?: string;
|
|
92
|
+
schema?: GbnfJsonSchema;
|
|
93
|
+
strict?: boolean | null;
|
|
94
|
+
};
|
|
95
|
+
} | {
|
|
96
|
+
type: "json_object";
|
|
97
|
+
};
|
|
98
|
+
seed?: number | null;
|
|
99
|
+
stop?: string | null | string[];
|
|
100
|
+
temperature?: number | null;
|
|
101
|
+
"min_p"?: number | null;
|
|
102
|
+
"top_p"?: number | null;
|
|
103
|
+
"top_k"?: number | null;
|
|
104
|
+
};
|
|
105
|
+
type OpenAiChatTool = {
|
|
106
|
+
type: "function";
|
|
107
|
+
function: {
|
|
108
|
+
name: string;
|
|
109
|
+
description?: string;
|
|
110
|
+
parameters?: GbnfJsonSchema;
|
|
111
|
+
strict?: boolean | null;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
export type IntermediateOpenAiMessage = (Omit<OpenAiChatSystemMessage, "content"> & {
|
|
115
|
+
content: LlamaText | string;
|
|
116
|
+
} | Omit<OpenAiChatUserMessage, "content"> & {
|
|
117
|
+
content: LlamaText | string;
|
|
118
|
+
} | Omit<OpenAiChatToolMessage, "content"> & {
|
|
119
|
+
content: LlamaText | string;
|
|
120
|
+
} | Omit<OpenAiChatAssistantMessage, "content" | "tool_calls"> & {
|
|
121
|
+
content?: LlamaText | string;
|
|
122
|
+
"tool_calls"?: Array<{
|
|
123
|
+
id: string;
|
|
124
|
+
type: "function";
|
|
125
|
+
function: {
|
|
126
|
+
name: string;
|
|
127
|
+
arguments: string | any;
|
|
128
|
+
};
|
|
129
|
+
}>;
|
|
130
|
+
});
|
|
131
|
+
export type OpenAiChatMessage = OpenAiChatSystemMessage | OpenAiChatUserMessage | OpenAiChatAssistantMessage | OpenAiChatToolMessage;
|
|
132
|
+
export type OpenAiChatSystemMessage = {
|
|
133
|
+
role: "system";
|
|
134
|
+
content: string | {
|
|
135
|
+
type: "text";
|
|
136
|
+
text: string;
|
|
137
|
+
}[];
|
|
138
|
+
};
|
|
139
|
+
export type OpenAiChatUserMessage = {
|
|
140
|
+
role: "user";
|
|
141
|
+
content: string | {
|
|
142
|
+
type: "text";
|
|
143
|
+
text: string;
|
|
144
|
+
}[];
|
|
145
|
+
};
|
|
146
|
+
export type OpenAiChatAssistantMessage = {
|
|
147
|
+
role: "assistant";
|
|
148
|
+
content?: string | {
|
|
149
|
+
type: "text";
|
|
150
|
+
text: string;
|
|
151
|
+
}[] | null;
|
|
152
|
+
"tool_calls"?: Array<{
|
|
153
|
+
id: string;
|
|
154
|
+
type: "function";
|
|
155
|
+
function: {
|
|
156
|
+
name: string;
|
|
157
|
+
arguments: string;
|
|
158
|
+
};
|
|
159
|
+
}>;
|
|
160
|
+
};
|
|
161
|
+
export type OpenAiChatToolMessage = {
|
|
162
|
+
role: "tool";
|
|
163
|
+
content: string | {
|
|
164
|
+
type: "text";
|
|
165
|
+
text: string;
|
|
166
|
+
}[];
|
|
167
|
+
"tool_call_id": string;
|
|
168
|
+
};
|
|
169
|
+
export declare function resolveOpenAiText(text: string | {
|
|
170
|
+
type: "text";
|
|
171
|
+
text: string;
|
|
172
|
+
}[]): string;
|
|
173
|
+
export declare function resolveOpenAiText(text: string | {
|
|
174
|
+
type: "text";
|
|
175
|
+
text: string;
|
|
176
|
+
}[] | null | undefined): string | null;
|
|
177
|
+
export {};
|
|
@@ -0,0 +1,488 @@
|
|
|
1
|
+
import { splitText } from "lifecycle-utils";
|
|
2
|
+
import { allSegmentTypes } from "../types.js";
|
|
3
|
+
import { jsonDumps } from "../chatWrappers/utils/jsonDumps.js";
|
|
4
|
+
import { TokenBias } from "../evaluator/TokenBias.js";
|
|
5
|
+
import { getChatWrapperSegmentDefinition } from "./getChatWrapperSegmentDefinition.js";
|
|
6
|
+
import { LlamaText } from "./LlamaText.js";
|
|
7
|
+
import { removeUndefinedFields } from "./removeNullFields.js";
|
|
8
|
+
// Note: this is a work in progress and is not yet complete.
|
|
9
|
+
// Will be exported through the main index.js file once this is complete and fully tested
|
|
10
|
+
export class OpenAIFormat {
|
|
11
|
+
chatWrapper;
|
|
12
|
+
constructor({ chatWrapper }) {
|
|
13
|
+
this.chatWrapper = chatWrapper;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert `node-llama-cpp`'s chat history to OpenAI format.
|
|
17
|
+
*
|
|
18
|
+
* Note that this conversion is lossy, as OpenAI's format is more limited than `node-llama-cpp`'s.
|
|
19
|
+
*/
|
|
20
|
+
toOpenAiChat({ chatHistory, functionCalls, functions, useRawValues = true }) {
|
|
21
|
+
const res = fromChatHistoryToIntermediateOpenAiMessages({
|
|
22
|
+
chatHistory,
|
|
23
|
+
chatWrapperSettings: this.chatWrapper.settings,
|
|
24
|
+
functionCalls,
|
|
25
|
+
functions,
|
|
26
|
+
useRawValues
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
...res,
|
|
30
|
+
messages: fromIntermediateToCompleteOpenAiMessages(res.messages)
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async fromOpenAiChat(options, { llama, model } = {}) {
|
|
34
|
+
const { messages, tools } = options;
|
|
35
|
+
if ((options["response_format"]?.type === "json_schema" || options["response_format"]?.type === "json_object") &&
|
|
36
|
+
tools != null && options["tool_choice"] !== "none")
|
|
37
|
+
throw new Error("Using both JSON response format and tools is not supported yet");
|
|
38
|
+
const { chatHistory, functionCalls: pendingFunctionCalls } = fromOpenAiMessagesToChatHistory({
|
|
39
|
+
messages,
|
|
40
|
+
chatWrapper: this.chatWrapper
|
|
41
|
+
});
|
|
42
|
+
const functions = {};
|
|
43
|
+
for (const tool of tools ?? []) {
|
|
44
|
+
functions[tool.function.name] = {
|
|
45
|
+
description: tool.function.description,
|
|
46
|
+
params: tool.function.parameters
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
let tokenBias;
|
|
50
|
+
if (options["logit_bias"] != null && model != null) {
|
|
51
|
+
tokenBias = TokenBias.for(model);
|
|
52
|
+
for (const [token, bias] of Object.entries(options["logit_bias"]))
|
|
53
|
+
tokenBias.set(token, { logit: bias });
|
|
54
|
+
}
|
|
55
|
+
let grammar;
|
|
56
|
+
if (options["response_format"]?.type === "json_schema" && llama != null) {
|
|
57
|
+
const schema = options["response_format"]?.json_schema?.schema;
|
|
58
|
+
if (schema != null)
|
|
59
|
+
grammar = await llama.createGrammarForJsonSchema(schema);
|
|
60
|
+
else
|
|
61
|
+
grammar = await llama.getGrammarFor("json");
|
|
62
|
+
}
|
|
63
|
+
else if (options["response_format"]?.type === "json_object" && llama != null)
|
|
64
|
+
grammar = await llama.getGrammarFor("json");
|
|
65
|
+
return {
|
|
66
|
+
chatHistory,
|
|
67
|
+
functionCalls: pendingFunctionCalls,
|
|
68
|
+
functions: Object.keys(functions).length === 0
|
|
69
|
+
? undefined
|
|
70
|
+
: functions,
|
|
71
|
+
tokenBias,
|
|
72
|
+
maxTokens: options["max_completion_tokens"] ?? options["max_tokens"] ?? undefined,
|
|
73
|
+
maxParallelFunctionCalls: options["parallel_tool_calls"] === false ? 1 : undefined,
|
|
74
|
+
grammar,
|
|
75
|
+
seed: options.seed ?? undefined,
|
|
76
|
+
customStopTriggers: typeof options.stop === "string"
|
|
77
|
+
? [options.stop]
|
|
78
|
+
: options.stop instanceof Array
|
|
79
|
+
? options.stop.filter((item) => typeof item === "string")
|
|
80
|
+
: undefined,
|
|
81
|
+
temperature: options.temperature ?? undefined,
|
|
82
|
+
minP: options["min_p"] ?? undefined,
|
|
83
|
+
topK: options["top_k"] ?? undefined,
|
|
84
|
+
topP: options["top_p"] ?? undefined
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
export function fromIntermediateToCompleteOpenAiMessages(messages) {
|
|
89
|
+
return messages.map((message) => {
|
|
90
|
+
if (message.content != null && LlamaText.isLlamaText(message.content))
|
|
91
|
+
return {
|
|
92
|
+
...message,
|
|
93
|
+
content: message.content.toString()
|
|
94
|
+
};
|
|
95
|
+
return message;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
export function fromChatHistoryToIntermediateOpenAiMessages({ chatHistory, chatWrapperSettings, functionCalls, functions, useRawValues = true, combineModelMessageAndToolCalls = true, stringifyFunctionParams = true, stringifyFunctionResults = true, squashModelTextResponses = true }) {
|
|
99
|
+
const messages = [];
|
|
100
|
+
for (let i = 0; i < chatHistory.length; i++) {
|
|
101
|
+
const item = chatHistory[i];
|
|
102
|
+
if (item == null)
|
|
103
|
+
continue;
|
|
104
|
+
if (item.type === "system")
|
|
105
|
+
messages.push({
|
|
106
|
+
role: "system",
|
|
107
|
+
content: LlamaText.fromJSON(item.text)
|
|
108
|
+
});
|
|
109
|
+
else if (item.type === "user")
|
|
110
|
+
messages.push({
|
|
111
|
+
role: "user",
|
|
112
|
+
content: item.text
|
|
113
|
+
});
|
|
114
|
+
else if (item.type === "model") {
|
|
115
|
+
let lastModelTextMessage = null;
|
|
116
|
+
const segmentStack = [];
|
|
117
|
+
let canUseLastAssistantMessage = squashModelTextResponses;
|
|
118
|
+
const addResponseText = (text) => {
|
|
119
|
+
const lastResItem = canUseLastAssistantMessage
|
|
120
|
+
? messages.at(-1)
|
|
121
|
+
: undefined;
|
|
122
|
+
if (lastResItem?.role === "assistant" && (lastResItem.tool_calls == null || lastResItem.tool_calls.length === 0)) {
|
|
123
|
+
if (lastResItem.content == null)
|
|
124
|
+
lastResItem.content = text;
|
|
125
|
+
else
|
|
126
|
+
lastResItem.content = LlamaText([lastResItem.content, text]);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
lastModelTextMessage = {
|
|
130
|
+
role: "assistant",
|
|
131
|
+
content: text
|
|
132
|
+
};
|
|
133
|
+
messages.push(lastModelTextMessage);
|
|
134
|
+
canUseLastAssistantMessage = true;
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
for (let j = 0; j < item.response.length; j++) {
|
|
138
|
+
const response = item.response[j];
|
|
139
|
+
if (response == null)
|
|
140
|
+
continue;
|
|
141
|
+
if (typeof response === "string")
|
|
142
|
+
addResponseText(response);
|
|
143
|
+
else if (response.type === "segment") {
|
|
144
|
+
const segmentDefinition = getChatWrapperSegmentDefinition(chatWrapperSettings, response.segmentType);
|
|
145
|
+
if (response.raw != null && useRawValues)
|
|
146
|
+
addResponseText(LlamaText.fromJSON(response.raw));
|
|
147
|
+
else
|
|
148
|
+
addResponseText(LlamaText([
|
|
149
|
+
(segmentStack.length > 0 && segmentStack.at(-1) === response.segmentType)
|
|
150
|
+
? ""
|
|
151
|
+
: segmentDefinition?.prefix ?? "",
|
|
152
|
+
response.text,
|
|
153
|
+
response.ended
|
|
154
|
+
? (segmentDefinition?.suffix ?? "")
|
|
155
|
+
: ""
|
|
156
|
+
]));
|
|
157
|
+
if (!response.ended && segmentStack.at(-1) !== response.segmentType)
|
|
158
|
+
segmentStack.push(response.segmentType);
|
|
159
|
+
else if (response.ended && segmentStack.at(-1) === response.segmentType) {
|
|
160
|
+
segmentStack.pop();
|
|
161
|
+
if (segmentStack.length === 0 && segmentDefinition?.suffix == null &&
|
|
162
|
+
chatWrapperSettings.segments?.closeAllSegments != null)
|
|
163
|
+
addResponseText(LlamaText(chatWrapperSettings.segments.closeAllSegments));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (response.type === "functionCall") {
|
|
167
|
+
const toolCallId = generateToolCallId(i, j);
|
|
168
|
+
if (lastModelTextMessage == null ||
|
|
169
|
+
(!combineModelMessageAndToolCalls && lastModelTextMessage.content != null && lastModelTextMessage.content !== "") ||
|
|
170
|
+
(response.startsNewChunk &&
|
|
171
|
+
lastModelTextMessage.tool_calls != null && lastModelTextMessage.tool_calls.length > 0)) {
|
|
172
|
+
lastModelTextMessage = {
|
|
173
|
+
role: "assistant"
|
|
174
|
+
};
|
|
175
|
+
messages.push(lastModelTextMessage);
|
|
176
|
+
}
|
|
177
|
+
lastModelTextMessage["tool_calls"] ||= [];
|
|
178
|
+
lastModelTextMessage["tool_calls"].push({
|
|
179
|
+
id: toolCallId,
|
|
180
|
+
type: "function",
|
|
181
|
+
function: {
|
|
182
|
+
name: response.name,
|
|
183
|
+
arguments: stringifyFunctionParams
|
|
184
|
+
? response.params === undefined
|
|
185
|
+
? ""
|
|
186
|
+
: jsonDumps(response.params)
|
|
187
|
+
: response.params
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
messages.push({
|
|
191
|
+
role: "tool",
|
|
192
|
+
"tool_call_id": toolCallId,
|
|
193
|
+
content: stringifyFunctionResults
|
|
194
|
+
? response.result === undefined
|
|
195
|
+
? ""
|
|
196
|
+
: jsonDumps(response.result)
|
|
197
|
+
: response.result
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
addResponseText("");
|
|
202
|
+
}
|
|
203
|
+
else
|
|
204
|
+
void item;
|
|
205
|
+
}
|
|
206
|
+
if (functionCalls != null && functionCalls.length > 0) {
|
|
207
|
+
let modelMessage = messages.at(-1);
|
|
208
|
+
const messageIndex = chatHistory.length - 1;
|
|
209
|
+
const functionCallStartIndex = modelMessage?.role === "assistant"
|
|
210
|
+
? (modelMessage.tool_calls?.length ?? 0)
|
|
211
|
+
: 0;
|
|
212
|
+
if (modelMessage?.role !== "assistant" ||
|
|
213
|
+
(!combineModelMessageAndToolCalls && modelMessage.content != null && modelMessage.content !== "")) {
|
|
214
|
+
modelMessage = {
|
|
215
|
+
role: "assistant"
|
|
216
|
+
};
|
|
217
|
+
messages.push(modelMessage);
|
|
218
|
+
}
|
|
219
|
+
modelMessage["tool_calls"] ||= [];
|
|
220
|
+
for (let i = 0; i < functionCalls.length; i++) {
|
|
221
|
+
const functionCall = functionCalls[i];
|
|
222
|
+
if (functionCall == null)
|
|
223
|
+
continue;
|
|
224
|
+
const toolCallId = generateToolCallId(messageIndex, functionCallStartIndex + i);
|
|
225
|
+
modelMessage["tool_calls"].push({
|
|
226
|
+
id: toolCallId,
|
|
227
|
+
type: "function",
|
|
228
|
+
function: {
|
|
229
|
+
name: functionCall.functionName,
|
|
230
|
+
arguments: stringifyFunctionParams
|
|
231
|
+
? functionCall.params === undefined
|
|
232
|
+
? ""
|
|
233
|
+
: jsonDumps(functionCall.params)
|
|
234
|
+
: functionCall.params
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
const tools = [];
|
|
240
|
+
for (const [funcName, func] of Object.entries(functions ?? {}))
|
|
241
|
+
tools.push({
|
|
242
|
+
type: "function",
|
|
243
|
+
function: {
|
|
244
|
+
name: funcName,
|
|
245
|
+
...removeUndefinedFields({
|
|
246
|
+
description: func.description,
|
|
247
|
+
parameters: func.params
|
|
248
|
+
})
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
return removeUndefinedFields({
|
|
252
|
+
messages,
|
|
253
|
+
tools: tools.length > 0
|
|
254
|
+
? tools
|
|
255
|
+
: undefined
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
function fromOpenAiMessagesToChatHistory({ messages, chatWrapper }) {
|
|
259
|
+
const chatHistory = [];
|
|
260
|
+
const pendingFunctionCalls = [];
|
|
261
|
+
const findToolCallResult = (startIndex, toolCallId, toolCallIndex) => {
|
|
262
|
+
let foundToolIndex = 0;
|
|
263
|
+
for (let i = startIndex; i < messages.length; i++) {
|
|
264
|
+
const message = messages[i];
|
|
265
|
+
if (message == null)
|
|
266
|
+
continue;
|
|
267
|
+
if (message.role === "user" || message.role === "assistant")
|
|
268
|
+
break;
|
|
269
|
+
if (message.role !== "tool")
|
|
270
|
+
continue;
|
|
271
|
+
if (toolCallId == null) {
|
|
272
|
+
if (toolCallIndex === foundToolIndex)
|
|
273
|
+
return message;
|
|
274
|
+
else if (foundToolIndex > foundToolIndex)
|
|
275
|
+
return undefined;
|
|
276
|
+
}
|
|
277
|
+
else if (message?.tool_call_id === toolCallId)
|
|
278
|
+
return message;
|
|
279
|
+
foundToolIndex++;
|
|
280
|
+
}
|
|
281
|
+
return undefined;
|
|
282
|
+
};
|
|
283
|
+
let lastUserOrAssistantMessageIndex = messages.length - 1;
|
|
284
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
285
|
+
const message = messages[i];
|
|
286
|
+
if (message == null)
|
|
287
|
+
continue;
|
|
288
|
+
if (message.role === "user" || message.role === "assistant") {
|
|
289
|
+
lastUserOrAssistantMessageIndex = i;
|
|
290
|
+
break;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
for (let i = 0; i < messages.length; i++) {
|
|
294
|
+
const message = messages[i];
|
|
295
|
+
if (message == null)
|
|
296
|
+
continue;
|
|
297
|
+
if (message.role === "system") {
|
|
298
|
+
if (message.content != null)
|
|
299
|
+
chatHistory.push({
|
|
300
|
+
type: "system",
|
|
301
|
+
text: LlamaText(resolveOpenAiText(message.content)).toJSON()
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
else if (message.role === "user")
|
|
305
|
+
chatHistory.push({
|
|
306
|
+
type: "user",
|
|
307
|
+
text: resolveOpenAiText(message.content) ?? ""
|
|
308
|
+
});
|
|
309
|
+
else if (message.role === "assistant") {
|
|
310
|
+
const isLastAssistantMessage = i === lastUserOrAssistantMessageIndex;
|
|
311
|
+
let chatItem = chatHistory.at(-1);
|
|
312
|
+
if (chatItem?.type !== "model") {
|
|
313
|
+
chatItem = {
|
|
314
|
+
type: "model",
|
|
315
|
+
response: []
|
|
316
|
+
};
|
|
317
|
+
chatHistory.push(chatItem);
|
|
318
|
+
}
|
|
319
|
+
const text = resolveOpenAiText(message.content);
|
|
320
|
+
if (text != null && text !== "") {
|
|
321
|
+
const segmentDefinitions = new Map();
|
|
322
|
+
for (const segmentType of allSegmentTypes) {
|
|
323
|
+
const segmentDefinition = getChatWrapperSegmentDefinition(chatWrapper.settings, segmentType);
|
|
324
|
+
if (segmentDefinition != null)
|
|
325
|
+
segmentDefinitions.set(segmentType, {
|
|
326
|
+
prefix: LlamaText(segmentDefinition.prefix).toString(),
|
|
327
|
+
suffix: segmentDefinition.suffix != null
|
|
328
|
+
? LlamaText(segmentDefinition.suffix).toString()
|
|
329
|
+
: undefined
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
const modelResponseSegments = segmentModelResponseText(text, {
|
|
333
|
+
segmentDefinitions,
|
|
334
|
+
closeAllSegments: chatWrapper.settings.segments?.closeAllSegments != null
|
|
335
|
+
? LlamaText(chatWrapper.settings.segments.closeAllSegments).toString()
|
|
336
|
+
: undefined
|
|
337
|
+
});
|
|
338
|
+
for (const segment of modelResponseSegments) {
|
|
339
|
+
if (segment.type == null) {
|
|
340
|
+
if (typeof chatItem.response.at(-1) === "string")
|
|
341
|
+
chatItem.response[chatItem.response.length - 1] += segment.text;
|
|
342
|
+
else
|
|
343
|
+
chatItem.response.push(segment.text);
|
|
344
|
+
}
|
|
345
|
+
else
|
|
346
|
+
chatItem.response.push({
|
|
347
|
+
type: "segment",
|
|
348
|
+
segmentType: segment.type,
|
|
349
|
+
text: segment.text,
|
|
350
|
+
ended: segment.ended
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
let toolCallIndex = 0;
|
|
355
|
+
for (const toolCall of message.tool_calls ?? []) {
|
|
356
|
+
const functionName = toolCall.function.name;
|
|
357
|
+
const callParams = parseToolSerializedValue(toolCall.function.arguments);
|
|
358
|
+
const toolCallResult = findToolCallResult(i + 1, toolCall.id, toolCallIndex);
|
|
359
|
+
if (toolCallResult == null) {
|
|
360
|
+
pendingFunctionCalls.push({
|
|
361
|
+
functionName,
|
|
362
|
+
params: callParams,
|
|
363
|
+
raw: chatWrapper.generateFunctionCall(functionName, callParams).toJSON()
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (toolCallResult != null || !isLastAssistantMessage)
|
|
367
|
+
chatItem.response.push({
|
|
368
|
+
type: "functionCall",
|
|
369
|
+
name: functionName,
|
|
370
|
+
params: callParams,
|
|
371
|
+
result: parseToolSerializedValue(toolCallResult?.content),
|
|
372
|
+
startsNewChunk: toolCallIndex === 0
|
|
373
|
+
? true
|
|
374
|
+
: undefined
|
|
375
|
+
});
|
|
376
|
+
toolCallIndex++;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
chatHistory,
|
|
382
|
+
functionCalls: pendingFunctionCalls
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function generateToolCallId(messageIndex, callIndex) {
|
|
386
|
+
const length = 9;
|
|
387
|
+
const start = "fc_" + String(messageIndex) + "_";
|
|
388
|
+
return start + String(callIndex).padStart(length - start.length, "0");
|
|
389
|
+
}
|
|
390
|
+
export function resolveOpenAiText(text) {
|
|
391
|
+
if (typeof text === "string")
|
|
392
|
+
return text;
|
|
393
|
+
if (text instanceof Array)
|
|
394
|
+
return text.map((item) => item?.text ?? "").join("");
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
function parseToolSerializedValue(value) {
|
|
398
|
+
const text = resolveOpenAiText(value);
|
|
399
|
+
if (text == null || text === "")
|
|
400
|
+
return undefined;
|
|
401
|
+
try {
|
|
402
|
+
return JSON.parse(text);
|
|
403
|
+
}
|
|
404
|
+
catch (err) {
|
|
405
|
+
return text;
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
function segmentModelResponseText(text, { segmentDefinitions, closeAllSegments }) {
|
|
409
|
+
const separatorActions = new Map();
|
|
410
|
+
for (const [segmentType, { prefix, suffix }] of segmentDefinitions) {
|
|
411
|
+
separatorActions.set(prefix, { type: "prefix", segmentType });
|
|
412
|
+
if (suffix != null)
|
|
413
|
+
separatorActions.set(suffix, { type: "suffix", segmentType });
|
|
414
|
+
}
|
|
415
|
+
if (closeAllSegments != null)
|
|
416
|
+
separatorActions.set(closeAllSegments, { type: "closeAll" });
|
|
417
|
+
const textParts = splitText(text, [...separatorActions.keys()]);
|
|
418
|
+
const segments = [];
|
|
419
|
+
const stack = [];
|
|
420
|
+
const stackSet = new Set();
|
|
421
|
+
const pushTextToLastSegment = (text) => {
|
|
422
|
+
const lastSegment = segments.at(-1);
|
|
423
|
+
if (lastSegment != null && !lastSegment.ended)
|
|
424
|
+
lastSegment.text += text;
|
|
425
|
+
else
|
|
426
|
+
segments.push({
|
|
427
|
+
type: undefined,
|
|
428
|
+
text,
|
|
429
|
+
ended: false
|
|
430
|
+
});
|
|
431
|
+
};
|
|
432
|
+
for (const item of textParts) {
|
|
433
|
+
if (typeof item === "string" || !separatorActions.has(item.separator))
|
|
434
|
+
pushTextToLastSegment(typeof item === "string"
|
|
435
|
+
? item
|
|
436
|
+
: item.separator);
|
|
437
|
+
else {
|
|
438
|
+
const action = separatorActions.get(item.separator);
|
|
439
|
+
if (action.type === "closeAll") {
|
|
440
|
+
while (stack.length > 0) {
|
|
441
|
+
const segmentType = stack.pop();
|
|
442
|
+
stackSet.delete(segmentType);
|
|
443
|
+
const lastSegment = segments.at(-1);
|
|
444
|
+
if (lastSegment != null && lastSegment.type != undefined && lastSegment.type === segmentType)
|
|
445
|
+
lastSegment.ended = true;
|
|
446
|
+
else
|
|
447
|
+
segments.push({ type: segmentType, text: "", ended: true });
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
else if (action.type === "prefix") {
|
|
451
|
+
if (!stackSet.has(action.segmentType)) {
|
|
452
|
+
stack.push(action.segmentType);
|
|
453
|
+
stackSet.add(action.segmentType);
|
|
454
|
+
segments.push({ type: action.segmentType, text: "", ended: false });
|
|
455
|
+
}
|
|
456
|
+
else
|
|
457
|
+
pushTextToLastSegment(item.separator);
|
|
458
|
+
}
|
|
459
|
+
else if (action.type === "suffix") {
|
|
460
|
+
const currentType = stack.at(-1);
|
|
461
|
+
if (currentType != null && currentType === action.segmentType) {
|
|
462
|
+
const lastSegment = segments.at(-1);
|
|
463
|
+
if (lastSegment != null && lastSegment.type != null && lastSegment.type === action.segmentType) {
|
|
464
|
+
lastSegment.ended = true;
|
|
465
|
+
stack.pop();
|
|
466
|
+
stackSet.delete(action.segmentType);
|
|
467
|
+
}
|
|
468
|
+
else
|
|
469
|
+
segments.push({ type: action.segmentType, text: "", ended: true });
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
const segmentTypeIndex = stack.lastIndexOf(action.segmentType);
|
|
473
|
+
if (segmentTypeIndex < 0)
|
|
474
|
+
pushTextToLastSegment(item.separator);
|
|
475
|
+
else {
|
|
476
|
+
for (let i = stack.length - 1; i >= segmentTypeIndex; i--) {
|
|
477
|
+
const segmentType = stack.pop();
|
|
478
|
+
stackSet.delete(segmentType);
|
|
479
|
+
segments.push({ type: segmentType, text: "", ended: true });
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
return segments;
|
|
487
|
+
}
|
|
488
|
+
//# sourceMappingURL=OpenAIFormat.js.map
|