@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.
Files changed (876) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +108 -0
  3. package/dist/ChatWrapper.d.ts +27 -0
  4. package/dist/ChatWrapper.js +233 -0
  5. package/dist/ChatWrapper.js.map +1 -0
  6. package/dist/apiDocsIndex.d.ts +1 -0
  7. package/dist/apiDocsIndex.js +7 -0
  8. package/dist/apiDocsIndex.js.map +1 -0
  9. package/dist/bindings/AddonTypes.d.ts +203 -0
  10. package/dist/bindings/AddonTypes.js +2 -0
  11. package/dist/bindings/AddonTypes.js.map +1 -0
  12. package/dist/bindings/Llama.d.ts +104 -0
  13. package/dist/bindings/Llama.js +570 -0
  14. package/dist/bindings/Llama.js.map +1 -0
  15. package/dist/bindings/consts.d.ts +2 -0
  16. package/dist/bindings/consts.js +13 -0
  17. package/dist/bindings/consts.js.map +1 -0
  18. package/dist/bindings/getLlama.d.ts +297 -0
  19. package/dist/bindings/getLlama.js +569 -0
  20. package/dist/bindings/getLlama.js.map +1 -0
  21. package/dist/bindings/types.d.ts +72 -0
  22. package/dist/bindings/types.js +105 -0
  23. package/dist/bindings/types.js.map +1 -0
  24. package/dist/bindings/utils/MemoryOrchestrator.d.ts +23 -0
  25. package/dist/bindings/utils/MemoryOrchestrator.js +50 -0
  26. package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
  27. package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
  28. package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
  29. package/dist/bindings/utils/NoBinaryFoundError.js.map +1 -0
  30. package/dist/bindings/utils/asyncEvery.d.ts +5 -0
  31. package/dist/bindings/utils/asyncEvery.js +15 -0
  32. package/dist/bindings/utils/asyncEvery.js.map +1 -0
  33. package/dist/bindings/utils/asyncSome.d.ts +5 -0
  34. package/dist/bindings/utils/asyncSome.js +29 -0
  35. package/dist/bindings/utils/asyncSome.js.map +1 -0
  36. package/dist/bindings/utils/binariesGithubRelease.d.ts +6 -0
  37. package/dist/bindings/utils/binariesGithubRelease.js +15 -0
  38. package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
  39. package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
  40. package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
  41. package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
  42. package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
  43. package/dist/bindings/utils/cloneLlamaCppRepo.js +166 -0
  44. package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
  45. package/dist/bindings/utils/compileLLamaCpp.d.ts +22 -0
  46. package/dist/bindings/utils/compileLLamaCpp.js +526 -0
  47. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
  48. package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +18 -0
  49. package/dist/bindings/utils/detectAvailableComputeLayers.js +311 -0
  50. package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
  51. package/dist/bindings/utils/detectBuildTools.d.ts +14 -0
  52. package/dist/bindings/utils/detectBuildTools.js +149 -0
  53. package/dist/bindings/utils/detectBuildTools.js.map +1 -0
  54. package/dist/bindings/utils/detectGlibc.d.ts +4 -0
  55. package/dist/bindings/utils/detectGlibc.js +74 -0
  56. package/dist/bindings/utils/detectGlibc.js.map +1 -0
  57. package/dist/bindings/utils/disposeBeforeExit.d.ts +8 -0
  58. package/dist/bindings/utils/disposeBeforeExit.js +36 -0
  59. package/dist/bindings/utils/disposeBeforeExit.js.map +1 -0
  60. package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
  61. package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
  62. package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
  63. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.d.ts +6 -0
  64. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +105 -0
  65. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
  66. package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
  67. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
  68. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
  69. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
  70. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
  71. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
  72. package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
  73. package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
  74. package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
  75. package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
  76. package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
  77. package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
  78. package/dist/bindings/utils/getLlamaGpuTypes.d.ts +13 -0
  79. package/dist/bindings/utils/getLlamaGpuTypes.js +36 -0
  80. package/dist/bindings/utils/getLlamaGpuTypes.js.map +1 -0
  81. package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
  82. package/dist/bindings/utils/getLlamaWithoutBackend.js +40 -0
  83. package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
  84. package/dist/bindings/utils/getPlatform.d.ts +2 -0
  85. package/dist/bindings/utils/getPlatform.js +15 -0
  86. package/dist/bindings/utils/getPlatform.js.map +1 -0
  87. package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
  88. package/dist/bindings/utils/getPlatformInfo.js +28 -0
  89. package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
  90. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
  91. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
  92. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
  93. package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
  94. package/dist/bindings/utils/hasFileInPath.js +34 -0
  95. package/dist/bindings/utils/hasFileInPath.js.map +1 -0
  96. package/dist/bindings/utils/lastBuildInfo.d.ts +6 -0
  97. package/dist/bindings/utils/lastBuildInfo.js +17 -0
  98. package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
  99. package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
  100. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +22 -0
  101. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
  102. package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
  103. package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
  104. package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
  105. package/dist/bindings/utils/resolveActualBindingBinaryPath.d.ts +1 -0
  106. package/dist/bindings/utils/resolveActualBindingBinaryPath.js +18 -0
  107. package/dist/bindings/utils/resolveActualBindingBinaryPath.js.map +1 -0
  108. package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
  109. package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
  110. package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
  111. package/dist/bindings/utils/testBindingBinary.d.ts +2 -0
  112. package/dist/bindings/utils/testBindingBinary.js +269 -0
  113. package/dist/bindings/utils/testBindingBinary.js.map +1 -0
  114. package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
  115. package/dist/bindings/utils/testCmakeBinary.js +32 -0
  116. package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
  117. package/dist/chatWrappers/AlpacaChatWrapper.d.ts +17 -0
  118. package/dist/chatWrappers/AlpacaChatWrapper.js +33 -0
  119. package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
  120. package/dist/chatWrappers/ChatMLChatWrapper.d.ts +6 -0
  121. package/dist/chatWrappers/ChatMLChatWrapper.js +85 -0
  122. package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
  123. package/dist/chatWrappers/DeepSeekChatWrapper.d.ts +37 -0
  124. package/dist/chatWrappers/DeepSeekChatWrapper.js +294 -0
  125. package/dist/chatWrappers/DeepSeekChatWrapper.js.map +1 -0
  126. package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
  127. package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
  128. package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
  129. package/dist/chatWrappers/FalconChatWrapper.d.ts +19 -0
  130. package/dist/chatWrappers/FalconChatWrapper.js +126 -0
  131. package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
  132. package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +17 -0
  133. package/dist/chatWrappers/FunctionaryChatWrapper.js +622 -0
  134. package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
  135. package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
  136. package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
  137. package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
  138. package/dist/chatWrappers/GeneralChatWrapper.d.ts +19 -0
  139. package/dist/chatWrappers/GeneralChatWrapper.js +140 -0
  140. package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
  141. package/dist/chatWrappers/HarmonyChatWrapper.d.ts +78 -0
  142. package/dist/chatWrappers/HarmonyChatWrapper.js +539 -0
  143. package/dist/chatWrappers/HarmonyChatWrapper.js.map +1 -0
  144. package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
  145. package/dist/chatWrappers/Llama2ChatWrapper.js +95 -0
  146. package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
  147. package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
  148. package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
  149. package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
  150. package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +32 -0
  151. package/dist/chatWrappers/Llama3_1ChatWrapper.js +290 -0
  152. package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
  153. package/dist/chatWrappers/Llama3_2LightweightChatWrapper.d.ts +35 -0
  154. package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js +264 -0
  155. package/dist/chatWrappers/Llama3_2LightweightChatWrapper.js.map +1 -0
  156. package/dist/chatWrappers/MistralChatWrapper.d.ts +16 -0
  157. package/dist/chatWrappers/MistralChatWrapper.js +180 -0
  158. package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
  159. package/dist/chatWrappers/QwenChatWrapper.d.ts +36 -0
  160. package/dist/chatWrappers/QwenChatWrapper.js +344 -0
  161. package/dist/chatWrappers/QwenChatWrapper.js.map +1 -0
  162. package/dist/chatWrappers/SeedChatWrapper.d.ts +25 -0
  163. package/dist/chatWrappers/SeedChatWrapper.js +183 -0
  164. package/dist/chatWrappers/SeedChatWrapper.js.map +1 -0
  165. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +138 -0
  166. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +665 -0
  167. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
  168. package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +76 -0
  169. package/dist/chatWrappers/generic/TemplateChatWrapper.js +212 -0
  170. package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
  171. package/dist/chatWrappers/generic/utils/UniqueIdGenerator.d.ts +7 -0
  172. package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js +30 -0
  173. package/dist/chatWrappers/generic/utils/UniqueIdGenerator.js.map +1 -0
  174. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +24 -0
  175. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
  176. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
  177. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.d.ts +25 -0
  178. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js +690 -0
  179. package/dist/chatWrappers/generic/utils/extractFunctionCallSettingsFromJinjaTemplate.js.map +1 -0
  180. package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.d.ts +2 -0
  181. package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js +66 -0
  182. package/dist/chatWrappers/generic/utils/extractSegmentSettingsFromTokenizerAndChatTemplate.js.map +1 -0
  183. package/dist/chatWrappers/generic/utils/getFirstValidResult.d.ts +6 -0
  184. package/dist/chatWrappers/generic/utils/getFirstValidResult.js +19 -0
  185. package/dist/chatWrappers/generic/utils/getFirstValidResult.js.map +1 -0
  186. package/dist/chatWrappers/generic/utils/squashChatHistoryItems.d.ts +2 -0
  187. package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js +35 -0
  188. package/dist/chatWrappers/generic/utils/squashChatHistoryItems.js.map +1 -0
  189. package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.d.ts +22 -0
  190. package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js +28 -0
  191. package/dist/chatWrappers/generic/utils/templateSegmentOptionsToChatWrapperSettings.js.map +1 -0
  192. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +76 -0
  193. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +177 -0
  194. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
  195. package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
  196. package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
  197. package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
  198. package/dist/chatWrappers/utils/getModelLinageNames.d.ts +2 -0
  199. package/dist/chatWrappers/utils/getModelLinageNames.js +18 -0
  200. package/dist/chatWrappers/utils/getModelLinageNames.js.map +1 -0
  201. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
  202. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +394 -0
  203. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
  204. package/dist/chatWrappers/utils/isLlama3_2LightweightModel.d.ts +2 -0
  205. package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js +9 -0
  206. package/dist/chatWrappers/utils/isLlama3_2LightweightModel.js.map +1 -0
  207. package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
  208. package/dist/chatWrappers/utils/jsonDumps.js +18 -0
  209. package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
  210. package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +148 -0
  211. package/dist/chatWrappers/utils/resolveChatWrapper.js +325 -0
  212. package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
  213. package/dist/cli/cli.d.ts +2 -0
  214. package/dist/cli/cli.js +45 -0
  215. package/dist/cli/cli.js.map +1 -0
  216. package/dist/cli/commands/ChatCommand.d.ts +59 -0
  217. package/dist/cli/commands/ChatCommand.js +856 -0
  218. package/dist/cli/commands/ChatCommand.js.map +1 -0
  219. package/dist/cli/commands/CompleteCommand.d.ts +47 -0
  220. package/dist/cli/commands/CompleteCommand.js +658 -0
  221. package/dist/cli/commands/CompleteCommand.js.map +1 -0
  222. package/dist/cli/commands/DebugCommand.d.ts +7 -0
  223. package/dist/cli/commands/DebugCommand.js +55 -0
  224. package/dist/cli/commands/DebugCommand.js.map +1 -0
  225. package/dist/cli/commands/InfillCommand.d.ts +49 -0
  226. package/dist/cli/commands/InfillCommand.js +693 -0
  227. package/dist/cli/commands/InfillCommand.js.map +1 -0
  228. package/dist/cli/commands/InitCommand.d.ts +12 -0
  229. package/dist/cli/commands/InitCommand.js +230 -0
  230. package/dist/cli/commands/InitCommand.js.map +1 -0
  231. package/dist/cli/commands/OnPostInstallCommand.d.ts +4 -0
  232. package/dist/cli/commands/OnPostInstallCommand.js +62 -0
  233. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -0
  234. package/dist/cli/commands/PullCommand.d.ts +13 -0
  235. package/dist/cli/commands/PullCommand.js +158 -0
  236. package/dist/cli/commands/PullCommand.js.map +1 -0
  237. package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
  238. package/dist/cli/commands/inspect/InspectCommand.js +21 -0
  239. package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
  240. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +17 -0
  241. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +275 -0
  242. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
  243. package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +13 -0
  244. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +230 -0
  245. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
  246. package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
  247. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +296 -0
  248. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
  249. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +26 -0
  250. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +869 -0
  251. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
  252. package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
  253. package/dist/cli/commands/source/SourceCommand.js +19 -0
  254. package/dist/cli/commands/source/SourceCommand.js.map +1 -0
  255. package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
  256. package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
  257. package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
  258. package/dist/cli/commands/source/commands/ClearCommand.d.ts +7 -0
  259. package/dist/cli/commands/source/commands/ClearCommand.js +54 -0
  260. package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
  261. package/dist/cli/commands/source/commands/DownloadCommand.d.ts +16 -0
  262. package/dist/cli/commands/source/commands/DownloadCommand.js +219 -0
  263. package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
  264. package/dist/cli/projectTemplates.d.ts +7 -0
  265. package/dist/cli/projectTemplates.js +10 -0
  266. package/dist/cli/projectTemplates.js.map +1 -0
  267. package/dist/cli/recommendedModels.d.ts +2 -0
  268. package/dist/cli/recommendedModels.js +428 -0
  269. package/dist/cli/recommendedModels.js.map +1 -0
  270. package/dist/cli/startCreateCli.d.ts +2 -0
  271. package/dist/cli/startCreateCli.js +26 -0
  272. package/dist/cli/startCreateCli.js.map +1 -0
  273. package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
  274. package/dist/cli/utils/ConsoleInteraction.js +122 -0
  275. package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
  276. package/dist/cli/utils/ConsoleTable.d.ts +24 -0
  277. package/dist/cli/utils/ConsoleTable.js +90 -0
  278. package/dist/cli/utils/ConsoleTable.js.map +1 -0
  279. package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
  280. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
  281. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
  282. package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
  283. package/dist/cli/utils/consolePromptQuestion.js +81 -0
  284. package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
  285. package/dist/cli/utils/getReadablePath.d.ts +1 -0
  286. package/dist/cli/utils/getReadablePath.js +14 -0
  287. package/dist/cli/utils/getReadablePath.js.map +1 -0
  288. package/dist/cli/utils/interactivelyAskForModel.d.ts +13 -0
  289. package/dist/cli/utils/interactivelyAskForModel.js +485 -0
  290. package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
  291. package/dist/cli/utils/isRunningUnderRosetta.d.ts +1 -0
  292. package/dist/cli/utils/isRunningUnderRosetta.js +20 -0
  293. package/dist/cli/utils/isRunningUnderRosetta.js.map +1 -0
  294. package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
  295. package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
  296. package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
  297. package/dist/cli/utils/packageJsonConfig.d.ts +6 -0
  298. package/dist/cli/utils/packageJsonConfig.js +51 -0
  299. package/dist/cli/utils/packageJsonConfig.js.map +1 -0
  300. package/dist/cli/utils/packageManager.d.ts +1 -0
  301. package/dist/cli/utils/packageManager.js +15 -0
  302. package/dist/cli/utils/packageManager.js.map +1 -0
  303. package/dist/cli/utils/parseXtcArg.d.ts +5 -0
  304. package/dist/cli/utils/parseXtcArg.js +16 -0
  305. package/dist/cli/utils/parseXtcArg.js.map +1 -0
  306. package/dist/cli/utils/printCommonInfoLines.d.ts +12 -0
  307. package/dist/cli/utils/printCommonInfoLines.js +163 -0
  308. package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
  309. package/dist/cli/utils/printInfoLine.d.ts +12 -0
  310. package/dist/cli/utils/printInfoLine.js +54 -0
  311. package/dist/cli/utils/printInfoLine.js.map +1 -0
  312. package/dist/cli/utils/printModelDestination.d.ts +2 -0
  313. package/dist/cli/utils/printModelDestination.js +11 -0
  314. package/dist/cli/utils/printModelDestination.js.map +1 -0
  315. package/dist/cli/utils/projectTemplates.d.ts +19 -0
  316. package/dist/cli/utils/projectTemplates.js +47 -0
  317. package/dist/cli/utils/projectTemplates.js.map +1 -0
  318. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
  319. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
  320. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
  321. package/dist/cli/utils/resolveCommandGgufPath.d.ts +19 -0
  322. package/dist/cli/utils/resolveCommandGgufPath.js +123 -0
  323. package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
  324. package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
  325. package/dist/cli/utils/resolveHeaderFlag.js +21 -0
  326. package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
  327. package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +14 -0
  328. package/dist/cli/utils/resolveModelRecommendationFileOptions.js +12 -0
  329. package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
  330. package/dist/cli/utils/resolveNpmrcConfig.d.ts +18 -0
  331. package/dist/cli/utils/resolveNpmrcConfig.js +129 -0
  332. package/dist/cli/utils/resolveNpmrcConfig.js.map +1 -0
  333. package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
  334. package/dist/cli/utils/splitAnsiToLines.js +32 -0
  335. package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
  336. package/dist/cli/utils/toBytes.d.ts +1 -0
  337. package/dist/cli/utils/toBytes.js +5 -0
  338. package/dist/cli/utils/toBytes.js.map +1 -0
  339. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
  340. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
  341. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
  342. package/dist/commands.d.ts +6 -0
  343. package/dist/commands.js +9 -0
  344. package/dist/commands.js.map +1 -0
  345. package/dist/config.d.ts +79 -0
  346. package/dist/config.js +127 -0
  347. package/dist/config.js.map +1 -0
  348. package/dist/consts.d.ts +4 -0
  349. package/dist/consts.js +11 -0
  350. package/dist/consts.js.map +1 -0
  351. package/dist/evaluator/LlamaChat/LlamaChat.d.ts +500 -0
  352. package/dist/evaluator/LlamaChat/LlamaChat.js +2696 -0
  353. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
  354. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
  355. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
  356. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
  357. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
  358. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
  359. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
  360. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
  361. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
  362. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
  363. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.d.ts +16 -0
  364. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +260 -0
  365. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
  366. package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +520 -0
  367. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +628 -0
  368. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
  369. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +45 -0
  370. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +191 -0
  371. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
  372. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +15 -0
  373. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +16 -0
  374. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
  375. package/dist/evaluator/LlamaCompletion.d.ts +219 -0
  376. package/dist/evaluator/LlamaCompletion.js +498 -0
  377. package/dist/evaluator/LlamaCompletion.js.map +1 -0
  378. package/dist/evaluator/LlamaContext/LlamaContext.d.ts +336 -0
  379. package/dist/evaluator/LlamaContext/LlamaContext.js +1919 -0
  380. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
  381. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.d.ts +27 -0
  382. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js +130 -0
  383. package/dist/evaluator/LlamaContext/LlamaContextSequenceCheckpoints.js.map +1 -0
  384. package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
  385. package/dist/evaluator/LlamaContext/LlamaSampler.js +39 -0
  386. package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
  387. package/dist/evaluator/LlamaContext/TokenPredictor.d.ts +55 -0
  388. package/dist/evaluator/LlamaContext/TokenPredictor.js +20 -0
  389. package/dist/evaluator/LlamaContext/TokenPredictor.js.map +1 -0
  390. package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.d.ts +56 -0
  391. package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js +266 -0
  392. package/dist/evaluator/LlamaContext/tokenPredictors/DraftSequenceTokenPredictor.js.map +1 -0
  393. package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.d.ts +58 -0
  394. package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js +138 -0
  395. package/dist/evaluator/LlamaContext/tokenPredictors/InputLookupTokenPredictor.js.map +1 -0
  396. package/dist/evaluator/LlamaContext/types.d.ts +602 -0
  397. package/dist/evaluator/LlamaContext/types.js +2 -0
  398. package/dist/evaluator/LlamaContext/types.js.map +1 -0
  399. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.d.ts +5 -0
  400. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js +16 -0
  401. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
  402. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.d.ts +5 -0
  403. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js +42 -0
  404. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
  405. package/dist/evaluator/LlamaContext/utils/padSafeContextSize.d.ts +1 -0
  406. package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js +18 -0
  407. package/dist/evaluator/LlamaContext/utils/padSafeContextSize.js.map +1 -0
  408. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
  409. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js +13 -0
  410. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
  411. package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
  412. package/dist/evaluator/LlamaEmbedding.js +53 -0
  413. package/dist/evaluator/LlamaEmbedding.js.map +1 -0
  414. package/dist/evaluator/LlamaEmbeddingContext.d.ts +52 -0
  415. package/dist/evaluator/LlamaEmbeddingContext.js +86 -0
  416. package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
  417. package/dist/evaluator/LlamaGrammar.d.ts +39 -0
  418. package/dist/evaluator/LlamaGrammar.js +72 -0
  419. package/dist/evaluator/LlamaGrammar.js.map +1 -0
  420. package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +19 -0
  421. package/dist/evaluator/LlamaGrammarEvaluationState.js +29 -0
  422. package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
  423. package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +17 -0
  424. package/dist/evaluator/LlamaJsonSchemaGrammar.js +35 -0
  425. package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
  426. package/dist/evaluator/LlamaModel/LlamaModel.d.ts +344 -0
  427. package/dist/evaluator/LlamaModel/LlamaModel.js +853 -0
  428. package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
  429. package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
  430. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
  431. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
  432. package/dist/evaluator/LlamaRankingContext.d.ts +91 -0
  433. package/dist/evaluator/LlamaRankingContext.js +178 -0
  434. package/dist/evaluator/LlamaRankingContext.js.map +1 -0
  435. package/dist/evaluator/TokenBias.d.ts +37 -0
  436. package/dist/evaluator/TokenBias.js +68 -0
  437. package/dist/evaluator/TokenBias.js.map +1 -0
  438. package/dist/evaluator/TokenMeter.d.ts +45 -0
  439. package/dist/evaluator/TokenMeter.js +74 -0
  440. package/dist/evaluator/TokenMeter.js.map +1 -0
  441. package/dist/evaluator/utils/chunkDocument.d.ts +86 -0
  442. package/dist/evaluator/utils/chunkDocument.js +212 -0
  443. package/dist/evaluator/utils/chunkDocument.js.map +1 -0
  444. package/dist/gguf/consts.d.ts +4 -0
  445. package/dist/gguf/consts.js +12 -0
  446. package/dist/gguf/consts.js.map +1 -0
  447. package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
  448. package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
  449. package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
  450. package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
  451. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
  452. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
  453. package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
  454. package/dist/gguf/fileReaders/GgufFileReader.js +106 -0
  455. package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
  456. package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
  457. package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
  458. package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
  459. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +28 -0
  460. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +94 -0
  461. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
  462. package/dist/gguf/insights/GgufInsights.d.ts +78 -0
  463. package/dist/gguf/insights/GgufInsights.js +854 -0
  464. package/dist/gguf/insights/GgufInsights.js.map +1 -0
  465. package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +203 -0
  466. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +284 -0
  467. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
  468. package/dist/gguf/insights/GgufInsightsTokens.d.ts +5 -0
  469. package/dist/gguf/insights/GgufInsightsTokens.js +40 -0
  470. package/dist/gguf/insights/GgufInsightsTokens.js.map +1 -0
  471. package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.d.ts +5 -0
  472. package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js +7 -0
  473. package/dist/gguf/insights/utils/getRamUsageFromUnifiedVram.js.map +1 -0
  474. package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +33 -0
  475. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +117 -0
  476. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
  477. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +20 -0
  478. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +251 -0
  479. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
  480. package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
  481. package/dist/gguf/insights/utils/scoreLevels.js +16 -0
  482. package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
  483. package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
  484. package/dist/gguf/parser/GgufV2Parser.js +184 -0
  485. package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
  486. package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
  487. package/dist/gguf/parser/GgufV3Parser.js +4 -0
  488. package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
  489. package/dist/gguf/parser/parseGguf.d.ts +8 -0
  490. package/dist/gguf/parser/parseGguf.js +61 -0
  491. package/dist/gguf/parser/parseGguf.js.map +1 -0
  492. package/dist/gguf/readGgufFileInfo.d.ts +54 -0
  493. package/dist/gguf/readGgufFileInfo.js +82 -0
  494. package/dist/gguf/readGgufFileInfo.js.map +1 -0
  495. package/dist/gguf/types/GgufFileInfoTypes.d.ts +85 -0
  496. package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
  497. package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
  498. package/dist/gguf/types/GgufMetadataTypes.d.ts +480 -0
  499. package/dist/gguf/types/GgufMetadataTypes.js +194 -0
  500. package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
  501. package/dist/gguf/types/GgufTensorInfoTypes.d.ts +63 -0
  502. package/dist/gguf/types/GgufTensorInfoTypes.js +54 -0
  503. package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
  504. package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
  505. package/dist/gguf/utils/GgufReadOffset.js +18 -0
  506. package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
  507. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
  508. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
  509. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
  510. package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
  511. package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
  512. package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
  513. package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
  514. package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
  515. package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
  516. package/dist/gguf/utils/getGgufMetadataKeyValue.d.ts +1 -0
  517. package/dist/gguf/utils/getGgufMetadataKeyValue.js +27 -0
  518. package/dist/gguf/utils/getGgufMetadataKeyValue.js.map +1 -0
  519. package/dist/gguf/utils/ggufQuantNames.d.ts +2 -0
  520. package/dist/gguf/utils/ggufQuantNames.js +42 -0
  521. package/dist/gguf/utils/ggufQuantNames.js.map +1 -0
  522. package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +2 -0
  523. package/dist/gguf/utils/normalizeGgufDownloadUrl.js +18 -0
  524. package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
  525. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
  526. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +38 -0
  527. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
  528. package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
  529. package/dist/gguf/utils/resolveSplitGgufParts.js +64 -0
  530. package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
  531. package/dist/index.d.ts +71 -0
  532. package/dist/index.js +64 -0
  533. package/dist/index.js.map +1 -0
  534. package/dist/state.d.ts +6 -0
  535. package/dist/state.js +22 -0
  536. package/dist/state.js.map +1 -0
  537. package/dist/tsconfig.tsbuildinfo +1 -0
  538. package/dist/types.d.ts +408 -0
  539. package/dist/types.js +13 -0
  540. package/dist/types.js.map +1 -0
  541. package/dist/utils/DisposeGuard.d.ts +13 -0
  542. package/dist/utils/DisposeGuard.js +120 -0
  543. package/dist/utils/DisposeGuard.js.map +1 -0
  544. package/dist/utils/InsufficientMemoryError.d.ts +3 -0
  545. package/dist/utils/InsufficientMemoryError.js +6 -0
  546. package/dist/utils/InsufficientMemoryError.js.map +1 -0
  547. package/dist/utils/LlamaText.d.ts +92 -0
  548. package/dist/utils/LlamaText.js +527 -0
  549. package/dist/utils/LlamaText.js.map +1 -0
  550. package/dist/utils/LruCache.d.ts +12 -0
  551. package/dist/utils/LruCache.js +44 -0
  552. package/dist/utils/LruCache.js.map +1 -0
  553. package/dist/utils/OpenAIFormat.d.ts +177 -0
  554. package/dist/utils/OpenAIFormat.js +488 -0
  555. package/dist/utils/OpenAIFormat.js.map +1 -0
  556. package/dist/utils/OverridesObject.d.ts +7 -0
  557. package/dist/utils/OverridesObject.js +2 -0
  558. package/dist/utils/OverridesObject.js.map +1 -0
  559. package/dist/utils/ReplHistory.d.ts +9 -0
  560. package/dist/utils/ReplHistory.js +72 -0
  561. package/dist/utils/ReplHistory.js.map +1 -0
  562. package/dist/utils/StopGenerationDetector.d.ts +47 -0
  563. package/dist/utils/StopGenerationDetector.js +291 -0
  564. package/dist/utils/StopGenerationDetector.js.map +1 -0
  565. package/dist/utils/ThreadsSplitter.d.ts +32 -0
  566. package/dist/utils/ThreadsSplitter.js +177 -0
  567. package/dist/utils/ThreadsSplitter.js.map +1 -0
  568. package/dist/utils/TokenStreamRegulator.d.ts +38 -0
  569. package/dist/utils/TokenStreamRegulator.js +200 -0
  570. package/dist/utils/TokenStreamRegulator.js.map +1 -0
  571. package/dist/utils/UnsupportedError.d.ts +2 -0
  572. package/dist/utils/UnsupportedError.js +7 -0
  573. package/dist/utils/UnsupportedError.js.map +1 -0
  574. package/dist/utils/appendUserMessageToChatHistory.d.ts +6 -0
  575. package/dist/utils/appendUserMessageToChatHistory.js +22 -0
  576. package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
  577. package/dist/utils/clearTempFolder.d.ts +1 -0
  578. package/dist/utils/clearTempFolder.js +16 -0
  579. package/dist/utils/clearTempFolder.js.map +1 -0
  580. package/dist/utils/cmake.d.ts +10 -0
  581. package/dist/utils/cmake.js +146 -0
  582. package/dist/utils/cmake.js.map +1 -0
  583. package/dist/utils/compareTokens.d.ts +2 -0
  584. package/dist/utils/compareTokens.js +4 -0
  585. package/dist/utils/compareTokens.js.map +1 -0
  586. package/dist/utils/createModelDownloader.d.ts +262 -0
  587. package/dist/utils/createModelDownloader.js +486 -0
  588. package/dist/utils/createModelDownloader.js.map +1 -0
  589. package/dist/utils/findBestOption.d.ts +4 -0
  590. package/dist/utils/findBestOption.js +15 -0
  591. package/dist/utils/findBestOption.js.map +1 -0
  592. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +20 -0
  593. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +85 -0
  594. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
  595. package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +19 -0
  596. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +60 -0
  597. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -0
  598. package/dist/utils/gbnfJson/GbnfTerminal.d.ts +11 -0
  599. package/dist/utils/gbnfJson/GbnfTerminal.js +54 -0
  600. package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -0
  601. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
  602. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
  603. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
  604. package/dist/utils/gbnfJson/terminals/GbnfAnyJson.d.ts +9 -0
  605. package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js +53 -0
  606. package/dist/utils/gbnfJson/terminals/GbnfAnyJson.js.map +1 -0
  607. package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +18 -0
  608. package/dist/utils/gbnfJson/terminals/GbnfArray.js +83 -0
  609. package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -0
  610. package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +7 -0
  611. package/dist/utils/gbnfJson/terminals/GbnfBoolean.js +22 -0
  612. package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -0
  613. package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.d.ts +7 -0
  614. package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js +17 -0
  615. package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -0
  616. package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.d.ts +11 -0
  617. package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js +28 -0
  618. package/dist/utils/gbnfJson/terminals/GbnfCommaWhitespace.js.map +1 -0
  619. package/dist/utils/gbnfJson/terminals/GbnfFormatString.d.ts +11 -0
  620. package/dist/utils/gbnfJson/terminals/GbnfFormatString.js +90 -0
  621. package/dist/utils/gbnfJson/terminals/GbnfFormatString.js.map +1 -0
  622. package/dist/utils/gbnfJson/terminals/GbnfGrammar.d.ts +9 -0
  623. package/dist/utils/gbnfJson/terminals/GbnfGrammar.js +23 -0
  624. package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -0
  625. package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.d.ts +5 -0
  626. package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js +24 -0
  627. package/dist/utils/gbnfJson/terminals/GbnfInsideStringChar.js.map +1 -0
  628. package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +5 -0
  629. package/dist/utils/gbnfJson/terminals/GbnfNull.js +11 -0
  630. package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -0
  631. package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +9 -0
  632. package/dist/utils/gbnfJson/terminals/GbnfNumber.js +22 -0
  633. package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -0
  634. package/dist/utils/gbnfJson/terminals/GbnfNumberValue.d.ts +9 -0
  635. package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js +21 -0
  636. package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -0
  637. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +28 -0
  638. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +88 -0
  639. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -0
  640. package/dist/utils/gbnfJson/terminals/GbnfOr.d.ts +9 -0
  641. package/dist/utils/gbnfJson/terminals/GbnfOr.js +34 -0
  642. package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -0
  643. package/dist/utils/gbnfJson/terminals/GbnfRef.d.ts +15 -0
  644. package/dist/utils/gbnfJson/terminals/GbnfRef.js +34 -0
  645. package/dist/utils/gbnfJson/terminals/GbnfRef.js.map +1 -0
  646. package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +15 -0
  647. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +86 -0
  648. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
  649. package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +12 -0
  650. package/dist/utils/gbnfJson/terminals/GbnfString.js +43 -0
  651. package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -0
  652. package/dist/utils/gbnfJson/terminals/GbnfStringValue.d.ts +8 -0
  653. package/dist/utils/gbnfJson/terminals/GbnfStringValue.js +26 -0
  654. package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -0
  655. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
  656. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
  657. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
  658. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +13 -0
  659. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +67 -0
  660. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -0
  661. package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +30 -0
  662. package/dist/utils/gbnfJson/terminals/gbnfConsts.js +72 -0
  663. package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -0
  664. package/dist/utils/gbnfJson/types.d.ts +213 -0
  665. package/dist/utils/gbnfJson/types.js +30 -0
  666. package/dist/utils/gbnfJson/types.js.map +1 -0
  667. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
  668. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
  669. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
  670. package/dist/utils/gbnfJson/utils/defsScope.d.ts +7 -0
  671. package/dist/utils/gbnfJson/utils/defsScope.js +17 -0
  672. package/dist/utils/gbnfJson/utils/defsScope.js.map +1 -0
  673. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +5 -0
  674. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +143 -0
  675. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -0
  676. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.d.ts +5 -0
  677. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js +16 -0
  678. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForLiteral.js.map +1 -0
  679. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +8 -0
  680. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +242 -0
  681. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -0
  682. package/dist/utils/getBuildDefaults.d.ts +5 -0
  683. package/dist/utils/getBuildDefaults.js +9 -0
  684. package/dist/utils/getBuildDefaults.js.map +1 -0
  685. package/dist/utils/getChatWrapperSegmentDefinition.d.ts +2 -0
  686. package/dist/utils/getChatWrapperSegmentDefinition.js +9 -0
  687. package/dist/utils/getChatWrapperSegmentDefinition.js.map +1 -0
  688. package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
  689. package/dist/utils/getConsoleLogPrefix.js +10 -0
  690. package/dist/utils/getConsoleLogPrefix.js.map +1 -0
  691. package/dist/utils/getFirstWritableDir.d.ts +8 -0
  692. package/dist/utils/getFirstWritableDir.js +60 -0
  693. package/dist/utils/getFirstWritableDir.js.map +1 -0
  694. package/dist/utils/getGrammarsFolder.d.ts +2 -0
  695. package/dist/utils/getGrammarsFolder.js +19 -0
  696. package/dist/utils/getGrammarsFolder.js.map +1 -0
  697. package/dist/utils/getLlamaClasses.d.ts +9 -0
  698. package/dist/utils/getLlamaClasses.js +14 -0
  699. package/dist/utils/getLlamaClasses.js.map +1 -0
  700. package/dist/utils/getModuleVersion.d.ts +1 -0
  701. package/dist/utils/getModuleVersion.js +13 -0
  702. package/dist/utils/getModuleVersion.js.map +1 -0
  703. package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
  704. package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
  705. package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
  706. package/dist/utils/getReadableContextSize.d.ts +1 -0
  707. package/dist/utils/getReadableContextSize.js +7 -0
  708. package/dist/utils/getReadableContextSize.js.map +1 -0
  709. package/dist/utils/getTempDir.d.ts +10 -0
  710. package/dist/utils/getTempDir.js +121 -0
  711. package/dist/utils/getTempDir.js.map +1 -0
  712. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
  713. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +205 -0
  714. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
  715. package/dist/utils/gitReleaseBundles.d.ts +2 -0
  716. package/dist/utils/gitReleaseBundles.js +132 -0
  717. package/dist/utils/gitReleaseBundles.js.map +1 -0
  718. package/dist/utils/hashString.d.ts +1 -0
  719. package/dist/utils/hashString.js +8 -0
  720. package/dist/utils/hashString.js.map +1 -0
  721. package/dist/utils/includesText.d.ts +1 -0
  722. package/dist/utils/includesText.js +12 -0
  723. package/dist/utils/includesText.js.map +1 -0
  724. package/dist/utils/isLockfileActive.d.ts +4 -0
  725. package/dist/utils/isLockfileActive.js +12 -0
  726. package/dist/utils/isLockfileActive.js.map +1 -0
  727. package/dist/utils/isToken.d.ts +2 -0
  728. package/dist/utils/isToken.js +4 -0
  729. package/dist/utils/isToken.js.map +1 -0
  730. package/dist/utils/isUrl.d.ts +1 -0
  731. package/dist/utils/isUrl.js +15 -0
  732. package/dist/utils/isUrl.js.map +1 -0
  733. package/dist/utils/mergeUnionTypes.d.ts +10 -0
  734. package/dist/utils/mergeUnionTypes.js +2 -0
  735. package/dist/utils/mergeUnionTypes.js.map +1 -0
  736. package/dist/utils/modelDownloadEndpoints.d.ts +13 -0
  737. package/dist/utils/modelDownloadEndpoints.js +27 -0
  738. package/dist/utils/modelDownloadEndpoints.js.map +1 -0
  739. package/dist/utils/modelFileAccessTokens.d.ts +5 -0
  740. package/dist/utils/modelFileAccessTokens.js +41 -0
  741. package/dist/utils/modelFileAccessTokens.js.map +1 -0
  742. package/dist/utils/optionsMatrix.d.ts +58 -0
  743. package/dist/utils/optionsMatrix.js +97 -0
  744. package/dist/utils/optionsMatrix.js.map +1 -0
  745. package/dist/utils/parseModelFileName.d.ts +15 -0
  746. package/dist/utils/parseModelFileName.js +132 -0
  747. package/dist/utils/parseModelFileName.js.map +1 -0
  748. package/dist/utils/parseModelUri.d.ts +40 -0
  749. package/dist/utils/parseModelUri.js +346 -0
  750. package/dist/utils/parseModelUri.js.map +1 -0
  751. package/dist/utils/parseTextTemplate.d.ts +66 -0
  752. package/dist/utils/parseTextTemplate.js +116 -0
  753. package/dist/utils/parseTextTemplate.js.map +1 -0
  754. package/dist/utils/prettyPrintObject.d.ts +10 -0
  755. package/dist/utils/prettyPrintObject.js +84 -0
  756. package/dist/utils/prettyPrintObject.js.map +1 -0
  757. package/dist/utils/pushAll.d.ts +6 -0
  758. package/dist/utils/pushAll.js +11 -0
  759. package/dist/utils/pushAll.js.map +1 -0
  760. package/dist/utils/removeNullFields.d.ts +2 -0
  761. package/dist/utils/removeNullFields.js +17 -0
  762. package/dist/utils/removeNullFields.js.map +1 -0
  763. package/dist/utils/resolveGithubRelease.d.ts +2 -0
  764. package/dist/utils/resolveGithubRelease.js +77 -0
  765. package/dist/utils/resolveGithubRelease.js.map +1 -0
  766. package/dist/utils/resolveLastTokens.d.ts +2 -0
  767. package/dist/utils/resolveLastTokens.js +12 -0
  768. package/dist/utils/resolveLastTokens.js.map +1 -0
  769. package/dist/utils/resolveModelDestination.d.ts +16 -0
  770. package/dist/utils/resolveModelDestination.js +54 -0
  771. package/dist/utils/resolveModelDestination.js.map +1 -0
  772. package/dist/utils/resolveModelFile.d.ts +142 -0
  773. package/dist/utils/resolveModelFile.js +201 -0
  774. package/dist/utils/resolveModelFile.js.map +1 -0
  775. package/dist/utils/runtime.d.ts +4 -0
  776. package/dist/utils/runtime.js +8 -0
  777. package/dist/utils/runtime.js.map +1 -0
  778. package/dist/utils/safeEventCallback.d.ts +6 -0
  779. package/dist/utils/safeEventCallback.js +29 -0
  780. package/dist/utils/safeEventCallback.js.map +1 -0
  781. package/dist/utils/signalSleep.d.ts +1 -0
  782. package/dist/utils/signalSleep.js +20 -0
  783. package/dist/utils/signalSleep.js.map +1 -0
  784. package/dist/utils/spawnCommand.d.ts +11 -0
  785. package/dist/utils/spawnCommand.js +89 -0
  786. package/dist/utils/spawnCommand.js.map +1 -0
  787. package/dist/utils/tokenizeInput.d.ts +3 -0
  788. package/dist/utils/tokenizeInput.js +14 -0
  789. package/dist/utils/tokenizeInput.js.map +1 -0
  790. package/dist/utils/tokenizerUtils.d.ts +12 -0
  791. package/dist/utils/tokenizerUtils.js +32 -0
  792. package/dist/utils/tokenizerUtils.js.map +1 -0
  793. package/dist/utils/transformPromisable.d.ts +54 -0
  794. package/dist/utils/transformPromisable.js +95 -0
  795. package/dist/utils/transformPromisable.js.map +1 -0
  796. package/dist/utils/truncateTextAndRoundToWords.d.ts +11 -0
  797. package/dist/utils/truncateTextAndRoundToWords.js +110 -0
  798. package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
  799. package/dist/utils/utilTypes.d.ts +18 -0
  800. package/dist/utils/utilTypes.js +2 -0
  801. package/dist/utils/utilTypes.js.map +1 -0
  802. package/dist/utils/waitForLockfileRelease.d.ts +5 -0
  803. package/dist/utils/waitForLockfileRelease.js +19 -0
  804. package/dist/utils/waitForLockfileRelease.js.map +1 -0
  805. package/dist/utils/withLockfile.d.ts +7 -0
  806. package/dist/utils/withLockfile.js +44 -0
  807. package/dist/utils/withLockfile.js.map +1 -0
  808. package/dist/utils/withOra.d.ts +7 -0
  809. package/dist/utils/withOra.js +37 -0
  810. package/dist/utils/withOra.js.map +1 -0
  811. package/dist/utils/withProgressLog.d.ts +22 -0
  812. package/dist/utils/withProgressLog.js +211 -0
  813. package/dist/utils/withProgressLog.js.map +1 -0
  814. package/dist/utils/withStatusLogs.d.ts +6 -0
  815. package/dist/utils/withStatusLogs.js +25 -0
  816. package/dist/utils/withStatusLogs.js.map +1 -0
  817. package/dist/utils/wrapAbortSignal.d.ts +1 -0
  818. package/dist/utils/wrapAbortSignal.js +14 -0
  819. package/dist/utils/wrapAbortSignal.js.map +1 -0
  820. package/llama/.clang-format +46 -0
  821. package/llama/CMakeLists.txt +141 -0
  822. package/llama/addon/AddonContext.cpp +1181 -0
  823. package/llama/addon/AddonContext.h +85 -0
  824. package/llama/addon/AddonGrammar.cpp +92 -0
  825. package/llama/addon/AddonGrammar.h +22 -0
  826. package/llama/addon/AddonGrammarEvaluationState.cpp +36 -0
  827. package/llama/addon/AddonGrammarEvaluationState.h +17 -0
  828. package/llama/addon/AddonModel.cpp +691 -0
  829. package/llama/addon/AddonModel.h +64 -0
  830. package/llama/addon/AddonModelData.cpp +25 -0
  831. package/llama/addon/AddonModelData.h +15 -0
  832. package/llama/addon/AddonModelLora.cpp +103 -0
  833. package/llama/addon/AddonModelLora.h +28 -0
  834. package/llama/addon/AddonSampler.cpp +669 -0
  835. package/llama/addon/AddonSampler.h +75 -0
  836. package/llama/addon/RingBuffer.h +109 -0
  837. package/llama/addon/addon.cpp +330 -0
  838. package/llama/addon/addonGlobals.cpp +22 -0
  839. package/llama/addon/addonGlobals.h +12 -0
  840. package/llama/addon/globals/addonLog.cpp +143 -0
  841. package/llama/addon/globals/addonLog.h +24 -0
  842. package/llama/addon/globals/addonProgress.cpp +15 -0
  843. package/llama/addon/globals/addonProgress.h +15 -0
  844. package/llama/addon/globals/getGpuInfo.cpp +146 -0
  845. package/llama/addon/globals/getGpuInfo.h +11 -0
  846. package/llama/addon/globals/getMemoryInfo.cpp +63 -0
  847. package/llama/addon/globals/getMemoryInfo.h +4 -0
  848. package/llama/addon/globals/getSwapInfo.cpp +69 -0
  849. package/llama/addon/globals/getSwapInfo.h +4 -0
  850. package/llama/binariesGithubRelease.json +3 -0
  851. package/llama/cmake/addVariantSuffix.cmake +21 -0
  852. package/llama/cmake/win32.ensureNinjaPath.cmake +68 -0
  853. package/llama/cmake/win32.ensureNodeLib.cmake +34 -0
  854. package/llama/cmake/win32.llvmApplyGnuModeAdaptations.cmake +12 -0
  855. package/llama/cmake/win32.llvmEnsureCmakeAr.cmake +37 -0
  856. package/llama/cmake/win32.llvmUseGnuModeCompilers.cmake +87 -0
  857. package/llama/cmake/win32.programFilesPaths.cmake +35 -0
  858. package/llama/gpuInfo/vulkan-gpu-info.cpp +207 -0
  859. package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
  860. package/llama/package.json +5 -0
  861. package/llama/profiles/llvm.win32.host-arm64.target-arm64.cmake +14 -0
  862. package/llama/profiles/llvm.win32.host-x64.target-arm64.cmake +14 -0
  863. package/llama/profiles/llvm.win32.host-x64.target-x64.cmake +14 -0
  864. package/llama/toolchains/darwin.host-x64.target-arm64.cmake +8 -0
  865. package/llama/toolchains/linux.host-arm64.target-x64.cmake +5 -0
  866. package/llama/toolchains/linux.host-x64.target-arm64.cmake +5 -0
  867. package/llama/toolchains/linux.host-x64.target-arm71.cmake +5 -0
  868. package/llama/toolchains/llvm.win32.host-x64.target-x64.cmake +20 -0
  869. package/llama/toolchains/win32.host-arm64.target-arm64.cmake +21 -0
  870. package/llama/toolchains/win32.host-x64.target-arm64.cmake +21 -0
  871. package/llama/xpack/package.json +10 -0
  872. package/package.json +241 -0
  873. package/templates/README.md +6 -0
  874. package/templates/package.json +10 -0
  875. package/templates/packed/electron-typescript-react.json +1 -0
  876. package/templates/packed/node-typescript.json +1 -0
