node-llama-cpp 2.8.6 → 3.0.0-beta.10

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 (346) hide show
  1. package/README.md +2 -2
  2. package/dist/ChatWrapper.d.ts +49 -0
  3. package/dist/ChatWrapper.js +120 -0
  4. package/dist/ChatWrapper.js.map +1 -0
  5. package/dist/bindings/AddonTypes.d.ts +92 -0
  6. package/dist/bindings/AddonTypes.js +2 -0
  7. package/dist/bindings/AddonTypes.js.map +1 -0
  8. package/dist/bindings/Llama.d.ts +23 -0
  9. package/dist/bindings/Llama.js +225 -0
  10. package/dist/bindings/Llama.js.map +1 -0
  11. package/dist/bindings/getLlama.d.ts +86 -0
  12. package/dist/bindings/getLlama.js +225 -0
  13. package/dist/bindings/getLlama.js.map +1 -0
  14. package/dist/bindings/types.d.ts +33 -0
  15. package/dist/bindings/types.js +30 -0
  16. package/dist/bindings/types.js.map +1 -0
  17. package/dist/bindings/utils/NoBinaryFoundError.d.ts +2 -0
  18. package/dist/bindings/utils/NoBinaryFoundError.js +7 -0
  19. package/dist/bindings/utils/NoBinaryFoundError.js.map +1 -0
  20. package/dist/{utils → bindings/utils}/binariesGithubRelease.js +1 -1
  21. package/dist/bindings/utils/binariesGithubRelease.js.map +1 -0
  22. package/dist/bindings/utils/clearAllLocalBuilds.d.ts +1 -0
  23. package/dist/bindings/utils/clearAllLocalBuilds.js +47 -0
  24. package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -0
  25. package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +11 -0
  26. package/dist/bindings/utils/cloneLlamaCppRepo.js +155 -0
  27. package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -0
  28. package/dist/bindings/utils/compileLLamaCpp.d.ts +12 -0
  29. package/dist/bindings/utils/compileLLamaCpp.js +157 -0
  30. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -0
  31. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.d.ts +5 -0
  32. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +85 -0
  33. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -0
  34. package/dist/bindings/utils/getCanUsePrebuiltBinaries.d.ts +1 -0
  35. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js +8 -0
  36. package/dist/bindings/utils/getCanUsePrebuiltBinaries.js.map +1 -0
  37. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.d.ts +2 -0
  38. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js +21 -0
  39. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -0
  40. package/dist/bindings/utils/getPlatform.d.ts +2 -0
  41. package/dist/bindings/utils/getPlatform.js +15 -0
  42. package/dist/bindings/utils/getPlatform.js.map +1 -0
  43. package/dist/bindings/utils/lastBuildInfo.d.ts +6 -0
  44. package/dist/bindings/utils/lastBuildInfo.js +17 -0
  45. package/dist/bindings/utils/lastBuildInfo.js.map +1 -0
  46. package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +2 -0
  47. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +28 -0
  48. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -0
  49. package/dist/bindings/utils/resolveCustomCmakeOptions.d.ts +1 -0
  50. package/dist/bindings/utils/resolveCustomCmakeOptions.js +43 -0
  51. package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -0
  52. package/dist/chatWrappers/AlpacaChatWrapper.d.ts +12 -0
  53. package/dist/chatWrappers/AlpacaChatWrapper.js +21 -0
  54. package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -0
  55. package/dist/chatWrappers/ChatMLChatWrapper.d.ts +18 -0
  56. package/dist/chatWrappers/ChatMLChatWrapper.js +83 -0
  57. package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -0
  58. package/dist/chatWrappers/EmptyChatWrapper.d.ts +4 -0
  59. package/dist/chatWrappers/EmptyChatWrapper.js +5 -0
  60. package/dist/chatWrappers/EmptyChatWrapper.js.map +1 -0
  61. package/dist/chatWrappers/FalconChatWrapper.d.ts +21 -0
  62. package/dist/chatWrappers/FalconChatWrapper.js +104 -0
  63. package/dist/chatWrappers/FalconChatWrapper.js.map +1 -0
  64. package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +41 -0
  65. package/dist/chatWrappers/FunctionaryChatWrapper.js +200 -0
  66. package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -0
  67. package/dist/chatWrappers/GeneralChatWrapper.d.ts +21 -0
  68. package/dist/chatWrappers/GeneralChatWrapper.js +112 -0
  69. package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -0
  70. package/dist/chatWrappers/LlamaChatWrapper.d.ts +13 -0
  71. package/dist/chatWrappers/LlamaChatWrapper.js +78 -0
  72. package/dist/chatWrappers/LlamaChatWrapper.js.map +1 -0
  73. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +13 -0
  74. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +60 -0
  75. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +1 -0
  76. package/dist/cli/cli.js +5 -1
  77. package/dist/cli/cli.js.map +1 -1
  78. package/dist/cli/commands/BuildCommand.d.ts +2 -1
  79. package/dist/cli/commands/BuildCommand.js +50 -10
  80. package/dist/cli/commands/BuildCommand.js.map +1 -1
  81. package/dist/cli/commands/ChatCommand.d.ts +10 -4
  82. package/dist/cli/commands/ChatCommand.js +169 -57
  83. package/dist/cli/commands/ChatCommand.js.map +1 -1
  84. package/dist/cli/commands/ClearCommand.js +4 -6
  85. package/dist/cli/commands/ClearCommand.js.map +1 -1
  86. package/dist/cli/commands/DebugCommand.d.ts +7 -0
  87. package/dist/cli/commands/DebugCommand.js +59 -0
  88. package/dist/cli/commands/DebugCommand.js.map +1 -0
  89. package/dist/cli/commands/DownloadCommand.d.ts +2 -1
  90. package/dist/cli/commands/DownloadCommand.js +47 -40
  91. package/dist/cli/commands/DownloadCommand.js.map +1 -1
  92. package/dist/cli/commands/OnPostInstallCommand.js +7 -10
  93. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
  94. package/dist/config.d.ts +10 -3
  95. package/dist/config.js +18 -7
  96. package/dist/config.js.map +1 -1
  97. package/dist/evaluator/LlamaChat/LlamaChat.d.ts +185 -0
  98. package/dist/evaluator/LlamaChat/LlamaChat.js +705 -0
  99. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -0
  100. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +22 -0
  101. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +121 -0
  102. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +1 -0
  103. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.d.ts +16 -0
  104. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +135 -0
  105. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -0
  106. package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +157 -0
  107. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +219 -0
  108. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -0
  109. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +7 -0
  110. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
  111. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -0
  112. package/dist/evaluator/LlamaContext/LlamaContext.d.ts +109 -0
  113. package/dist/evaluator/LlamaContext/LlamaContext.js +606 -0
  114. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -0
  115. package/dist/evaluator/LlamaContext/types.d.ts +82 -0
  116. package/dist/evaluator/LlamaContext/types.js +2 -0
  117. package/dist/evaluator/LlamaContext/types.js.map +1 -0
  118. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.d.ts +5 -0
  119. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js +16 -0
  120. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +1 -0
  121. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.d.ts +5 -0
  122. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js +42 -0
  123. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +1 -0
  124. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +2 -0
  125. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js +13 -0
  126. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +1 -0
  127. package/dist/evaluator/LlamaEmbeddingContext.d.ts +37 -0
  128. package/dist/evaluator/LlamaEmbeddingContext.js +78 -0
  129. package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -0
  130. package/dist/evaluator/LlamaGrammar.d.ts +30 -0
  131. package/dist/{llamaEvaluator → evaluator}/LlamaGrammar.js +15 -19
  132. package/dist/evaluator/LlamaGrammar.js.map +1 -0
  133. package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +15 -0
  134. package/dist/evaluator/LlamaGrammarEvaluationState.js +17 -0
  135. package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -0
  136. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.d.ts +2 -1
  137. package/dist/{llamaEvaluator → evaluator}/LlamaJsonSchemaGrammar.js +4 -2
  138. package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -0
  139. package/dist/evaluator/LlamaModel.d.ts +120 -0
  140. package/dist/evaluator/LlamaModel.js +320 -0
  141. package/dist/evaluator/LlamaModel.js.map +1 -0
  142. package/dist/index.d.ts +29 -16
  143. package/dist/index.js +28 -15
  144. package/dist/index.js.map +1 -1
  145. package/dist/state.d.ts +2 -0
  146. package/dist/state.js +7 -0
  147. package/dist/state.js.map +1 -1
  148. package/dist/types.d.ts +44 -4
  149. package/dist/types.js +5 -1
  150. package/dist/types.js.map +1 -1
  151. package/dist/utils/LlamaText.d.ts +42 -0
  152. package/dist/utils/LlamaText.js +207 -0
  153. package/dist/utils/LlamaText.js.map +1 -0
  154. package/dist/utils/ReplHistory.js +1 -1
  155. package/dist/utils/ReplHistory.js.map +1 -1
  156. package/dist/utils/StopGenerationDetector.d.ts +28 -0
  157. package/dist/utils/StopGenerationDetector.js +205 -0
  158. package/dist/utils/StopGenerationDetector.js.map +1 -0
  159. package/dist/utils/TokenStreamRegulator.d.ts +30 -0
  160. package/dist/utils/TokenStreamRegulator.js +96 -0
  161. package/dist/utils/TokenStreamRegulator.js.map +1 -0
  162. package/dist/utils/appendUserMessageToChatHistory.d.ts +2 -0
  163. package/dist/utils/appendUserMessageToChatHistory.js +18 -0
  164. package/dist/utils/appendUserMessageToChatHistory.js.map +1 -0
  165. package/dist/utils/cmake.js +16 -11
  166. package/dist/utils/cmake.js.map +1 -1
  167. package/dist/utils/compareTokens.d.ts +2 -0
  168. package/dist/utils/compareTokens.js +4 -0
  169. package/dist/utils/compareTokens.js.map +1 -0
  170. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +18 -0
  171. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +61 -0
  172. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -0
  173. package/dist/utils/gbnfJson/GbnfGrammarGenerator.d.ts +1 -0
  174. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js +17 -0
  175. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
  176. package/dist/utils/gbnfJson/GbnfTerminal.d.ts +1 -1
  177. package/dist/utils/gbnfJson/GbnfTerminal.js.map +1 -1
  178. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.d.ts +6 -0
  179. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js +21 -0
  180. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -0
  181. package/dist/utils/gbnfJson/types.d.ts +1 -1
  182. package/dist/utils/gbnfJson/types.js.map +1 -1
  183. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.d.ts +1 -0
  184. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
  185. package/dist/utils/getConsoleLogPrefix.d.ts +1 -0
  186. package/dist/utils/getConsoleLogPrefix.js +9 -0
  187. package/dist/utils/getConsoleLogPrefix.js.map +1 -0
  188. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +1 -15
  189. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +1 -1
  190. package/dist/utils/getGrammarsFolder.d.ts +2 -1
  191. package/dist/utils/getGrammarsFolder.js +8 -7
  192. package/dist/utils/getGrammarsFolder.js.map +1 -1
  193. package/dist/utils/getModuleVersion.d.ts +1 -0
  194. package/dist/utils/getModuleVersion.js +13 -0
  195. package/dist/utils/getModuleVersion.js.map +1 -0
  196. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.d.ts +2 -0
  197. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +49 -0
  198. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -0
  199. package/dist/utils/gitReleaseBundles.js +6 -5
  200. package/dist/utils/gitReleaseBundles.js.map +1 -1
  201. package/dist/utils/hashString.d.ts +1 -0
  202. package/dist/utils/hashString.js +8 -0
  203. package/dist/utils/hashString.js.map +1 -0
  204. package/dist/utils/isLockfileActive.d.ts +4 -0
  205. package/dist/utils/isLockfileActive.js +12 -0
  206. package/dist/utils/isLockfileActive.js.map +1 -0
  207. package/dist/utils/parseModelFileName.d.ts +9 -0
  208. package/dist/utils/parseModelFileName.js +68 -0
  209. package/dist/utils/parseModelFileName.js.map +1 -0
  210. package/dist/utils/parseModelTypeDescription.d.ts +6 -0
  211. package/dist/utils/parseModelTypeDescription.js +9 -0
  212. package/dist/utils/parseModelTypeDescription.js.map +1 -0
  213. package/dist/utils/prettyPrintObject.d.ts +1 -0
  214. package/dist/utils/prettyPrintObject.js +40 -0
  215. package/dist/utils/prettyPrintObject.js.map +1 -0
  216. package/dist/utils/removeNullFields.d.ts +1 -0
  217. package/dist/utils/removeNullFields.js +8 -0
  218. package/dist/utils/removeNullFields.js.map +1 -1
  219. package/dist/utils/resolveChatWrapper.d.ts +4 -0
  220. package/dist/utils/resolveChatWrapper.js +16 -0
  221. package/dist/utils/resolveChatWrapper.js.map +1 -0
  222. package/dist/utils/resolveGithubRelease.d.ts +2 -0
  223. package/dist/utils/resolveGithubRelease.js +36 -0
  224. package/dist/utils/resolveGithubRelease.js.map +1 -0
  225. package/dist/utils/spawnCommand.d.ts +1 -1
  226. package/dist/utils/spawnCommand.js +4 -2
  227. package/dist/utils/spawnCommand.js.map +1 -1
  228. package/dist/utils/tokenizeInput.d.ts +3 -0
  229. package/dist/utils/tokenizeInput.js +9 -0
  230. package/dist/utils/tokenizeInput.js.map +1 -0
  231. package/dist/utils/truncateTextAndRoundToWords.d.ts +8 -0
  232. package/dist/utils/truncateTextAndRoundToWords.js +27 -0
  233. package/dist/utils/truncateTextAndRoundToWords.js.map +1 -0
  234. package/dist/utils/waitForLockfileRelease.d.ts +5 -0
  235. package/dist/utils/waitForLockfileRelease.js +20 -0
  236. package/dist/utils/waitForLockfileRelease.js.map +1 -0
  237. package/dist/utils/withLockfile.d.ts +7 -0
  238. package/dist/utils/withLockfile.js +44 -0
  239. package/dist/utils/withLockfile.js.map +1 -0
  240. package/dist/utils/withOra.js +11 -1
  241. package/dist/utils/withOra.js.map +1 -1
  242. package/dist/utils/withStatusLogs.d.ts +2 -1
  243. package/dist/utils/withStatusLogs.js +11 -8
  244. package/dist/utils/withStatusLogs.js.map +1 -1
  245. package/llama/.clang-format +11 -11
  246. package/llama/CMakeLists.txt +87 -2
  247. package/llama/addon.cpp +915 -352
  248. package/llama/binariesGithubRelease.json +1 -1
  249. package/llama/gitRelease.bundle +0 -0
  250. package/llama/gpuInfo/cuda-gpu-info.cu +99 -0
  251. package/llama/gpuInfo/cuda-gpu-info.h +7 -0
  252. package/llama/gpuInfo/metal-gpu-info.h +5 -0
  253. package/llama/gpuInfo/metal-gpu-info.mm +17 -0
  254. package/llama/llama.cpp.info.json +4 -0
  255. package/llamaBins/linux-arm64/.buildMetadata.json +1 -0
  256. package/llamaBins/linux-arm64/llama-addon.node +0 -0
  257. package/llamaBins/linux-armv7l/.buildMetadata.json +1 -0
  258. package/llamaBins/linux-armv7l/llama-addon.node +0 -0
  259. package/llamaBins/linux-x64/.buildMetadata.json +1 -0
  260. package/llamaBins/linux-x64/llama-addon.node +0 -0
  261. package/llamaBins/linux-x64-cuda/.buildMetadata.json +1 -0
  262. package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
  263. package/llamaBins/mac-arm64-metal/.buildMetadata.json +1 -0
  264. package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
  265. package/llamaBins/mac-x64/.buildMetadata.json +1 -0
  266. package/llamaBins/mac-x64/llama-addon.node +0 -0
  267. package/llamaBins/win-x64/.buildMetadata.json +1 -0
  268. package/llamaBins/win-x64/llama-addon.exp +0 -0
  269. package/llamaBins/win-x64/llama-addon.node +0 -0
  270. package/llamaBins/win-x64-cuda/.buildMetadata.json +1 -0
  271. package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
  272. package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
  273. package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
  274. package/package.json +39 -19
  275. package/dist/ChatPromptWrapper.d.ts +0 -11
  276. package/dist/ChatPromptWrapper.js +0 -20
  277. package/dist/ChatPromptWrapper.js.map +0 -1
  278. package/dist/chatWrappers/ChatMLChatPromptWrapper.d.ts +0 -12
  279. package/dist/chatWrappers/ChatMLChatPromptWrapper.js +0 -22
  280. package/dist/chatWrappers/ChatMLChatPromptWrapper.js.map +0 -1
  281. package/dist/chatWrappers/EmptyChatPromptWrapper.d.ts +0 -4
  282. package/dist/chatWrappers/EmptyChatPromptWrapper.js +0 -5
  283. package/dist/chatWrappers/EmptyChatPromptWrapper.js.map +0 -1
  284. package/dist/chatWrappers/FalconChatPromptWrapper.d.ts +0 -19
  285. package/dist/chatWrappers/FalconChatPromptWrapper.js +0 -33
  286. package/dist/chatWrappers/FalconChatPromptWrapper.js.map +0 -1
  287. package/dist/chatWrappers/GeneralChatPromptWrapper.d.ts +0 -19
  288. package/dist/chatWrappers/GeneralChatPromptWrapper.js +0 -38
  289. package/dist/chatWrappers/GeneralChatPromptWrapper.js.map +0 -1
  290. package/dist/chatWrappers/LlamaChatPromptWrapper.d.ts +0 -12
  291. package/dist/chatWrappers/LlamaChatPromptWrapper.js +0 -23
  292. package/dist/chatWrappers/LlamaChatPromptWrapper.js.map +0 -1
  293. package/dist/chatWrappers/createChatWrapperByBos.d.ts +0 -2
  294. package/dist/chatWrappers/createChatWrapperByBos.js +0 -14
  295. package/dist/chatWrappers/createChatWrapperByBos.js.map +0 -1
  296. package/dist/chatWrappers/generateContextTextFromConversationHistory.d.ts +0 -23
  297. package/dist/chatWrappers/generateContextTextFromConversationHistory.js +0 -47
  298. package/dist/chatWrappers/generateContextTextFromConversationHistory.js.map +0 -1
  299. package/dist/llamaEvaluator/LlamaBins.d.ts +0 -4
  300. package/dist/llamaEvaluator/LlamaBins.js +0 -5
  301. package/dist/llamaEvaluator/LlamaBins.js.map +0 -1
  302. package/dist/llamaEvaluator/LlamaChatSession.d.ts +0 -122
  303. package/dist/llamaEvaluator/LlamaChatSession.js +0 -236
  304. package/dist/llamaEvaluator/LlamaChatSession.js.map +0 -1
  305. package/dist/llamaEvaluator/LlamaContext.d.ts +0 -99
  306. package/dist/llamaEvaluator/LlamaContext.js +0 -143
  307. package/dist/llamaEvaluator/LlamaContext.js.map +0 -1
  308. package/dist/llamaEvaluator/LlamaGrammar.d.ts +0 -32
  309. package/dist/llamaEvaluator/LlamaGrammar.js.map +0 -1
  310. package/dist/llamaEvaluator/LlamaGrammarEvaluationState.d.ts +0 -14
  311. package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js +0 -16
  312. package/dist/llamaEvaluator/LlamaGrammarEvaluationState.js.map +0 -1
  313. package/dist/llamaEvaluator/LlamaJsonSchemaGrammar.js.map +0 -1
  314. package/dist/llamaEvaluator/LlamaModel.d.ts +0 -123
  315. package/dist/llamaEvaluator/LlamaModel.js +0 -74
  316. package/dist/llamaEvaluator/LlamaModel.js.map +0 -1
  317. package/dist/utils/binariesGithubRelease.js.map +0 -1
  318. package/dist/utils/clearLlamaBuild.d.ts +0 -1
  319. package/dist/utils/clearLlamaBuild.js +0 -12
  320. package/dist/utils/clearLlamaBuild.js.map +0 -1
  321. package/dist/utils/cloneLlamaCppRepo.d.ts +0 -2
  322. package/dist/utils/cloneLlamaCppRepo.js +0 -102
  323. package/dist/utils/cloneLlamaCppRepo.js.map +0 -1
  324. package/dist/utils/compileLLamaCpp.d.ts +0 -8
  325. package/dist/utils/compileLLamaCpp.js +0 -132
  326. package/dist/utils/compileLLamaCpp.js.map +0 -1
  327. package/dist/utils/getBin.d.ts +0 -53
  328. package/dist/utils/getBin.js +0 -78
  329. package/dist/utils/getBin.js.map +0 -1
  330. package/dist/utils/getReleaseInfo.d.ts +0 -7
  331. package/dist/utils/getReleaseInfo.js +0 -30
  332. package/dist/utils/getReleaseInfo.js.map +0 -1
  333. package/dist/utils/getTextCompletion.d.ts +0 -3
  334. package/dist/utils/getTextCompletion.js +0 -12
  335. package/dist/utils/getTextCompletion.js.map +0 -1
  336. package/dist/utils/usedBinFlag.d.ts +0 -6
  337. package/dist/utils/usedBinFlag.js +0 -15
  338. package/dist/utils/usedBinFlag.js.map +0 -1
  339. package/dist/utils/withLock.d.ts +0 -1
  340. package/dist/utils/withLock.js +0 -19
  341. package/dist/utils/withLock.js.map +0 -1
  342. package/llama/usedBin.json +0 -3
  343. package/llamaBins/mac-arm64/llama-addon.node +0 -0
  344. package/llamaBins/mac-x64/ggml-metal.metal +0 -6119
  345. /package/dist/{utils → bindings/utils}/binariesGithubRelease.d.ts +0 -0
  346. /package/llamaBins/{mac-arm64 → mac-arm64-metal}/ggml-metal.metal +0 -0
