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
@@ -1,23 +0,0 @@
1
- import { ChatPromptWrapper } from "../ChatPromptWrapper.js";
2
- import { ConversationInteraction } from "../types.js";
3
- /**
4
- * Generate context text to load into a model context from a conversation history.
5
- * @param {ChatPromptWrapper} chatPromptWrapper
6
- * @param {ConversationInteraction[]} conversationHistory
7
- * @param {object} [options]
8
- * @param {string} [options.systemPrompt]
9
- * @param {number} [options.currentPromptIndex]
10
- * @param {string | null} [options.lastStopString]
11
- * @param {string | null} [options.lastStopStringSuffix]
12
- * @returns {{text: string, stopString: (string | null), stopStringSuffix: (string | null)}}
13
- */
14
- export declare function generateContextTextFromConversationHistory(chatPromptWrapper: ChatPromptWrapper, conversationHistory: readonly ConversationInteraction[], { systemPrompt, currentPromptIndex, lastStopString, lastStopStringSuffix }?: {
15
- systemPrompt?: string;
16
- currentPromptIndex?: number;
17
- lastStopString?: string | null;
18
- lastStopStringSuffix?: string | null;
19
- }): {
20
- text: string;
21
- stopString: string | null;
22
- stopStringSuffix: string | null;
23
- };
@@ -1,47 +0,0 @@
1
- import { defaultChatSystemPrompt } from "../config.js";
2
- /**
3
- * Generate context text to load into a model context from a conversation history.
4
- * @param {ChatPromptWrapper} chatPromptWrapper
5
- * @param {ConversationInteraction[]} conversationHistory
6
- * @param {object} [options]
7
- * @param {string} [options.systemPrompt]
8
- * @param {number} [options.currentPromptIndex]
9
- * @param {string | null} [options.lastStopString]
10
- * @param {string | null} [options.lastStopStringSuffix]
11
- * @returns {{text: string, stopString: (string | null), stopStringSuffix: (string | null)}}
12
- */
13
- export function generateContextTextFromConversationHistory(chatPromptWrapper, conversationHistory, { systemPrompt = defaultChatSystemPrompt, currentPromptIndex = 0, lastStopString = null, lastStopStringSuffix = null } = {}) {
14
- let res = "";
15
- for (let i = 0; i < conversationHistory.length; i++) {
16
- const interaction = conversationHistory[i];
17
- const wrappedPrompt = chatPromptWrapper.wrapPrompt(interaction.prompt, {
18
- systemPrompt,
19
- promptIndex: currentPromptIndex,
20
- lastStopString,
21
- lastStopStringSuffix
22
- });
23
- const stopStrings = chatPromptWrapper.getStopStrings();
24
- const defaultStopString = chatPromptWrapper.getDefaultStopString();
25
- const stopStringsToCheckInResponse = new Set([...stopStrings, defaultStopString]);
26
- currentPromptIndex++;
27
- lastStopString = null;
28
- lastStopStringSuffix = null;
29
- res += wrappedPrompt;
30
- for (const stopString of stopStringsToCheckInResponse) {
31
- if (interaction.response.includes(stopString)) {
32
- console.error(`Stop string "${stopString}" was found in model response of conversation interaction index ${i}`, { interaction, stopString });
33
- throw new Error("A stop string cannot be in a conversation history interaction model response");
34
- }
35
- }
36
- res += interaction.response;
37
- res += defaultStopString;
38
- lastStopString = defaultStopString;
39
- lastStopStringSuffix = "";
40
- }
41
- return {
42
- text: res,
43
- stopString: lastStopString,
44
- stopStringSuffix: lastStopStringSuffix
45
- };
46
- }
47
- //# sourceMappingURL=generateContextTextFromConversationHistory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateContextTextFromConversationHistory.js","sourceRoot":"","sources":["../../src/chatWrappers/generateContextTextFromConversationHistory.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AAIrD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0CAA0C,CACtD,iBAAoC,EACpC,mBAAuD,EACvD,EACI,YAAY,GAAG,uBAAuB,EAAE,kBAAkB,GAAG,CAAC,EAAE,cAAc,GAAG,IAAI,EAAE,oBAAoB,GAAG,IAAI,KAGlH,EAAE;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
@@ -1,4 +0,0 @@
1
- import { type LLAMAModel, type LLAMAContext, type LLAMAGrammar, type LLAMAGrammarEvaluationState } from "../utils/getBin.js";
2
- export declare const llamaCppNode: import("../utils/getBin.js").LlamaCppNodeModule;
3
- declare const LLAMAModel: LLAMAModel, LLAMAContext: LLAMAContext, LLAMAGrammar: LLAMAGrammar, LLAMAGrammarEvaluationState: LLAMAGrammarEvaluationState;
4
- export { LLAMAModel, LLAMAContext, LLAMAGrammar, LLAMAGrammarEvaluationState };
@@ -1,5 +0,0 @@
1
- import { loadBin } from "../utils/getBin.js";
2
- export const llamaCppNode = await loadBin();
3
- const { LLAMAModel, LLAMAContext, LLAMAGrammar, LLAMAGrammarEvaluationState } = llamaCppNode;
4
- export { LLAMAModel, LLAMAContext, LLAMAGrammar, LLAMAGrammarEvaluationState };
5
- //# sourceMappingURL=LlamaBins.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LlamaBins.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaBins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAA0F,MAAM,oBAAoB,CAAC;AAEpI,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,OAAO,EAAE,CAAC;AAC5C,MAAM,EAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,2BAA2B,EAAC,GAAG,YAAY,CAAC;AAE3F,OAAO,EAAC,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,2BAA2B,EAAC,CAAC"}
@@ -1,122 +0,0 @@
1
- /// <reference types="node" />
2
- import { ChatPromptWrapper } from "../ChatPromptWrapper.js";
3
- import { ConversationInteraction, Token } from "../types.js";
4
- import { LlamaContext } from "./LlamaContext.js";
5
- import { LlamaGrammar } from "./LlamaGrammar.js";
6
- export type LlamaChatSessionOptions = {
7
- context: LlamaContext;
8
- printLLamaSystemInfo?: boolean;
9
- /** GeneralChatPromptWrapper is ued by default */
10
- promptWrapper?: ChatPromptWrapper | "auto";
11
- systemPrompt?: string;
12
- /** Conversation history to load into the context to continue an existing conversation */
13
- conversationHistory?: readonly ConversationInteraction[];
14
- };
15
- export type LLamaChatPromptOptions = {
16
- onToken?: (tokens: Token[]) => void;
17
- signal?: AbortSignal;
18
- maxTokens?: number;
19
- /**
20
- * Temperature is a hyperparameter that controls the randomness of the generated text.
21
- * It affects the probability distribution of the model's output tokens.
22
- * A higher temperature (e.g., 1.5) makes the output more random and creative,
23
- * while a lower temperature (e.g., 0.5) makes the output more focused, deterministic, and conservative.
24
- * The suggested temperature is 0.8, which provides a balance between randomness and determinism.
25
- * At the extreme, a temperature of 0 will always pick the most likely next token, leading to identical outputs in each run.
26
- *
27
- * Set to `0` to disable.
28
- * Disabled by default (set to `0`).
29
- */
30
- temperature?: number;
31
- /**
32
- * Limits the model to consider only the K most likely next tokens for sampling at each step of sequence generation.
33
- * An integer number between `1` and the size of the vocabulary.
34
- * Set to `0` to disable (which uses the full vocabulary).
35
- *
36
- * Only relevant when `temperature` is set to a value greater than 0.
37
- */
38
- topK?: number;
39
- /**
40
- * Dynamically selects the smallest set of tokens whose cumulative probability exceeds the threshold P,
41
- * and samples the next token only from this set.
42
- * A float number between `0` and `1`.
43
- * Set to `1` to disable.
44
- *
45
- * Only relevant when `temperature` is set to a value greater than `0`.
46
- */
47
- topP?: number;
48
- grammar?: LlamaGrammar;
49
- /**
50
- * Trim whitespace from the end of the generated text
51
- * Disabled by default.
52
- */
53
- trimWhitespaceSuffix?: boolean;
54
- repeatPenalty?: false | LlamaChatSessionRepeatPenalty;
55
- };
56
- export type LlamaChatSessionRepeatPenalty = {
57
- /**
58
- * Number of recent tokens generated by the model to apply penalties to repetition of.
59
- * Defaults to `64`.
60
- */
61
- lastTokens?: number;
62
- punishTokensFilter?: (tokens: Token[]) => Token[];
63
- /**
64
- * Penalize new line tokens.
65
- * Enabled by default.
66
- */
67
- penalizeNewLine?: boolean;
68
- /**
69
- * The relative amount to lower the probability of the tokens in `punishTokens` by
70
- * Defaults to `1.1`.
71
- * Set to `1` to disable.
72
- */
73
- penalty?: number;
74
- /**
75
- * For n time a token is in the `punishTokens` array, lower its probability by `n * frequencyPenalty`
76
- * Disabled by default (`0`).
77
- * Set to a value between `0` and `1` to enable.
78
- */
79
- frequencyPenalty?: number;
80
- /**
81
- * Lower the probability of all the tokens in the `punishTokens` array by `presencePenalty`
82
- * Disabled by default (`0`).
83
- * Set to a value between `0` and `1` to enable.
84
- */
85
- presencePenalty?: number;
86
- };
87
- export declare class LlamaChatSession {
88
- private readonly _systemPrompt;
89
- private readonly _printLLamaSystemInfo;
90
- private readonly _promptWrapper;
91
- private _promptIndex;
92
- private _initialized;
93
- private _lastStopString;
94
- private _lastStopStringSuffix;
95
- private _conversationHistoryToLoad;
96
- private readonly _ctx;
97
- /**
98
- * @param {LlamaChatSessionOptions} options
99
- */
100
- constructor({ context, printLLamaSystemInfo, promptWrapper, systemPrompt, conversationHistory }: LlamaChatSessionOptions);
101
- get initialized(): boolean;
102
- get context(): LlamaContext;
103
- init(): Promise<void>;
104
- /**
105
- * @param {string} prompt
106
- * @param {object} options
107
- * @returns {Promise<string>}
108
- */
109
- prompt(prompt: string, { onToken, signal, maxTokens, temperature, topK, topP, grammar, trimWhitespaceSuffix, repeatPenalty }?: LLamaChatPromptOptions): Promise<string>;
110
- /**
111
- * @param {string} prompt
112
- * @param {LLamaChatPromptOptions} options
113
- */
114
- promptWithMeta(prompt: string, { onToken, signal, maxTokens, temperature, topK, topP, grammar, trimWhitespaceSuffix, repeatPenalty }?: LLamaChatPromptOptions): Promise<{
115
- text: string;
116
- stopReason: "maxTokens" | "eosToken" | "stopString";
117
- stopString: string | null;
118
- stopStringSuffix: string | null;
119
- }>;
120
- private _evalTokens;
121
- private _checkStopString;
122
- }
@@ -1,236 +0,0 @@
1
- import { defaultChatSystemPrompt } from "../config.js";
2
- import { withLock } from "../utils/withLock.js";
3
- import { AbortError } from "../AbortError.js";
4
- import { GeneralChatPromptWrapper } from "../chatWrappers/GeneralChatPromptWrapper.js";
5
- import { getChatWrapperByBos } from "../chatWrappers/createChatWrapperByBos.js";
6
- import { generateContextTextFromConversationHistory } from "../chatWrappers/generateContextTextFromConversationHistory.js";
7
- import { removeNullFields } from "../utils/removeNullFields.js";
8
- import { LlamaModel } from "./LlamaModel.js";
9
- import { LlamaGrammarEvaluationState } from "./LlamaGrammarEvaluationState.js";
10
- const UNKNOWN_UNICODE_CHAR = "\ufffd";
11
- export class LlamaChatSession {
12
- _systemPrompt;
13
- _printLLamaSystemInfo;
14
- _promptWrapper;
15
- _promptIndex = 0;
16
- _initialized = false;
17
- _lastStopString = null;
18
- _lastStopStringSuffix = null;
19
- _conversationHistoryToLoad = null;
20
- _ctx;
21
- /**
22
- * @param {LlamaChatSessionOptions} options
23
- */
24
- constructor({ context, printLLamaSystemInfo = false, promptWrapper = new GeneralChatPromptWrapper(), systemPrompt = defaultChatSystemPrompt, conversationHistory }) {
25
- this._ctx = context;
26
- this._printLLamaSystemInfo = printLLamaSystemInfo;
27
- this._systemPrompt = systemPrompt;
28
- this._conversationHistoryToLoad = (conversationHistory != null && conversationHistory.length > 0)
29
- ? conversationHistory
30
- : null;
31
- if (promptWrapper === "auto") {
32
- const chatWrapper = getChatWrapperByBos(context.getBosString());
33
- if (chatWrapper != null)
34
- this._promptWrapper = new chatWrapper();
35
- else
36
- this._promptWrapper = new GeneralChatPromptWrapper();
37
- }
38
- else
39
- this._promptWrapper = promptWrapper;
40
- }
41
- get initialized() {
42
- return this._initialized;
43
- }
44
- get context() {
45
- return this._ctx;
46
- }
47
- async init() {
48
- await withLock(this, "init", async () => {
49
- if (this._initialized)
50
- return;
51
- if (this._printLLamaSystemInfo)
52
- console.log("Llama system info", LlamaModel.systemInfo);
53
- this._initialized = true;
54
- });
55
- }
56
- /**
57
- * @param {string} prompt
58
- * @param {object} options
59
- * @returns {Promise<string>}
60
- */
61
- async prompt(prompt, { onToken, signal, maxTokens, temperature, topK, topP, grammar = this.context._chatGrammar, trimWhitespaceSuffix = false, repeatPenalty } = {}) {
62
- const { text } = await this.promptWithMeta(prompt, {
63
- onToken, signal, maxTokens, temperature, topK, topP, grammar, trimWhitespaceSuffix, repeatPenalty
64
- });
65
- return text;
66
- }
67
- /**
68
- * @param {string} prompt
69
- * @param {LLamaChatPromptOptions} options
70
- */
71
- async promptWithMeta(prompt, { onToken, signal, maxTokens, temperature, topK, topP, grammar = this.context._chatGrammar, trimWhitespaceSuffix = false, repeatPenalty } = {}) {
72
- if (!this.initialized)
73
- await this.init();
74
- return await withLock(this, "prompt", async () => {
75
- let promptText = "";
76
- if (this._promptIndex == 0 && this._conversationHistoryToLoad != null) {
77
- const { text, stopString, stopStringSuffix } = generateContextTextFromConversationHistory(this._promptWrapper, this._conversationHistoryToLoad, {
78
- systemPrompt: this._systemPrompt,
79
- currentPromptIndex: this._promptIndex,
80
- lastStopString: this._lastStopString,
81
- lastStopStringSuffix: this._promptIndex == 0
82
- ? (this._ctx.prependBos
83
- ? this._ctx.getBosString()
84
- : null)
85
- : this._lastStopStringSuffix
86
- });
87
- promptText += text;
88
- this._lastStopString = stopString;
89
- this._lastStopStringSuffix = stopStringSuffix;
90
- this._promptIndex += this._conversationHistoryToLoad.length;
91
- this._conversationHistoryToLoad = null;
92
- }
93
- promptText += this._promptWrapper.wrapPrompt(prompt, {
94
- systemPrompt: this._systemPrompt,
95
- promptIndex: this._promptIndex,
96
- lastStopString: this._lastStopString,
97
- lastStopStringSuffix: this._promptIndex == 0
98
- ? (this._ctx.prependBos
99
- ? this._ctx.getBosString()
100
- : null)
101
- : this._lastStopStringSuffix
102
- });
103
- this._promptIndex++;
104
- this._lastStopString = null;
105
- this._lastStopStringSuffix = null;
106
- const { text, stopReason, stopString, stopStringSuffix } = await this._evalTokens(this._ctx.encode(promptText), {
107
- onToken, signal, maxTokens, temperature, topK, topP, grammar, trimWhitespaceSuffix,
108
- repeatPenalty: repeatPenalty == false ? { lastTokens: 0 } : repeatPenalty
109
- });
110
- this._lastStopString = stopString;
111
- this._lastStopStringSuffix = stopStringSuffix;
112
- return {
113
- text,
114
- stopReason,
115
- stopString,
116
- stopStringSuffix
117
- };
118
- });
119
- }
120
- async _evalTokens(tokens, { onToken, signal, maxTokens, temperature, topK, topP, grammar = this.context._chatGrammar, trimWhitespaceSuffix = false, repeatPenalty: { lastTokens: repeatPenaltyLastTokens = 64, punishTokensFilter, penalizeNewLine, penalty, frequencyPenalty, presencePenalty } = {} } = {}) {
121
- let stopStrings = this._promptWrapper.getStopStrings();
122
- if (grammar != null)
123
- stopStrings = stopStrings.concat(grammar.stopStrings);
124
- const stopStringIndexes = Array(stopStrings.length).fill(0);
125
- const skippedChunksQueue = [];
126
- const res = [];
127
- const grammarEvaluationState = grammar != null
128
- ? new LlamaGrammarEvaluationState({ grammar })
129
- : undefined;
130
- const repeatPenaltyEnabled = repeatPenaltyLastTokens > 0;
131
- let stopReason = "eosToken";
132
- const getPenaltyTokens = () => {
133
- let punishTokens = res.slice(-repeatPenaltyLastTokens);
134
- if (punishTokensFilter != null)
135
- punishTokens = punishTokensFilter(punishTokens);
136
- if (!penalizeNewLine) {
137
- const nlToken = this.context.getNlToken();
138
- if (nlToken != null)
139
- punishTokens = punishTokens.filter(token => token !== nlToken);
140
- }
141
- return Uint32Array.from(punishTokens);
142
- };
143
- const evaluationIterator = this._ctx.evaluate(tokens, removeNullFields({
144
- temperature, topK, topP, grammarEvaluationState,
145
- repeatPenalty: !repeatPenaltyEnabled ? undefined : {
146
- punishTokens: getPenaltyTokens,
147
- penalty,
148
- frequencyPenalty,
149
- presencePenalty
150
- }
151
- }));
152
- for await (const chunk of evaluationIterator) {
153
- if (signal?.aborted)
154
- throw new AbortError();
155
- const tokenStr = this._ctx.decode(Uint32Array.from([chunk]));
156
- const { shouldReturn, skipTokenEvent, stopString, stopStringSuffix } = this._checkStopString(tokenStr, stopStrings, stopStringIndexes);
157
- if (shouldReturn) {
158
- skippedChunksQueue.push(chunk);
159
- const skippedChunksText = skippedChunksQueue.length > 0
160
- ? this._ctx.decode(Uint32Array.from(skippedChunksQueue))
161
- : "";
162
- let [queuedTextBeforeStopString] = skippedChunksText.split(stopString);
163
- if (grammar?.trimWhitespaceSuffix || trimWhitespaceSuffix)
164
- queuedTextBeforeStopString = queuedTextBeforeStopString.trimEnd();
165
- if (queuedTextBeforeStopString.length > 0) {
166
- const beforeStopStringTokens = Array.from(this._ctx.encode(queuedTextBeforeStopString));
167
- res.push(...beforeStopStringTokens);
168
- onToken?.(beforeStopStringTokens);
169
- skippedChunksQueue.length = 0;
170
- }
171
- stopReason = "stopString";
172
- return {
173
- text: this._ctx.decode(Uint32Array.from(res)),
174
- stopReason,
175
- stopString,
176
- stopStringSuffix
177
- };
178
- }
179
- // if the token is unknown, it means it's not complete character
180
- if (tokenStr === UNKNOWN_UNICODE_CHAR || skipTokenEvent || ((grammar?.trimWhitespaceSuffix || trimWhitespaceSuffix) && tokenStr.trim() === "")) {
181
- skippedChunksQueue.push(chunk);
182
- continue;
183
- }
184
- if (skippedChunksQueue.length > 0) {
185
- res.push(...skippedChunksQueue);
186
- onToken?.(skippedChunksQueue);
187
- skippedChunksQueue.length = 0;
188
- }
189
- res.push(chunk);
190
- onToken?.([chunk]);
191
- if (maxTokens != null && maxTokens > 0 && res.length >= maxTokens) {
192
- stopReason = "maxTokens";
193
- break;
194
- }
195
- }
196
- let resText = this._ctx.decode(Uint32Array.from(res));
197
- if (grammar?.trimWhitespaceSuffix || trimWhitespaceSuffix)
198
- resText = resText.trimEnd();
199
- return {
200
- text: resText,
201
- stopReason,
202
- stopString: null,
203
- stopStringSuffix: null
204
- };
205
- }
206
- _checkStopString(tokenStr, stopStrings, stopStringIndexes) {
207
- let skipTokenEvent = false;
208
- for (let stopStringIndex = 0; stopStringIndex < stopStrings.length; stopStringIndex++) {
209
- const stopString = stopStrings[stopStringIndex];
210
- let localShouldSkipTokenEvent = false;
211
- let i = 0;
212
- for (; i < tokenStr.length && stopStringIndexes[stopStringIndex] !== stopString.length; i++) {
213
- if (tokenStr[i] === stopString[stopStringIndexes[stopStringIndex]]) {
214
- stopStringIndexes[stopStringIndex]++;
215
- localShouldSkipTokenEvent = true;
216
- }
217
- else {
218
- stopStringIndexes[stopStringIndex] = 0;
219
- localShouldSkipTokenEvent = false;
220
- }
221
- }
222
- if (stopStringIndexes[stopStringIndex] === stopString.length) {
223
- return {
224
- shouldReturn: true,
225
- stopString,
226
- stopStringSuffix: tokenStr.length === i
227
- ? null
228
- : tokenStr.slice(i)
229
- };
230
- }
231
- skipTokenEvent ||= localShouldSkipTokenEvent;
232
- }
233
- return { skipTokenEvent };
234
- }
235
- }
236
- //# sourceMappingURL=LlamaChatSession.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"LlamaChatSession.js","sourceRoot":"","sources":["../../src/llamaEvaluator/LlamaChatSession.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,uBAAuB,EAAC,MAAM,cAAc,CAAC;AACrD,OAAO,EAAC,QAAQ,EAAC,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAC,UAAU,EAAC,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAC,wBAAwB,EAAC,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAC,mBAAmB,EAAC,MAAM,2CAA2C,CAAC;AAE9E,OAAO,EAAC,0CAA0C,EAAC,MAAM,+DAA+D,CAAC;AACzH,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAG3C,OAAO,EAAC,2BAA2B,EAAC,MAAM,kCAAkC,CAAC;AAE7E,MAAM,oBAAoB,GAAG,QAAQ,CAAC;AAqGtC,MAAM,OAAO,gBAAgB;IACR,aAAa,CAAS;IACtB,qBAAqB,CAAU;IAC/B,cAAc,CAAoB;IAC3C,YAAY,GAAW,CAAC,CAAC;IACzB,YAAY,GAAY,KAAK,CAAC;IAC9B,eAAe,GAAkB,IAAI,CAAC;IACtC,qBAAqB,GAAkB,IAAI,CAAC;IAC5C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AAe,CAAC,KAAK,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBACzF,IAAI,QAAQ,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC,EAAE;oBAChE,iBAAiB,CAAC,eAAe,CAAC,EAAE,CAAC;oBACrC,yBAAyB,GAAG,IAAI,CAAC;iBACpC;qBAAM;oBACH,iBAAiB,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;oBACvC,yBAAyB,GAAG,KAAK,CAAC;iBACrC;aACJ;YAED,IAAI,iBAAiB,CAAC,eAAe,CAAC,KAAK,UAAU,CAAC,MAAM,EAAE;gBAC1D,OAAO;oBACH,YAAY,EAAE,IAAI;oBAClB,UAAU;oBACV,gBAAgB,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC;wBACnC,CAAC,CAAC,IAAI;wBACN,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;iBAC1B,CAAC;aACL;YAED,cAAc,KAAK,yBAAyB,CAAC;SAChD;QAED,OAAO,EAAC,cAAc,EAAC,CAAC;IAC5B,CAAC;CACJ"}
@@ -1,99 +0,0 @@
1
- import { Token } from "../types.js";
2
- import { LlamaModel } from "./LlamaModel.js";
3
- import { LlamaGrammarEvaluationState } from "./LlamaGrammarEvaluationState.js";
4
- import { LlamaGrammar } from "./LlamaGrammar.js";
5
- export type LlamaContextOptions = {
6
- model: LlamaModel;
7
- prependBos?: boolean;
8
- /**
9
- * @deprecated use the `grammar` option on `LlamaChatSession`'s `prompt` function
10
- * or the `grammarEvaluationState` option on `LlamaContext`'s `evaluate` function instead
11
- * @hidden
12
- */
13
- grammar?: LlamaGrammar;
14
- /** If null, a random seed will be used */
15
- seed?: number | null;
16
- /** text context size */
17
- contextSize?: number;
18
- /** prompt processing batch size */
19
- batchSize?: number;
20
- /** the llama_eval() call computes all logits, not just the last one */
21
- logitsAll?: boolean;
22
- /** embedding mode only */
23
- embedding?: boolean;
24
- /** number of threads to use to evaluate tokens */
25
- threads?: number;
26
- };
27
- export type LlamaContextRepeatPenalty = {
28
- /** Tokens to lower the predication probability of to be the next predicted token */
29
- punishTokens: Uint32Array | (() => Uint32Array);
30
- /**
31
- * The relative amount to lower the probability of the tokens in `punishTokens` by
32
- * Defaults to `1.1`.
33
- * Set to `1` to disable.
34
- */
35
- penalty?: number;
36
- /**
37
- * For n time a token is in the `punishTokens` array, lower its probability by `n * frequencyPenalty`
38
- * Disabled by default (`0`).
39
- * Set to a value between `0` and `1` to enable.
40
- */
41
- frequencyPenalty?: number;
42
- /**
43
- * Lower the probability of all the tokens in the `punishTokens` array by `presencePenalty`
44
- * Disabled by default (`0`).
45
- * Set to a value between `0` and `1` to enable.
46
- */
47
- presencePenalty?: number;
48
- };
49
- export declare class LlamaContext {
50
- private readonly _model;
51
- private readonly _ctx;
52
- private readonly _prependBos;
53
- private _prependTokens;
54
- /**
55
- * @param {LlamaContextOptions} options
56
- */
57
- constructor({ model, prependBos, grammar, seed, contextSize, batchSize, logitsAll, embedding, threads }: LlamaContextOptions);
58
- encode(text: string): Uint32Array;
59
- decode(tokens: Uint32Array | Token[]): string;
60
- get prependBos(): boolean;
61
- /**
62
- * @returns {Token | null} The BOS (Beginning Of Sequence) token.
63
- */
64
- getBosToken(): Token | null;
65
- /**
66
- * @returns {Token | null} The EOS (End Of Sequence) token.
67
- */
68
- getEosToken(): Token | null;
69
- /**
70
- * @returns {Token | null} The NL (New Line) token.
71
- */
72
- getNlToken(): Token | null;
73
- /**
74
- * @returns {string | null} The BOS (Beginning Of Sequence) token as a string.
75
- */
76
- getBosString(): string | null;
77
- /**
78
- * @returns {string | null} The EOS (End Of Sequence) token as a string.
79
- */
80
- getEosString(): string | null;
81
- /**
82
- * @returns {string | null} The NL (New Line) token as a string.
83
- */
84
- getNlString(): string | null;
85
- getContextSize(): number;
86
- printTimings(): void;
87
- /**
88
- * @param {Uint32Array} tokens
89
- * @param {object} options
90
- * @returns {AsyncGenerator<Token, void>}
91
- */
92
- evaluate(tokens: Uint32Array, { temperature, topK, topP, grammarEvaluationState, repeatPenalty }?: {
93
- temperature?: number;
94
- topK?: number;
95
- topP?: number;
96
- grammarEvaluationState?: LlamaGrammarEvaluationState;
97
- repeatPenalty?: LlamaContextRepeatPenalty;
98
- }): AsyncGenerator<Token, void>;
99
- }