@@ -0,0 +1,486 @@
1
+ import process from "process";
2
+ import path from "path";
3
+ import { downloadFile, downloadSequence } from "ipull";
4
+ import fs from "fs-extra";
5
+ import chalk from "chalk";
6
+ import { createSplitPartFilename, resolveSplitGgufParts } from "../gguf/utils/resolveSplitGgufParts.js";
7
+ import { getFilenameForBinarySplitGgufPartUrls, resolveBinarySplitGgufPartUrls } from "../gguf/utils/resolveBinarySplitGgufPartUrls.js";
8
+ import { cliModelsDirectory, isCI } from "../config.js";
9
+ import { safeEventCallback } from "./safeEventCallback.js";
10
+ import { resolveModelFileAccessTokensTryHeaders } from "./modelFileAccessTokens.js";
11
+ import { pushAll } from "./pushAll.js";
12
+ import { resolveModelDestination } from "./resolveModelDestination.js";
13
+ import { getAuthorizationHeader, resolveParsedModelUri } from "./parseModelUri.js";
14
+ import withOra from "./withOra.js";
15
+ /**
16
+ * Create a model downloader to download a model from a URI.
17
+ * Uses [`ipull`](https://github.com/ido-pluto/ipull) to download a model file as fast as possible with parallel connections
18
+ * and other optimizations.
19
+ *
20
+ * If the uri points to a `.gguf` file that is split into multiple parts (for example, `model-00001-of-00009.gguf`),
21
+ * all the parts will be downloaded to the specified directory.
22
+ *
23
+ * If the uri points to a `.gguf` file that is binary split into multiple parts (for example, `model.gguf.part1of9`),
24
+ * all the parts will be spliced into a single file and be downloaded to the specified directory.
25
+ *
26
+ * If the uri points to a `.gguf` file that is not split or binary spliced (for example, `model.gguf`),
27
+ * the file will be downloaded to the specified directory.
28
+ *
29
+ * The supported URI schemes are:
30
+ * - **HTTP:** `https://`, `http://`
31
+ * - **Hugging Face:** `hf:<user>/<model>:<quant>` (`:<quant>` is optional, but recommended)
32
+ * - **Hugging Face:** `hf:<user>/<model>/<file-path>#<branch>` (`#<branch>` is optional)
33
+ * @example
34
+ * ```typescript
35
+ * import {fileURLToPath} from "url";
36
+ * import path from "path";
37
+ * import {createModelDownloader, getLlama} from "node-llama-cpp";
38
+ *
39
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url));
40
+ *
41
+ * const downloader = await createModelDownloader({
42
+ * modelUri: "https://example.com/model.gguf",
43
+ * dirPath: path.join(__dirname, "models")
44
+ * });
45
+ * const modelPath = await downloader.download();
46
+ *
47
+ * const llama = await getLlama();
48
+ * const model = await llama.loadModel({
49
+ * modelPath
50
+ * });
51
+ * ```
52
+ * @example
53
+ * ```typescript
54
+ * import {fileURLToPath} from "url";
55
+ * import path from "path";
56
+ * import {createModelDownloader, getLlama} from "node-llama-cpp";
57
+ *
58
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url));
59
+ *
60
+ * const downloader = await createModelDownloader({
61
+ * modelUri: "hf:user/model:quant",
62
+ * dirPath: path.join(__dirname, "models")
63
+ * });
64
+ * const modelPath = await downloader.download();
65
+ *
66
+ * const llama = await getLlama();
67
+ * const model = await llama.loadModel({
68
+ * modelPath
69
+ * });
70
+ * ```
71
+ */
72
+ export function createModelDownloader(options) {
73
+ return ModelDownloader._create(options);
74
+ }
75
+ /**
76
+ * Combine multiple models downloaders to a single downloader to download everything using as much parallelism as possible.
77
+ *
78
+ * You can check each individual model downloader for its download progress,
79
+ * but only the `onProgress` passed to the combined downloader will be called during the download.
80
+ *
81
+ * When combining `ModelDownloader` instances, the following options on each individual `ModelDownloader` are ignored:
82
+ * - `showCliProgress`
83
+ * - `onProgress`
84
+ * - `parallelDownloads`
85
+ *
86
+ * To set any of those options for the combined downloader, you have to pass them to the combined downloader instance.
87
+ * @example
88
+ * ```typescript
89
+ * import {fileURLToPath} from "url";
90
+ * import path from "path";
91
+ * import {createModelDownloader, combineModelDownloaders, getLlama} from "node-llama-cpp";
92
+ *
93
+ * const __dirname = path.dirname(fileURLToPath(import.meta.url));
94
+ *
95
+ * const downloaders = [
96
+ * createModelDownloader({
97
+ * modelUri: "https://example.com/model1.gguf",
98
+ * dirPath: path.join(__dirname, "models")
99
+ * }),
100
+ * createModelDownloader({
101
+ * modelUri: "hf:user/model2:quant",
102
+ * dirPath: path.join(__dirname, "models")
103
+ * }),
104
+ * createModelDownloader({
105
+ * modelUri: "hf:user/model/model3.gguf",
106
+ * dirPath: path.join(__dirname, "models")
107
+ * })
108
+ * ];
109
+ * const combinedDownloader = await combineModelDownloaders(downloaders, {
110
+ * showCliProgress: true // show download progress in the CLI
111
+ * });
112
+ * const [
113
+ * model1Path,
114
+ * model2Path,
115
+ * model3Path
116
+ * ] = await combinedDownloader.download();
117
+ *
118
+ * const llama = await getLlama();
119
+ * const model1 = await llama.loadModel({
120
+ * modelPath: model1Path!
121
+ * });
122
+ * const model2 = await llama.loadModel({
123
+ * modelPath: model2Path!
124
+ * });
125
+ * const model3 = await llama.loadModel({
126
+ * modelPath: model3Path!
127
+ * });
128
+ * ```
129
+ */
130
+ export async function combineModelDownloaders(downloaders, options) {
131
+ const downloader = CombinedModelDownloader._create(await Promise.all(downloaders), options);
132
+ await downloader._init();
133
+ return downloader;
134
+ }
135
+ export class ModelDownloader {
136
+ /** @internal */ _modelUrl;
137
+ /** @internal */ _dirPath;
138
+ /** @internal */ _fileName;
139
+ /** @internal */ _headers;
140
+ /** @internal */ _showCliProgress;
141
+ /** @internal */ _onProgress;
142
+ /** @internal */ _tokens;
143
+ /** @internal */ _endpoints;
144
+ /** @internal */ _deleteTempFileOnCancel;
145
+ /** @internal */ _skipExisting;
146
+ /** @internal */ _parallelDownloads;
147
+ /** @internal */ _specificFileDownloaders = [];
148
+ /** @internal */ _downloader;
149
+ /** @internal */ _entrypointFilename;
150
+ /** @internal */ _splitBinaryParts;
151
+ /** @internal */ _totalFiles;
152
+ /** @internal */ _tryHeaders = [];
153
+ constructor(options, { resolvedModelUrl, resolvedFileName }) {
154
+ const { dirPath = cliModelsDirectory, headers, showCliProgress = false, onProgress, deleteTempFileOnCancel = true, skipExisting = true, parallelDownloads = 4, tokens, endpoints } = options;
155
+ this._modelUrl = resolvedModelUrl;
156
+ this._dirPath = path.resolve(process.cwd(), dirPath);
157
+ this._fileName = resolvedFileName;
158
+ this._headers = headers;
159
+ this._showCliProgress = showCliProgress;
160
+ this._onProgress = safeEventCallback(onProgress);
161
+ this._deleteTempFileOnCancel = deleteTempFileOnCancel;
162
+ this._skipExisting = skipExisting;
163
+ this._parallelDownloads = parallelDownloads;
164
+ this._tokens = tokens;
165
+ this._endpoints = endpoints;
166
+ this._onDownloadProgress = this._onDownloadProgress.bind(this);
167
+ }
168
+ /**
169
+ * The filename of the entrypoint file that should be used to load the model.
170
+ */
171
+ get entrypointFilename() {
172
+ return this._entrypointFilename;
173
+ }
174
+ /**
175
+ * The full path to the entrypoint file that should be used to load the model.
176
+ */
177
+ get entrypointFilePath() {
178
+ return path.join(this._dirPath, this.entrypointFilename);
179
+ }
180
+ /**
181
+ * If the model is binary spliced from multiple parts, this will return the number of those binary parts.
182
+ */
183
+ get splitBinaryParts() {
184
+ return this._splitBinaryParts;
185
+ }
186
+ /**
187
+ * The total number of files that will be saved to the directory.
188
+ * For split files, this will be the number of split parts, as multiple files will be saved.
189
+ * For binary-split files, this will be 1, as the parts will be spliced into a single file.
190
+ */
191
+ get totalFiles() {
192
+ return this._totalFiles;
193
+ }
194
+ get totalSize() {
195
+ return this._specificFileDownloaders
196
+ .map((downloader) => downloader.status.totalBytes)
197
+ .reduce((acc, totalBytes) => acc + totalBytes, 0);
198
+ }
199
+ get downloadedSize() {
200
+ return this._specificFileDownloaders
201
+ .map((downloader) => downloader.status.transferredBytes)
202
+ .reduce((acc, transferredBytes) => acc + transferredBytes, 0);
203
+ }
204
+ /**
205
+ * @returns The path to the entrypoint file that should be used to load the model
206
+ */
207
+ async download({ signal } = {}) {
208
+ if (signal?.aborted)
209
+ throw signal.reason;
210
+ const onAbort = () => {
211
+ signal?.removeEventListener("abort", onAbort);
212
+ this.cancel();
213
+ };
214
+ if (signal != null)
215
+ signal.addEventListener("abort", onAbort);
216
+ try {
217
+ if (this._onProgress)
218
+ this._downloader.on("progress", this._onDownloadProgress);
219
+ await this._downloader.download();
220
+ }
221
+ catch (err) {
222
+ if (signal?.aborted)
223
+ throw signal.reason;
224
+ throw err;
225
+ }
226
+ finally {
227
+ if (this._onProgress)
228
+ this._downloader.off("progress", this._onDownloadProgress);
229
+ if (signal != null)
230
+ signal.removeEventListener("abort", onAbort);
231
+ }
232
+ return this.entrypointFilePath;
233
+ }
234
+ async cancel({ deleteTempFile = this._deleteTempFileOnCancel } = {}) {
235
+ for (const downloader of this._specificFileDownloaders)
236
+ await downloader.close({ deleteTempFile });
237
+ if (this._downloader !== this._specificFileDownloaders[0])
238
+ await this._downloader?.close({ deleteTempFile });
239
+ }
240
+ /** @internal */
241
+ _onDownloadProgress() {
242
+ this._onProgress?.({
243
+ totalSize: this.totalSize,
244
+ downloadedSize: this.downloadedSize
245
+ });
246
+ }
247
+ /** @internal */
248
+ async resolveTryHeaders() {
249
+ if (this._tokens == null)
250
+ return;
251
+ pushAll(this._tryHeaders, await resolveModelFileAccessTokensTryHeaders(this._modelUrl, this._tokens, this._endpoints, this._headers));
252
+ }
253
+ /** @internal */
254
+ async _init() {
255
+ await this.resolveTryHeaders();
256
+ const binarySplitPartUrls = resolveBinarySplitGgufPartUrls(this._modelUrl);
257
+ await fs.ensureDir(this._dirPath);
258
+ if (binarySplitPartUrls instanceof Array) {
259
+ this._downloader = await downloadFile({
260
+ partURLs: binarySplitPartUrls,
261
+ directory: this._dirPath,
262
+ fileName: this._fileName ?? getFilenameForBinarySplitGgufPartUrls(binarySplitPartUrls),
263
+ cliProgress: this._showCliProgress,
264
+ cliStyle: isCI ? "ci" : "fancy",
265
+ headers: this._headers ?? {},
266
+ tryHeaders: this._tryHeaders.slice(),
267
+ skipExisting: this._skipExisting
268
+ });
269
+ this._specificFileDownloaders.push(this._downloader);
270
+ this._entrypointFilename = this._downloader.fileName;
271
+ this._splitBinaryParts = binarySplitPartUrls.length;
272
+ this._totalFiles = 1;
273
+ if (this._downloader.fileName == null || this._downloader.fileName === "")
274
+ throw new Error("Failed to get the file name from the given URL");
275
+ return;
276
+ }
277
+ const splitGgufPartUrls = resolveSplitGgufParts(this._modelUrl);
278
+ if (splitGgufPartUrls.length === 1) {
279
+ this._downloader = await downloadFile({
280
+ url: splitGgufPartUrls[0],
281
+ directory: this._dirPath,
282
+ fileName: this._fileName ?? undefined,
283
+ cliProgress: this._showCliProgress,
284
+ cliStyle: isCI ? "ci" : "fancy",
285
+ headers: this._headers ?? {},
286
+ tryHeaders: this._tryHeaders.slice(),
287
+ skipExisting: this._skipExisting
288
+ });
289
+ this._specificFileDownloaders.push(this._downloader);
290
+ this._entrypointFilename = this._downloader.fileName;
291
+ this._totalFiles = 1;
292
+ if (this._downloader.fileName == null || this._downloader.fileName === "")
293
+ throw new Error("Failed to get the file name from the given URL");
294
+ return;
295
+ }
296
+ const partDownloads = splitGgufPartUrls.map((url, index) => downloadFile({
297
+ url,
298
+ directory: this._dirPath,
299
+ fileName: this._fileName != null
300
+ ? createSplitPartFilename(this._fileName, index + 1, splitGgufPartUrls.length)
301
+ : undefined,
302
+ headers: this._headers ?? {},
303
+ tryHeaders: this._tryHeaders.slice(),
304
+ skipExisting: this._skipExisting
305
+ }));
306
+ this._downloader = await downloadSequence({
307
+ cliProgress: this._showCliProgress,
308
+ cliStyle: isCI ? "ci" : "fancy",
309
+ parallelDownloads: this._parallelDownloads
310
+ }, ...partDownloads);
311
+ const firstDownload = await partDownloads[0];
312
+ this._specificFileDownloaders = await Promise.all(partDownloads);
313
+ this._entrypointFilename = firstDownload.fileName;
314
+ this._totalFiles = partDownloads.length;
315
+ if (this._entrypointFilename == null || this._entrypointFilename === "")
316
+ throw new Error("Failed to get the file name from the given URL");
317
+ return;
318
+ }
319
+ /** @internal */
320
+ static async _create(options) {
321
+ const { modelUri, modelUrl, dirPath = cliModelsDirectory, fileName, _showUriResolvingProgress = false } = options;
322
+ const resolvedModelUri = modelUri || modelUrl;
323
+ if (resolvedModelUri == null || dirPath == null)
324
+ throw new Error("modelUri and dirPath cannot be null");
325
+ async function getModelUrlAndFilename() {
326
+ const resolvedModelDestination = resolveModelDestination(resolvedModelUri, undefined, options.endpoints);
327
+ if (resolvedModelDestination.type == "file")
328
+ return {
329
+ resolvedModelUrl: path.resolve(dirPath, resolvedModelDestination.path),
330
+ resolvedFileName: fileName
331
+ };
332
+ else if (resolvedModelDestination.type === "url")
333
+ return {
334
+ resolvedModelUrl: resolvedModelDestination.url,
335
+ resolvedFileName: fileName
336
+ };
337
+ else if (resolvedModelDestination.parsedUri.type === "resolved")
338
+ return {
339
+ resolvedModelUrl: resolvedModelDestination.parsedUri.resolvedUrl,
340
+ resolvedFileName: fileName || resolvedModelDestination.parsedUri.fullFilename
341
+ };
342
+ const resolvedUri = _showUriResolvingProgress
343
+ ? await withOra({
344
+ loading: chalk.blue("Resolving model URI"),
345
+ success: chalk.blue("Resolved model URI"),
346
+ fail: chalk.blue("Failed to resolve model URI"),
347
+ noSuccessLiveStatus: true
348
+ }, () => {
349
+ return resolveParsedModelUri(resolvedModelDestination.parsedUri, {
350
+ tokens: options.tokens,
351
+ endpoints: options.endpoints,
352
+ authorizationHeader: getAuthorizationHeader(options.headers)
353
+ });
354
+ })
355
+ : await resolveParsedModelUri(resolvedModelDestination.parsedUri, {
356
+ tokens: options.tokens,
357
+ endpoints: options.endpoints,
358
+ authorizationHeader: getAuthorizationHeader(options.headers)
359
+ });
360
+ return {
361
+ resolvedModelUrl: resolvedUri.resolvedUrl,
362
+ resolvedFileName: fileName || resolvedUri.fullFilename
363
+ };
364
+ }
365
+ const modelDownloader = new ModelDownloader(options, await getModelUrlAndFilename());
366
+ await modelDownloader._init();
367
+ return modelDownloader;
368
+ }
369
+ }
370
+ export class CombinedModelDownloader {
371
+ /** @internal */ _downloaders;
372
+ /** @internal */ _showCliProgress;
373
+ /** @internal */ _onProgress;
374
+ /** @internal */ _parallelDownloads;
375
+ /** @internal */ _lock = {};
376
+ /** @internal */ _downloader;
377
+ /**
378
+ * When combining `ModelDownloader` instances, the following options on each individual `ModelDownloader` are ignored:
379
+ * - `showCliProgress`
380
+ * - `onProgress`
381
+ * - `parallelDownloads`
382
+ *
383
+ * To set any of those options for the combined downloader, you have to pass them to the combined downloader instance
384
+ */
385
+ constructor(downloaders, options) {
386
+ const { showCliProgress = false, onProgress, parallelDownloads = 4 } = options ?? {};
387
+ this._downloaders = Object.freeze(downloaders);
388
+ this._showCliProgress = showCliProgress;
389
+ this._onProgress = onProgress;
390
+ this._parallelDownloads = parallelDownloads;
391
+ this._onDownloadProgress = this._onDownloadProgress.bind(this);
392
+ }
393
+ async cancel() {
394
+ for (const modelDownloader of this._downloaders) {
395
+ if (modelDownloader._specificFileDownloaders.every((downloader) => downloader.status.downloadStatus === "Finished"))
396
+ continue;
397
+ for (const downloader of modelDownloader._specificFileDownloaders)
398
+ await downloader.close({
399
+ deleteTempFile: modelDownloader._deleteTempFileOnCancel
400
+ });
401
+ }
402
+ }
403
+ /**
404
+ * @returns The paths to the entrypoint files that should be used to load the models
405
+ */
406
+ async download({ signal } = {}) {
407
+ if (signal?.aborted)
408
+ throw signal.reason;
409
+ const onAbort = () => {
410
+ signal?.removeEventListener("abort", onAbort);
411
+ this.cancel();
412
+ };
413
+ if (signal != null)
414
+ signal.addEventListener("abort", onAbort);
415
+ try {
416
+ if (this._onProgress)
417
+ this._downloader.on("progress", this._onDownloadProgress);
418
+ await this._downloader.download();
419
+ }
420
+ catch (err) {
421
+ if (signal?.aborted)
422
+ throw signal.reason;
423
+ throw err;
424
+ }
425
+ finally {
426
+ if (this._onProgress)
427
+ this._downloader.off("progress", this._onDownloadProgress);
428
+ if (signal != null)
429
+ signal.removeEventListener("abort", onAbort);
430
+ }
431
+ return this.entrypointFilePaths;
432
+ }
433
+ get modelDownloaders() {
434
+ return this._downloaders;
435
+ }
436
+ /**
437
+ * The filename of the entrypoint files that should be used to load the models.
438
+ */
439
+ get entrypointFilenames() {
440
+ return this._downloaders.map((downloader) => downloader.entrypointFilename);
441
+ }
442
+ /**
443
+ * The full paths to the entrypoint files that should be used to load the models.
444
+ */
445
+ get entrypointFilePaths() {
446
+ return this._downloaders.map((downloader) => downloader.entrypointFilePath);
447
+ }
448
+ /**
449
+ * The accumulation of `totalFiles` of all the model downloaders
450
+ */
451
+ get totalFiles() {
452
+ return this._downloaders
453
+ .map((downloader) => downloader.totalFiles)
454
+ .reduce((acc, totalFiles) => acc + totalFiles, 0);
455
+ }
456
+ get totalSize() {
457
+ return this._downloaders
458
+ .map((downloader) => downloader.totalSize)
459
+ .reduce((acc, totalBytes) => acc + totalBytes, 0);
460
+ }
461
+ get downloadedSize() {
462
+ return this._downloaders
463
+ .map((downloader) => downloader.downloadedSize)
464
+ .reduce((acc, transferredBytes) => acc + transferredBytes, 0);
465
+ }
466
+ /** @internal */
467
+ _onDownloadProgress() {
468
+ this._onProgress?.({
469
+ totalSize: this.totalSize,
470
+ downloadedSize: this.downloadedSize
471
+ });
472
+ }
473
+ /** @internal */
474
+ async _init() {
475
+ this._downloader = await downloadSequence({
476
+ cliProgress: this._showCliProgress,
477
+ cliStyle: isCI ? "ci" : "fancy",
478
+ parallelDownloads: this._parallelDownloads
479
+ }, ...this._downloaders.flatMap((downloader) => downloader._specificFileDownloaders));
480
+ }
481
+ /** @internal */
482
+ static _create(downloaders, options) {
483
+ return new CombinedModelDownloader(downloaders, options);
484
+ }
485
+ }
486
+ //# sourceMappingURL=createModelDownloader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModelDownloader.js","sourceRoot":"","sources":["../../src/utils/createModelDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,IAAI,MAAM,MAAM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,IAAI,CAAC,YAAY;aACnB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;aACzC,MAAM,CAAC,CAAC,GAAG,EAAE,UAAU,EAAE,EAAE,CAAC,GAAG,GAAG,UAAU,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,YAAY;aACnB,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC;aAC9C,MAAM,CAAC,CAAC,GAAG,EAAE,gBAAgB,EAAE,EAAE,CAAC,GAAG,GAAG,gBAAgB,EAAE,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,gBAAgB;IACR,mBAAmB;QACvB,IAAI,CAAC,WAAW,EAAE,CAAC;YACf,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,cAAc,EAAE,IAAI,CAAC,cAAc;SACtC,CAAC,CAAC;IACP,CAAC;IAED,gBAAgB;IACT,KAAK,CAAC,KAAK;QACd,IAAI,CAAC,WAAW,GAAG,MAAM,gBAAgB,CACrC;YACI,WAAW,EAAE,IAAI,CAAC,gBAAgB;YAClC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO;YAC/B,iBAAiB,EAAE,IAAI,CAAC,kBAAkB;SAC7C,EACD,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,wBAAwB,CAAC,CACpF,CAAC;IACN,CAAC;IAED,gBAAgB;IACT,MAAM,CAAC,OAAO,CAAC,WAA8B,EAAE,OAAwC;QAC1F,OAAO,IAAI,uBAAuB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;CACJ"}
@@ -0,0 +1,4 @@
1
+ export declare function findBestOption<const O>({ generator, score }: {
2
+ generator: () => Generator<O>;
3
+ score: (option: O) => number | null;
4
+ }): O | null;
@@ -0,0 +1,15 @@
1
+ export function findBestOption({ generator, score }) {
2
+ let bestOption = null;
3
+ let bestScore = null;
4
+ for (const option of generator()) {
5
+ const currentScore = score(option);
6
+ if (currentScore === Infinity)
7
+ return option;
8
+ if (currentScore != null && (bestScore == null || currentScore > bestScore)) {
9
+ bestOption = option;
10
+ bestScore = currentScore;
11
+ }
12
+ }
13
+ return bestOption;
14
+ }
15
+ //# sourceMappingURL=findBestOption.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findBestOption.js","sourceRoot":"","sources":["../../src/utils/findBestOption.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,cAAc,CAAU,EAAC,SAAS,EAAE,KAAK,EAGxD;IACG,IAAI,UAAU,GAAa,IAAI,CAAC;IAChC,IAAI,SAAS,GAAkB,IAAI,CAAC;IAEpC,KAAK,MAAM,MAAM,IAAI,SAAS,EAAE,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,YAAY,KAAK,QAAQ;YACzB,OAAO,MAAM,CAAC;QAElB,IAAI,YAAY,IAAI,IAAI,IAAI,CAAC,SAAS,IAAI,IAAI,IAAI,YAAY,GAAG,SAAS,CAAC,EAAE,CAAC;YAC1E,UAAU,GAAG,MAAM,CAAC;YACpB,SAAS,GAAG,YAAY,CAAC;QAC7B,CAAC;IACL,CAAC;IAED,OAAO,UAAU,CAAC;AACtB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { ChatHistoryItem, Tokenizer } from "../types.js";
2
+ import { ChatWrapper } from "../ChatWrapper.js";
3
+ export declare function findCharacterRemovalCountToFitChatHistoryInContext({ compressChatHistory, chatHistory, tokensCountToFit, tokenizer, chatWrapper, initialCharactersRemovalCount, estimatedCharactersPerToken, maxDecompressionAttempts, failedCompressionErrorMessage }: {
4
+ compressChatHistory(options: {
5
+ chatHistory: readonly ChatHistoryItem[];
6
+ charactersToRemove: number;
7
+ estimatedCharactersPerToken: number;
8
+ }): ChatHistoryItem[] | Promise<ChatHistoryItem[]>;
9
+ chatHistory: ChatHistoryItem[];
10
+ tokensCountToFit: number;
11
+ tokenizer: Tokenizer;
12
+ chatWrapper: ChatWrapper;
13
+ initialCharactersRemovalCount?: number;
14
+ estimatedCharactersPerToken?: number;
15
+ maxDecompressionAttempts?: number;
16
+ failedCompressionErrorMessage?: string;
17
+ }): Promise<{
18
+ removedCharactersCount: number;
19
+ compressedChatHistory: ChatHistoryItem[];
20
+ }>;
@@ -0,0 +1,85 @@
1
+ const maxSequentialUnhelpfulIterations = 100;
2
+ export async function findCharacterRemovalCountToFitChatHistoryInContext({ compressChatHistory, chatHistory, tokensCountToFit, tokenizer, chatWrapper, initialCharactersRemovalCount = 0, estimatedCharactersPerToken = 5, maxDecompressionAttempts = 2, failedCompressionErrorMessage = "Failed to compress chat history. Consider increasing the context size." }) {
3
+ let currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
4
+ function getTokensCountForChatHistory(chatHistory) {
5
+ const { contextText } = chatWrapper.generateContextState({ chatHistory });
6
+ return contextText.tokenize(tokenizer, "trimLeadingSpace").length;
7
+ }
8
+ async function getResultForCharacterRemovalCount(characterRemovalCount) {
9
+ if (characterRemovalCount === 0)
10
+ return {
11
+ compressedHistory: chatHistory,
12
+ tokensCount: getTokensCountForChatHistory(chatHistory),
13
+ characterRemovalCount
14
+ };
15
+ const compressedHistory = await compressChatHistory({
16
+ chatHistory,
17
+ charactersToRemove: characterRemovalCount,
18
+ estimatedCharactersPerToken: currentEstimatedCharactersPerToken
19
+ });
20
+ return {
21
+ compressedHistory,
22
+ tokensCount: getTokensCountForChatHistory(compressedHistory),
23
+ characterRemovalCount
24
+ };
25
+ }
26
+ let latestCompressionAttempt = await getResultForCharacterRemovalCount(initialCharactersRemovalCount);
27
+ const firstCompressionAttempt = latestCompressionAttempt;
28
+ let latestCompressionAttemptTokensCount = latestCompressionAttempt.tokensCount;
29
+ let sameTokensCountRepetitions = 0;
30
+ if (latestCompressionAttempt.tokensCount === tokensCountToFit ||
31
+ (latestCompressionAttempt.tokensCount < tokensCountToFit && latestCompressionAttempt.characterRemovalCount === 0))
32
+ return {
33
+ removedCharactersCount: initialCharactersRemovalCount,
34
+ compressedChatHistory: latestCompressionAttempt.compressedHistory
35
+ };
36
+ let bestCompressionAttempt = latestCompressionAttempt;
37
+ for (let compressionAttempts = 0, decompressionAttempts = 0; bestCompressionAttempt.tokensCount !== tokensCountToFit;) {
38
+ if (compressionAttempts > 0) {
39
+ if (latestCompressionAttempt.tokensCount != firstCompressionAttempt.tokensCount &&
40
+ latestCompressionAttempt.characterRemovalCount != firstCompressionAttempt.characterRemovalCount)
41
+ currentEstimatedCharactersPerToken =
42
+ Math.abs(latestCompressionAttempt.characterRemovalCount - firstCompressionAttempt.characterRemovalCount) /
43
+ Math.abs(latestCompressionAttempt.tokensCount - firstCompressionAttempt.tokensCount);
44
+ if (!Number.isFinite(currentEstimatedCharactersPerToken) || currentEstimatedCharactersPerToken === 0)
45
+ currentEstimatedCharactersPerToken = estimatedCharactersPerToken;
46
+ }
47
+ const tokensLeftToRemove = latestCompressionAttempt.tokensCount - tokensCountToFit;
48
+ let additionalCharactersToRemove = Math.round(tokensLeftToRemove * currentEstimatedCharactersPerToken);
49
+ if (additionalCharactersToRemove === 0) {
50
+ if (tokensLeftToRemove > 0)
51
+ additionalCharactersToRemove = 1;
52
+ else if (tokensLeftToRemove < 0)
53
+ additionalCharactersToRemove = -1;
54
+ }
55
+ if (tokensLeftToRemove > 0)
56
+ compressionAttempts++;
57
+ else if (tokensLeftToRemove < 0)
58
+ decompressionAttempts++;
59
+ if (decompressionAttempts >= maxDecompressionAttempts)
60
+ break;
61
+ latestCompressionAttempt = await getResultForCharacterRemovalCount(latestCompressionAttempt.characterRemovalCount + additionalCharactersToRemove);
62
+ if ((bestCompressionAttempt.tokensCount > tokensCountToFit &&
63
+ latestCompressionAttempt.tokensCount <= bestCompressionAttempt.tokensCount) || (bestCompressionAttempt.tokensCount < tokensCountToFit &&
64
+ latestCompressionAttempt.tokensCount < tokensCountToFit &&
65
+ latestCompressionAttempt.tokensCount > bestCompressionAttempt.tokensCount) || (bestCompressionAttempt.tokensCount <= tokensCountToFit &&
66
+ latestCompressionAttempt.tokensCount <= tokensCountToFit &&
67
+ latestCompressionAttempt.characterRemovalCount < bestCompressionAttempt.characterRemovalCount))
68
+ bestCompressionAttempt = latestCompressionAttempt;
69
+ if (latestCompressionAttempt.tokensCount === latestCompressionAttemptTokensCount)
70
+ sameTokensCountRepetitions++;
71
+ else {
72
+ latestCompressionAttemptTokensCount = latestCompressionAttempt.tokensCount;
73
+ sameTokensCountRepetitions = 0;
74
+ }
75
+ if (decompressionAttempts === 0 &&
76
+ compressionAttempts >= maxSequentialUnhelpfulIterations &&
77
+ sameTokensCountRepetitions >= maxSequentialUnhelpfulIterations)
78
+ throw new Error(failedCompressionErrorMessage);
79
+ }
80
+ return {
81
+ removedCharactersCount: bestCompressionAttempt.characterRemovalCount,
82
+ compressedChatHistory: bestCompressionAttempt.compressedHistory
83
+ };
84
+ }
85
+ //# sourceMappingURL=findCharacterRemovalCountToFitChatHistoryInContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"findCharacterRemovalCountToFitChatHistoryInContext.js","sourceRoot":"","sources":["../../src/utils/findCharacterRemovalCountToFitChatHistoryInContext.ts"],"names":[],"mappings":"AAGA,MAAM,gCAAgC,GAAG,GAAG,CAAC;AAE7C,MAAM,CAAC,KAAK,UAAU,kDAAkD,CAAC,EACrE,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,6BAA6B,GAAG,CAAC,EACjC,2BAA2B,GAAG,CAAC,EAC/B,wBAAwB,GAAG,CAAC,EAC5B,6BAA6B,GAAG,wEAAwE,EAa3G;IAIG,IAAI,kCAAkC,GAAG,2BAA2B,CAAC;IAErE,SAAS,4BAA4B,CAAC,WAAuC;QACzE,MAAM,EAAC,WAAW,EAAC,GAAG,WAAW,CAA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