@@ -0,0 +1,219 @@
1
+ import { DisposeAggregator, DisposedError, EventRelay, withLock } from "lifecycle-utils";
2
+ import { defaultChatSystemPrompt } from "../../config.js";
3
+ import { appendUserMessageToChatHistory } from "../../utils/appendUserMessageToChatHistory.js";
4
+ import { LlamaChat } from "../LlamaChat/LlamaChat.js";
5
+ export class LlamaChatSession {
6
+ /** @internal */ _disposeAggregator = new DisposeAggregator();
7
+ /** @internal */ _autoDisposeSequence;
8
+ /** @internal */ _contextShift;
9
+ /** @internal */ _chatHistory;
10
+ /** @internal */ _lastEvaluation;
11
+ /** @internal */ _chat;
12
+ onDispose = new EventRelay();
13
+ /**
14
+ * @param options
15
+ */
16
+ constructor({ contextSequence, chatWrapper = "auto", systemPrompt = defaultChatSystemPrompt, autoDisposeSequence = true, contextShift }) {
17
+ if (contextSequence == null)
18
+ throw new Error("contextSequence cannot be null");
19
+ if (contextSequence.disposed)
20
+ throw new DisposedError();
21
+ this._contextShift = contextShift;
22
+ this._chatHistory = [{
23
+ type: "system",
24
+ text: systemPrompt
25
+ }];
26
+ this._chat = new LlamaChat({
27
+ autoDisposeSequence,
28
+ chatWrapper,
29
+ contextSequence
30
+ });
31
+ this._autoDisposeSequence = autoDisposeSequence;
32
+ this._disposeAggregator.add(this._chat.onDispose.createListener(() => {
33
+ this.dispose();
34
+ }));
35
+ this._disposeAggregator.add(this.onDispose.dispatchEvent);
36
+ }
37
+ dispose({ disposeSequence = this._autoDisposeSequence } = {}) {
38
+ if (this._chat == null)
39
+ return;
40
+ this._chat.dispose({ disposeSequence });
41
+ this._chat = null;
42
+ this._disposeAggregator.dispose();
43
+ }
44
+ /** @hidden */
45
+ [Symbol.dispose]() {
46
+ return this.dispose();
47
+ }
48
+ get disposed() {
49
+ return this._chat == null || this._chat.disposed;
50
+ }
51
+ get chatWrapper() {
52
+ if (this._chat == null)
53
+ throw new DisposedError();
54
+ return this._chat.chatWrapper;
55
+ }
56
+ get sequence() {
57
+ if (this._chat == null)
58
+ throw new DisposedError();
59
+ return this._chat.sequence;
60
+ }
61
+ get context() {
62
+ return this.sequence.context;
63
+ }
64
+ get model() {
65
+ return this.sequence.model;
66
+ }
67
+ /**
68
+ * @param prompt
69
+ * @param [options]
70
+ */
71
+ async prompt(prompt, { functions, documentFunctionParams, onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix = false, repeatPenalty } = {}) {
72
+ const { responseText } = await this.promptWithMeta(prompt, {
73
+ // this is a workaround to allow passing both `functions` and `grammar`
74
+ functions: functions,
75
+ documentFunctionParams: documentFunctionParams,
76
+ onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix, repeatPenalty
77
+ });
78
+ return responseText;
79
+ }
80
+ /**
81
+ * @param prompt
82
+ * @param [options]
83
+ */
84
+ async promptWithMeta(prompt, { functions, documentFunctionParams, onToken, signal, maxTokens, temperature, minP, topK, topP, grammar, trimWhitespaceSuffix = false, repeatPenalty, evaluationPriority } = {}) {
85
+ this._ensureNotDisposed();
86
+ if (grammar != null && grammar._llama !== this.model._llama)
87
+ throw new Error("The LlamaGrammar used by passed to this function was created with a different Llama instance than the one used by this sequence's model. Make sure you use the same Llama instance for both the model and the grammar.");
88
+ return await withLock(this, "prompt", async () => {
89
+ this._ensureNotDisposed();
90
+ if (this._chat == null)
91
+ throw new DisposedError();
92
+ let lastEvaluation = this._lastEvaluation;
93
+ let newChatHistory = appendUserMessageToChatHistory(this._chatHistory, prompt);
94
+ let newContextWindowChatHistory = lastEvaluation?.contextWindow == null
95
+ ? undefined
96
+ : appendUserMessageToChatHistory(lastEvaluation?.contextWindow, prompt);
97
+ newChatHistory.push({
98
+ type: "model",
99
+ response: []
100
+ });
101
+ if (newContextWindowChatHistory != null)
102
+ newContextWindowChatHistory.push({
103
+ type: "model",
104
+ response: []
105
+ });
106
+ // eslint-disable-next-line no-constant-condition
107
+ while (true) {
108
+ const { functionCall, lastEvaluation: currentLastEvaluation, metadata } = await this._chat.generateResponse(newChatHistory, {
109
+ functions,
110
+ documentFunctionParams,
111
+ grammar: grammar,
112
+ onToken,
113
+ signal,
114
+ repeatPenalty,
115
+ minP,
116
+ topK,
117
+ topP,
118
+ maxTokens,
119
+ temperature,
120
+ trimWhitespaceSuffix,
121
+ contextShift: {
122
+ ...this._contextShift,
123
+ lastEvaluationMetadata: lastEvaluation?.contextShiftMetadata
124
+ },
125
+ evaluationPriority,
126
+ lastEvaluationContextWindow: {
127
+ history: newContextWindowChatHistory,
128
+ minimumOverlapPercentageToPreventContextShift: 0.01
129
+ }
130
+ });
131
+ this._ensureNotDisposed();
132
+ lastEvaluation = currentLastEvaluation;
133
+ newChatHistory = lastEvaluation.cleanHistory;
134
+ if (functionCall != null) {
135
+ const functionDefinition = functions?.[functionCall.functionName];
136
+ if (functionDefinition == null)
137
+ throw new Error(`The model tried to call function "${functionCall.functionName}" which is not defined`);
138
+ const functionCallResult = await functionDefinition.handler(functionCall.params);
139
+ this._ensureNotDisposed();
140
+ newChatHistory = addFunctionCallToChatHistory({
141
+ chatHistory: newChatHistory,
142
+ functionName: functionCall.functionName,
143
+ functionDescription: functionDefinition.description,
144
+ callParams: functionCall.params,
145
+ callResult: functionCallResult,
146
+ raw: functionCall.raw + this._chat.chatWrapper.generateFunctionCallResult(functionCall.functionName, functionCall.params, functionCallResult)
147
+ });
148
+ newContextWindowChatHistory = addFunctionCallToChatHistory({
149
+ chatHistory: lastEvaluation.contextWindow,
150
+ functionName: functionCall.functionName,
151
+ functionDescription: functionDefinition.description,
152
+ callParams: functionCall.params,
153
+ callResult: functionCallResult,
154
+ raw: functionCall.raw + this._chat.chatWrapper.generateFunctionCallResult(functionCall.functionName, functionCall.params, functionCallResult)
155
+ });
156
+ lastEvaluation.cleanHistory = newChatHistory;
157
+ lastEvaluation.contextWindow = newContextWindowChatHistory;
158
+ continue;
159
+ }
160
+ this._lastEvaluation = lastEvaluation;
161
+ this._chatHistory = newChatHistory;
162
+ const lastModelResponseItem = getLastModelResponseItem(newChatHistory);
163
+ return {
164
+ response: lastModelResponseItem.response,
165
+ responseText: lastModelResponseItem.response
166
+ .filter((item) => typeof item === "string")
167
+ .join(""),
168
+ stopReason: metadata.stopReason,
169
+ remainingGenerationAfterStop: metadata.remainingGenerationAfterStop
170
+ };
171
+ }
172
+ });
173
+ }
174
+ getChatHistory() {
175
+ return structuredClone(this._chatHistory);
176
+ }
177
+ getLastEvaluationContextWindow() {
178
+ if (this._lastEvaluation == null)
179
+ return null;
180
+ return structuredClone(this._lastEvaluation?.contextWindow);
181
+ }
182
+ setChatHistory(chatHistory) {
183
+ this._chatHistory = structuredClone(chatHistory);
184
+ this._lastEvaluation = undefined;
185
+ }
186
+ /** @internal */
187
+ _ensureNotDisposed() {
188
+ if (this.disposed)
189
+ throw new DisposedError();
190
+ }
191
+ }
192
+ function addFunctionCallToChatHistory({ chatHistory, functionName, functionDescription, callParams, callResult, raw }) {
193
+ const newChatHistory = chatHistory.slice();
194
+ if (newChatHistory.length === 0 || newChatHistory[newChatHistory.length - 1].type !== "model")
195
+ newChatHistory.push({
196
+ type: "model",
197
+ response: []
198
+ });
199
+ const lastModelResponseItem = newChatHistory[newChatHistory.length - 1];
200
+ const newLastModelResponseItem = { ...lastModelResponseItem };
201
+ newChatHistory[newChatHistory.length - 1] = newLastModelResponseItem;
202
+ const modelResponse = newLastModelResponseItem.response.slice();
203
+ newLastModelResponseItem.response = modelResponse;
204
+ modelResponse.push({
205
+ type: "functionCall",
206
+ name: functionName,
207
+ description: functionDescription,
208
+ params: callParams,
209
+ result: callResult,
210
+ raw
211
+ });
212
+ return newChatHistory;
213
+ }
214
+ function getLastModelResponseItem(chatHistory) {
215
+ if (chatHistory.length === 0 || chatHistory[chatHistory.length - 1].type !== "model")
216
+ throw new Error("Expected chat history to end with a model response");
217
+ return chatHistory[chatHistory.length - 1];
218
+ }
219
+ //# sourceMappingURL=LlamaChatSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LlamaChatSession.js","sourceRoot":"","sources":["../../../src/evaluator/LlamaChatSession/LlamaChatSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,iBAAiB,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AACvF,OAAO,EAAC,uBAAuB,EAAC,MAAM,iBAAiB,CAAC;AAGxD,OAAO,EAAC,8BAA8B,EAAC,MAAM,+CAA+C,CAAC;AAG7F,OAAO,EAAC,SAAS,EAAkD,MAAM,2BAA2B,CAAC;AA2IrG,MAAM,OAAO,gBAAgB;IACzB,gBAAgB,CAAkB,kBAAkB,GAAG,IAAI,iBAAiB,EAAE,CAAC;IAC/E,gBAAgB,CAAkB,oBAAoB,CAAU;IAChE,gBAAgB,CAAkB,aAAa,CAAuC;IACtF,gBAAgB,CAAS,YAAY,CAAoB;IACzD,gBAAgB,CAAS,eAAe,CAAuC;IAC/E,gBAAgB,CAAS,KAAK,CAAmB;IAEjC,SAAS,GAAG,IAAI,UAAU,EAAQ,CAAC;IAEnD;;OAEG;IACH,YAAmB,EACf,eAAe,EACf,WAAW,GAAG,MAAM,EACpB,YAAY,GAAG,uBAAuB,EACtC,mBAAmB,GAAG,IAAI,EAC1B,YAAY,EACU;QACtB,IAAI,eAAe,IAAI,IAAI;YACvB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;QAEtD,IAAI,eAAe,CAAC,QAAQ;YACxB,MAAM,IAAI,aAAa,EAAE,CAAC;QAE9B,IAAI,CAAC,aAAa,GAAG,YAAY,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fJson/types.js";
2
+ import { ChatSessionModelFunction } from "../../../types.js";
3
+ export declare function defineChatSessionFunction<const Params extends GbnfJsonSchema | undefined>({ description, params, handler }: {
4
+ description?: string;
5
+ params?: Params;
6
+ handler: (params: GbnfJsonSchemaToType<Params>) => any;
7
+ }): ChatSessionModelFunction<Params>;
@@ -0,0 +1,8 @@
1
+ export function defineChatSessionFunction({ description, params, handler }) {
2
+ return {
3
+ description,
4
+ params,
5
+ handler
6
+ };
7
+ }
8
+ //# sourceMappingURL=defineChatSessionFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineChatSessionFunction.js","sourceRoot":"","sources":["../../../../src/evaluator/LlamaChatSession/utils/defineChatSessionFunction.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,yBAAyB,CAAkD,EACvF,WAAW,EACX,MAAM,EACN,OAAO,EAKV;IACG,OAAO;QACH,WAAW;QACX,MAAM;QACN,OAAO;KACV,CAAC;AACN,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { EventRelay } from "lifecycle-utils";
2
+ import { Token } from "../../types.js";
3
+ import { LlamaModel } from "../LlamaModel.js";
4
+ import { LlamaGrammarEvaluationState } from "../LlamaGrammarEvaluationState.js";
5
+ import { ContextShiftOptions, ContextTokensDeleteRange, EvaluationPriority, LlamaContextOptions, LlamaContextSequenceRepeatPenalty } from "./types.js";
6
+ export declare class LlamaContext {
7
+ readonly onDispose: EventRelay<void>;
8
+ /**
9
+ * @param options
10
+ */
11
+ constructor({ model, sequences, seed, contextSize, batchSize, threads, batching: { dispatchSchedule: batchingDispatchSchedule, itemsPrioritizingStrategy: batchingItemsPrioritizingStrategy }, _embedding, _noSeed }: LlamaContextOptions);
12
+ dispose(): void;
13
+ /** @hidden */
14
+ [Symbol.dispose](): void;
15
+ get disposed(): boolean;
16
+ get model(): LlamaModel;
17
+ get contextSize(): number;
18
+ get batchSize(): number;
19
+ getAllocatedContextSize(): number;
20
+ get totalSequences(): number;
21
+ get sequencesLeft(): number;
22
+ /**
23
+ * Before calling this method, make sure to call `sequencesLeft` to check if there are any sequences left.
24
+ * When there are no sequences left, this method will throw an error.
25
+ * @param [options]
26
+ */
27
+ getSequence({ contextShift: { size: contextShiftSize, strategy: contextShiftStrategy } }?: {
28
+ contextShift?: ContextShiftOptions;
29
+ }): LlamaContextSequence;
30
+ dispatchPendingBatch(): void;
31
+ printTimings(): Promise<void>;
32
+ }
33
+ export declare class LlamaContextSequence {
34
+ readonly onDispose: EventRelay<void>;
35
+ private constructor();
36
+ dispose(): void;
37
+ /** @hidden */
38
+ [Symbol.dispose](): void;
39
+ get disposed(): boolean;
40
+ get context(): LlamaContext;
41
+ get model(): LlamaModel;
42
+ get nextTokenIndex(): number;
43
+ get contextTokens(): Token[];
44
+ get isLoadedToMemory(): boolean;
45
+ compareContextTokens(tokens: Token[]): {
46
+ firstDifferentIndex: number;
47
+ };
48
+ /**
49
+ * Clear the history of the sequence.
50
+ * If `prependBos` was enabled, the BOS token will be prepended to the sequence again.
51
+ */
52
+ clearHistory(): Promise<void>;
53
+ /**
54
+ * Erase context tokens in the provided ranges to free up space for new tokens to be generated.
55
+ * the start and end of each range are exclusive.
56
+ * For example, the range `{start: 0, end: 1}` will remove the token at the `0` index only.
57
+ */
58
+ eraseContextTokenRanges(ranges: ContextTokensDeleteRange[]): Promise<void>;
59
+ /**
60
+ * @param tokens
61
+ * @param [options]
62
+ */
63
+ evaluate(tokens: Token[], { temperature, minP, topK, topP, grammarEvaluationState, repeatPenalty, evaluationPriority, contextShift: { size: contextShiftSize, strategy: contextShiftStrategy }, yieldEosToken }?: {
64
+ temperature?: number;
65
+ minP?: number;
66
+ topK?: number;
67
+ topP?: number;
68
+ grammarEvaluationState?: LlamaGrammarEvaluationState | (() => LlamaGrammarEvaluationState | undefined);
69
+ repeatPenalty?: LlamaContextSequenceRepeatPenalty;
70
+ /**
71
+ * When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be
72
+ * evaluated based on the strategy chosen for the context.
73
+ * By default, the `"maximumParallelism"` strategy is used, which will try to evaluate as many sequences in parallel as possible,
74
+ * but at some point, it'll have to choose which sequences to evaluate more tokens of, so it'll prioritize the sequences with the
75
+ * highest evaluation priority.
76
+ * Also, a custom strategy can be used to prioritize the sequences differently, but generally, the higher the evaluation priority
77
+ * is, the more likely and more tokens will be evaluated for that sequence in the next queued batch.
78
+ */
79
+ evaluationPriority?: EvaluationPriority;
80
+ /** Override the sequence context shift options for this evaluation */
81
+ contextShift?: ContextShiftOptions;
82
+ /**
83
+ * Yield the EOS token when it's generated.
84
+ * When `false` the generation will stop when the EOS token is generated and the EOS token won't be yielded.
85
+ * Defaults to `false`.
86
+ */
87
+ yieldEosToken?: boolean;
88
+ }): AsyncGenerator<Token, void>;
89
+ /**
90
+ * Evaluate the provided tokens into the context sequence without generating new tokens.
91
+ * @param tokens
92
+ * @param [options]
93
+ */
94
+ evaluateWithoutGeneratingNewTokens(tokens: Token[], { evaluationPriority, contextShift: { size: contextShiftSize, strategy: contextShiftStrategy } }?: {
95
+ grammarEvaluationState?: LlamaGrammarEvaluationState;
96
+ /**
97
+ * When a lot of tokens are queued for the next batch, more than the configured `batchSize`, the tokens for each sequence will be
98
+ * evaluated based on the strategy chosen for the context.
99
+ * By default, the `"maximumParallelism"` strategy is used, which will try to evaluate as many sequences in parallel as possible,
100
+ * but at some point, it'll have to choose which sequences to evaluate more tokens of, so it'll prioritize the sequences with the
101
+ * highest evaluation priority.
102
+ * Also, a custom strategy can be used to prioritize the sequences differently, but generally, the higher the evaluation priority
103
+ * is, the more likely and more tokens will be evaluated for that sequence in the next queued batch.
104
+ */
105
+ evaluationPriority?: EvaluationPriority;
106
+ /** Override the sequence context shift options for this evaluation */
107
+ contextShift?: ContextShiftOptions;
108
+ }): Promise<void>;
109
+ }