node-llama-cpp 3.0.0-beta.9 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (684) hide show
  1. package/README.md +42 -27
  2. package/bins/_linux-arm64.moved.txt +1 -0
  3. package/bins/_linux-armv7l.moved.txt +1 -0
  4. package/bins/_linux-x64-cuda.moved.txt +1 -0
  5. package/bins/_linux-x64-vulkan.moved.txt +1 -0
  6. package/bins/_linux-x64.moved.txt +1 -0
  7. package/bins/_mac-arm64-metal.moved.txt +1 -0
  8. package/bins/_mac-x64.moved.txt +1 -0
  9. package/bins/_win-arm64.moved.txt +1 -0
  10. package/bins/_win-x64-cuda.moved.txt +1 -0
  11. package/bins/_win-x64-vulkan.moved.txt +1 -0
  12. package/bins/_win-x64.moved.txt +1 -0
  13. package/dist/ChatWrapper.d.ts +19 -39
  14. package/dist/ChatWrapper.js +129 -72
  15. package/dist/ChatWrapper.js.map +1 -1
  16. package/dist/apiDocsIndex.d.ts +1 -0
  17. package/dist/apiDocsIndex.js +7 -0
  18. package/dist/apiDocsIndex.js.map +1 -0
  19. package/dist/bindings/AddonTypes.d.ts +88 -20
  20. package/dist/bindings/Llama.d.ts +43 -3
  21. package/dist/bindings/Llama.js +193 -23
  22. package/dist/bindings/Llama.js.map +1 -1
  23. package/dist/bindings/consts.d.ts +2 -0
  24. package/dist/bindings/consts.js +13 -0
  25. package/dist/bindings/consts.js.map +1 -0
  26. package/dist/bindings/getLlama.d.ts +123 -18
  27. package/dist/bindings/getLlama.js +264 -75
  28. package/dist/bindings/getLlama.js.map +1 -1
  29. package/dist/bindings/types.d.ts +29 -5
  30. package/dist/bindings/types.js +51 -2
  31. package/dist/bindings/types.js.map +1 -1
  32. package/dist/bindings/utils/MemoryOrchestrator.d.ts +21 -0
  33. package/dist/bindings/utils/MemoryOrchestrator.js +49 -0
  34. package/dist/bindings/utils/MemoryOrchestrator.js.map +1 -0
  35. package/dist/bindings/utils/asyncEvery.d.ts +5 -0
  36. package/dist/bindings/utils/asyncEvery.js +15 -0
  37. package/dist/bindings/utils/asyncEvery.js.map +1 -0
  38. package/dist/bindings/utils/asyncSome.d.ts +5 -0
  39. package/dist/bindings/utils/asyncSome.js +27 -0
  40. package/dist/bindings/utils/asyncSome.js.map +1 -0
  41. package/dist/bindings/utils/clearAllLocalBuilds.js.map +1 -1
  42. package/dist/bindings/utils/cloneLlamaCppRepo.d.ts +1 -1
  43. package/dist/bindings/utils/cloneLlamaCppRepo.js +39 -28
  44. package/dist/bindings/utils/cloneLlamaCppRepo.js.map +1 -1
  45. package/dist/bindings/utils/compileLLamaCpp.d.ts +11 -3
  46. package/dist/bindings/utils/compileLLamaCpp.js +250 -81
  47. package/dist/bindings/utils/compileLLamaCpp.js.map +1 -1
  48. package/dist/bindings/utils/detectAvailableComputeLayers.d.ts +14 -0
  49. package/dist/bindings/utils/detectAvailableComputeLayers.js +305 -0
  50. package/dist/bindings/utils/detectAvailableComputeLayers.js.map +1 -0
  51. package/dist/bindings/utils/detectGlibc.d.ts +4 -0
  52. package/dist/bindings/utils/detectGlibc.js +46 -0
  53. package/dist/bindings/utils/detectGlibc.js.map +1 -0
  54. package/dist/bindings/utils/getBestComputeLayersAvailable.d.ts +9 -0
  55. package/dist/bindings/utils/getBestComputeLayersAvailable.js +29 -0
  56. package/dist/bindings/utils/getBestComputeLayersAvailable.js.map +1 -0
  57. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js +14 -6
  58. package/dist/bindings/utils/getBuildFolderNameForBuildOptions.js.map +1 -1
  59. package/dist/bindings/utils/getExampleUsageCodeOfGetLlama.js.map +1 -1
  60. package/dist/bindings/utils/getGpuTypesToUseForOption.d.ts +12 -0
  61. package/dist/bindings/utils/getGpuTypesToUseForOption.js +39 -0
  62. package/dist/bindings/utils/getGpuTypesToUseForOption.js.map +1 -0
  63. package/dist/bindings/utils/getLinuxDistroInfo.d.ts +9 -0
  64. package/dist/bindings/utils/getLinuxDistroInfo.js +46 -0
  65. package/dist/bindings/utils/getLinuxDistroInfo.js.map +1 -0
  66. package/dist/bindings/utils/getLlamaWithoutBackend.d.ts +5 -0
  67. package/dist/bindings/utils/getLlamaWithoutBackend.js +27 -0
  68. package/dist/bindings/utils/getLlamaWithoutBackend.js.map +1 -0
  69. package/dist/bindings/utils/getPlatform.js.map +1 -1
  70. package/dist/bindings/utils/getPlatformInfo.d.ts +5 -0
  71. package/dist/bindings/utils/getPlatformInfo.js +28 -0
  72. package/dist/bindings/utils/getPlatformInfo.js.map +1 -0
  73. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.d.ts +3 -0
  74. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js +27 -0
  75. package/dist/bindings/utils/hasBuildingFromSourceDependenciesInstalled.js.map +1 -0
  76. package/dist/bindings/utils/hasFileInPath.d.ts +2 -0
  77. package/dist/bindings/utils/hasFileInPath.js +34 -0
  78. package/dist/bindings/utils/hasFileInPath.js.map +1 -0
  79. package/dist/bindings/utils/lastBuildInfo.js.map +1 -1
  80. package/dist/bindings/utils/logBinaryUsageExampleToConsole.d.ts +1 -1
  81. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js +3 -9
  82. package/dist/bindings/utils/logBinaryUsageExampleToConsole.js.map +1 -1
  83. package/dist/bindings/utils/logDistroInstallInstruction.d.ts +14 -0
  84. package/dist/bindings/utils/logDistroInstallInstruction.js +48 -0
  85. package/dist/bindings/utils/logDistroInstallInstruction.js.map +1 -0
  86. package/dist/bindings/utils/resolveCustomCmakeOptions.js +26 -26
  87. package/dist/bindings/utils/resolveCustomCmakeOptions.js.map +1 -1
  88. package/dist/bindings/utils/testBindingBinary.d.ts +1 -0
  89. package/dist/bindings/utils/testBindingBinary.js +100 -0
  90. package/dist/bindings/utils/testBindingBinary.js.map +1 -0
  91. package/dist/bindings/utils/testCmakeBinary.d.ts +5 -0
  92. package/dist/bindings/utils/testCmakeBinary.js +32 -0
  93. package/dist/bindings/utils/testCmakeBinary.js.map +1 -0
  94. package/dist/chatWrappers/AlpacaChatWrapper.d.ts +2 -1
  95. package/dist/chatWrappers/AlpacaChatWrapper.js +10 -2
  96. package/dist/chatWrappers/AlpacaChatWrapper.js.map +1 -1
  97. package/dist/chatWrappers/ChatMLChatWrapper.d.ts +2 -14
  98. package/dist/chatWrappers/ChatMLChatWrapper.js +23 -21
  99. package/dist/chatWrappers/ChatMLChatWrapper.js.map +1 -1
  100. package/dist/chatWrappers/FalconChatWrapper.d.ts +4 -10
  101. package/dist/chatWrappers/FalconChatWrapper.js +39 -21
  102. package/dist/chatWrappers/FalconChatWrapper.js.map +1 -1
  103. package/dist/chatWrappers/FunctionaryChatWrapper.d.ts +8 -32
  104. package/dist/chatWrappers/FunctionaryChatWrapper.js +514 -118
  105. package/dist/chatWrappers/FunctionaryChatWrapper.js.map +1 -1
  106. package/dist/chatWrappers/GemmaChatWrapper.d.ts +7 -0
  107. package/dist/chatWrappers/GemmaChatWrapper.js +96 -0
  108. package/dist/chatWrappers/GemmaChatWrapper.js.map +1 -0
  109. package/dist/chatWrappers/GeneralChatWrapper.d.ts +4 -10
  110. package/dist/chatWrappers/GeneralChatWrapper.js +46 -22
  111. package/dist/chatWrappers/GeneralChatWrapper.js.map +1 -1
  112. package/dist/chatWrappers/Llama2ChatWrapper.d.ts +12 -0
  113. package/dist/chatWrappers/{LlamaChatWrapper.js → Llama2ChatWrapper.js} +37 -20
  114. package/dist/chatWrappers/Llama2ChatWrapper.js.map +1 -0
  115. package/dist/chatWrappers/Llama3ChatWrapper.d.ts +16 -0
  116. package/dist/chatWrappers/Llama3ChatWrapper.js +173 -0
  117. package/dist/chatWrappers/Llama3ChatWrapper.js.map +1 -0
  118. package/dist/chatWrappers/Llama3_1ChatWrapper.d.ts +35 -0
  119. package/dist/chatWrappers/Llama3_1ChatWrapper.js +277 -0
  120. package/dist/chatWrappers/Llama3_1ChatWrapper.js.map +1 -0
  121. package/dist/chatWrappers/MistralChatWrapper.d.ts +15 -0
  122. package/dist/chatWrappers/MistralChatWrapper.js +169 -0
  123. package/dist/chatWrappers/MistralChatWrapper.js.map +1 -0
  124. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.d.ts +100 -0
  125. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js +409 -0
  126. package/dist/chatWrappers/generic/JinjaTemplateChatWrapper.js.map +1 -0
  127. package/dist/chatWrappers/generic/TemplateChatWrapper.d.ts +60 -0
  128. package/dist/chatWrappers/generic/TemplateChatWrapper.js +204 -0
  129. package/dist/chatWrappers/generic/TemplateChatWrapper.js.map +1 -0
  130. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.d.ts +23 -0
  131. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js +45 -0
  132. package/dist/chatWrappers/generic/utils/chatHistoryFunctionCallMessageTemplate.js.map +1 -0
  133. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.d.ts +57 -0
  134. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js +119 -0
  135. package/dist/chatWrappers/utils/ChatModelFunctionsDocumentationGenerator.js.map +1 -0
  136. package/dist/chatWrappers/utils/chunkChatItems.d.ts +10 -0
  137. package/dist/chatWrappers/utils/chunkChatItems.js +44 -0
  138. package/dist/chatWrappers/utils/chunkChatItems.js.map +1 -0
  139. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.d.ts +4 -0
  140. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js +221 -0
  141. package/dist/chatWrappers/utils/isJinjaTemplateEquivalentToSpecializedChatWrapper.js.map +1 -0
  142. package/dist/chatWrappers/utils/jsonDumps.d.ts +7 -0
  143. package/dist/chatWrappers/utils/jsonDumps.js +18 -0
  144. package/dist/chatWrappers/utils/jsonDumps.js.map +1 -0
  145. package/dist/chatWrappers/utils/resolveChatWrapper.d.ts +95 -0
  146. package/dist/chatWrappers/utils/resolveChatWrapper.js +335 -0
  147. package/dist/chatWrappers/utils/resolveChatWrapper.js.map +1 -0
  148. package/dist/cli/cli.js +19 -11
  149. package/dist/cli/cli.js.map +1 -1
  150. package/dist/cli/commands/ChatCommand.d.ts +16 -7
  151. package/dist/cli/commands/ChatCommand.js +321 -190
  152. package/dist/cli/commands/ChatCommand.js.map +1 -1
  153. package/dist/cli/commands/CompleteCommand.d.ts +31 -0
  154. package/dist/cli/commands/CompleteCommand.js +402 -0
  155. package/dist/cli/commands/CompleteCommand.js.map +1 -0
  156. package/dist/cli/commands/DebugCommand.d.ts +7 -0
  157. package/dist/cli/commands/DebugCommand.js +54 -0
  158. package/dist/cli/commands/DebugCommand.js.map +1 -0
  159. package/dist/cli/commands/InfillCommand.d.ts +33 -0
  160. package/dist/cli/commands/InfillCommand.js +438 -0
  161. package/dist/cli/commands/InfillCommand.js.map +1 -0
  162. package/dist/cli/commands/InitCommand.d.ts +11 -0
  163. package/dist/cli/commands/InitCommand.js +195 -0
  164. package/dist/cli/commands/InitCommand.js.map +1 -0
  165. package/dist/cli/commands/OnPostInstallCommand.js +6 -2
  166. package/dist/cli/commands/OnPostInstallCommand.js.map +1 -1
  167. package/dist/cli/commands/PullCommand.d.ts +13 -0
  168. package/dist/cli/commands/PullCommand.js +158 -0
  169. package/dist/cli/commands/PullCommand.js.map +1 -0
  170. package/dist/cli/commands/inspect/InspectCommand.d.ts +4 -0
  171. package/dist/cli/commands/inspect/InspectCommand.js +21 -0
  172. package/dist/cli/commands/inspect/InspectCommand.js.map +1 -0
  173. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.d.ts +12 -0
  174. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js +225 -0
  175. package/dist/cli/commands/inspect/commands/InspectEstimateCommand.js.map +1 -0
  176. package/dist/cli/commands/inspect/commands/InspectGgufCommand.d.ts +12 -0
  177. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js +149 -0
  178. package/dist/cli/commands/inspect/commands/InspectGgufCommand.js.map +1 -0
  179. package/dist/cli/commands/inspect/commands/InspectGpuCommand.d.ts +4 -0
  180. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js +202 -0
  181. package/dist/cli/commands/inspect/commands/InspectGpuCommand.js.map +1 -0
  182. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.d.ts +18 -0
  183. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js +629 -0
  184. package/dist/cli/commands/inspect/commands/InspectMeasureCommand.js.map +1 -0
  185. package/dist/cli/commands/source/SourceCommand.d.ts +4 -0
  186. package/dist/cli/commands/source/SourceCommand.js +19 -0
  187. package/dist/cli/commands/source/SourceCommand.js.map +1 -0
  188. package/dist/cli/commands/source/commands/BuildCommand.d.ts +16 -0
  189. package/dist/cli/commands/source/commands/BuildCommand.js +148 -0
  190. package/dist/cli/commands/source/commands/BuildCommand.js.map +1 -0
  191. package/dist/cli/commands/{ClearCommand.d.ts → source/commands/ClearCommand.d.ts} +1 -1
  192. package/dist/cli/commands/{ClearCommand.js → source/commands/ClearCommand.js} +11 -10
  193. package/dist/cli/commands/source/commands/ClearCommand.js.map +1 -0
  194. package/dist/cli/commands/{DownloadCommand.d.ts → source/commands/DownloadCommand.d.ts} +5 -4
  195. package/dist/cli/commands/source/commands/DownloadCommand.js +217 -0
  196. package/dist/cli/commands/source/commands/DownloadCommand.js.map +1 -0
  197. package/dist/cli/projectTemplates.d.ts +7 -0
  198. package/dist/cli/projectTemplates.js +10 -0
  199. package/dist/cli/projectTemplates.js.map +1 -0
  200. package/dist/cli/recommendedModels.d.ts +2 -0
  201. package/dist/cli/recommendedModels.js +585 -0
  202. package/dist/cli/recommendedModels.js.map +1 -0
  203. package/dist/cli/startCreateCli.d.ts +2 -0
  204. package/dist/cli/startCreateCli.js +26 -0
  205. package/dist/cli/startCreateCli.js.map +1 -0
  206. package/dist/cli/utils/ConsoleInteraction.d.ts +22 -0
  207. package/dist/cli/utils/ConsoleInteraction.js +122 -0
  208. package/dist/cli/utils/ConsoleInteraction.js.map +1 -0
  209. package/dist/cli/utils/ConsoleTable.d.ts +23 -0
  210. package/dist/cli/utils/ConsoleTable.js +86 -0
  211. package/dist/cli/utils/ConsoleTable.js.map +1 -0
  212. package/dist/cli/utils/basicChooseFromListConsoleInteraction.d.ts +13 -0
  213. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js +111 -0
  214. package/dist/cli/utils/basicChooseFromListConsoleInteraction.js.map +1 -0
  215. package/dist/cli/utils/consolePromptQuestion.d.ts +6 -0
  216. package/dist/cli/utils/consolePromptQuestion.js +82 -0
  217. package/dist/cli/utils/consolePromptQuestion.js.map +1 -0
  218. package/dist/cli/utils/getReadablePath.d.ts +1 -0
  219. package/dist/cli/utils/getReadablePath.js +14 -0
  220. package/dist/cli/utils/getReadablePath.js.map +1 -0
  221. package/dist/cli/utils/interactivelyAskForModel.d.ts +8 -0
  222. package/dist/cli/utils/interactivelyAskForModel.js +450 -0
  223. package/dist/cli/utils/interactivelyAskForModel.js.map +1 -0
  224. package/dist/cli/utils/logUsedGpuTypeOption.d.ts +2 -0
  225. package/dist/cli/utils/logUsedGpuTypeOption.js +9 -0
  226. package/dist/cli/utils/logUsedGpuTypeOption.js.map +1 -0
  227. package/dist/cli/utils/printCommonInfoLines.d.ts +9 -0
  228. package/dist/cli/utils/printCommonInfoLines.js +82 -0
  229. package/dist/cli/utils/printCommonInfoLines.js.map +1 -0
  230. package/dist/cli/utils/printInfoLine.d.ts +12 -0
  231. package/dist/cli/utils/printInfoLine.js +54 -0
  232. package/dist/cli/utils/printInfoLine.js.map +1 -0
  233. package/dist/cli/utils/projectTemplates.d.ts +19 -0
  234. package/dist/cli/utils/projectTemplates.js +47 -0
  235. package/dist/cli/utils/projectTemplates.js.map +1 -0
  236. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.d.ts +6 -0
  237. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js +14 -0
  238. package/dist/cli/utils/renderModelCompatibilityPercentageWithColors.js.map +1 -0
  239. package/dist/cli/utils/resolveCommandGgufPath.d.ts +5 -0
  240. package/dist/cli/utils/resolveCommandGgufPath.js +72 -0
  241. package/dist/cli/utils/resolveCommandGgufPath.js.map +1 -0
  242. package/dist/cli/utils/resolveHeaderFlag.d.ts +1 -0
  243. package/dist/cli/utils/resolveHeaderFlag.js +21 -0
  244. package/dist/cli/utils/resolveHeaderFlag.js.map +1 -0
  245. package/dist/cli/utils/resolveModelRecommendationFileOptions.d.ts +19 -0
  246. package/dist/cli/utils/resolveModelRecommendationFileOptions.js +7 -0
  247. package/dist/cli/utils/resolveModelRecommendationFileOptions.js.map +1 -0
  248. package/dist/cli/utils/splitAnsiToLines.d.ts +1 -0
  249. package/dist/cli/utils/splitAnsiToLines.js +32 -0
  250. package/dist/cli/utils/splitAnsiToLines.js.map +1 -0
  251. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.d.ts +2 -0
  252. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js +23 -0
  253. package/dist/cli/utils/withCliCommandDescriptionDocsUrl.js.map +1 -0
  254. package/dist/commands.d.ts +4 -3
  255. package/dist/commands.js +6 -3
  256. package/dist/commands.js.map +1 -1
  257. package/dist/config.d.ts +35 -4
  258. package/dist/config.js +58 -17
  259. package/dist/config.js.map +1 -1
  260. package/dist/consts.d.ts +4 -0
  261. package/dist/consts.js +11 -0
  262. package/dist/consts.js.map +1 -0
  263. package/dist/evaluator/LlamaChat/LlamaChat.d.ts +151 -41
  264. package/dist/evaluator/LlamaChat/LlamaChat.js +1289 -437
  265. package/dist/evaluator/LlamaChat/LlamaChat.js.map +1 -1
  266. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.d.ts +11 -0
  267. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js +55 -0
  268. package/dist/evaluator/LlamaChat/utils/FunctionCallNameGrammar.js.map +1 -0
  269. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.d.ts +16 -0
  270. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js +45 -0
  271. package/dist/evaluator/LlamaChat/utils/FunctionCallParamsGrammar.js.map +1 -0
  272. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.d.ts +8 -0
  273. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js +12 -0
  274. package/dist/evaluator/LlamaChat/utils/LlamaFunctionCallValidationError.js.map +1 -0
  275. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js +27 -17
  276. package/dist/evaluator/LlamaChat/utils/contextShiftStrategies/eraseFirstResponseAndKeepFirstSystemChatContextShiftStrategy.js.map +1 -1
  277. package/dist/evaluator/LlamaChatSession/LlamaChatSession.d.ts +187 -13
  278. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js +280 -53
  279. package/dist/evaluator/LlamaChatSession/LlamaChatSession.js.map +1 -1
  280. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.d.ts +40 -0
  281. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js +186 -0
  282. package/dist/evaluator/LlamaChatSession/utils/LlamaChatSessionPromptCompletionEngine.js.map +1 -0
  283. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.d.ts +10 -2
  284. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js +8 -0
  285. package/dist/evaluator/LlamaChatSession/utils/defineChatSessionFunction.js.map +1 -1
  286. package/dist/evaluator/LlamaCompletion.d.ts +168 -0
  287. package/dist/evaluator/LlamaCompletion.js +470 -0
  288. package/dist/evaluator/LlamaCompletion.js.map +1 -0
  289. package/dist/evaluator/LlamaContext/LlamaContext.d.ts +62 -21
  290. package/dist/evaluator/LlamaContext/LlamaContext.js +501 -120
  291. package/dist/evaluator/LlamaContext/LlamaContext.js.map +1 -1
  292. package/dist/evaluator/LlamaContext/LlamaSampler.d.ts +1 -0
  293. package/dist/evaluator/LlamaContext/LlamaSampler.js +31 -0
  294. package/dist/evaluator/LlamaContext/LlamaSampler.js.map +1 -0
  295. package/dist/evaluator/LlamaContext/types.d.ts +177 -16
  296. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/firstInFirstOutStrategy.js.map +1 -0
  297. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizationStrategies/maximumParallelismStrategy.js.map +1 -0
  298. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.d.ts +2 -0
  299. package/dist/evaluator/LlamaContext/utils/{resolveBatchItemsPrioritizingStrategy.js → resolveBatchItemsPrioritizationStrategy.js} +5 -5
  300. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizationStrategy.js.map +1 -0
  301. package/dist/evaluator/LlamaEmbedding.d.ts +21 -0
  302. package/dist/evaluator/LlamaEmbedding.js +53 -0
  303. package/dist/evaluator/LlamaEmbedding.js.map +1 -0
  304. package/dist/evaluator/LlamaEmbeddingContext.d.ts +29 -19
  305. package/dist/evaluator/LlamaEmbeddingContext.js +36 -43
  306. package/dist/evaluator/LlamaEmbeddingContext.js.map +1 -1
  307. package/dist/evaluator/LlamaGrammar.d.ts +16 -13
  308. package/dist/evaluator/LlamaGrammar.js +17 -10
  309. package/dist/evaluator/LlamaGrammar.js.map +1 -1
  310. package/dist/evaluator/LlamaGrammarEvaluationState.d.ts +7 -3
  311. package/dist/evaluator/LlamaGrammarEvaluationState.js +8 -4
  312. package/dist/evaluator/LlamaGrammarEvaluationState.js.map +1 -1
  313. package/dist/evaluator/LlamaJsonSchemaGrammar.d.ts +3 -0
  314. package/dist/evaluator/LlamaJsonSchemaGrammar.js +5 -3
  315. package/dist/evaluator/LlamaJsonSchemaGrammar.js.map +1 -1
  316. package/dist/evaluator/LlamaModel/LlamaModel.d.ts +255 -0
  317. package/dist/evaluator/LlamaModel/LlamaModel.js +780 -0
  318. package/dist/evaluator/LlamaModel/LlamaModel.js.map +1 -0
  319. package/dist/evaluator/LlamaModel/utils/TokenAttributes.d.ts +29 -0
  320. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js +65 -0
  321. package/dist/evaluator/LlamaModel/utils/TokenAttributes.js.map +1 -0
  322. package/dist/evaluator/TokenBias.d.ts +34 -0
  323. package/dist/evaluator/TokenBias.js +65 -0
  324. package/dist/evaluator/TokenBias.js.map +1 -0
  325. package/dist/evaluator/TokenMeter.d.ts +45 -0
  326. package/dist/evaluator/TokenMeter.js +74 -0
  327. package/dist/evaluator/TokenMeter.js.map +1 -0
  328. package/dist/gguf/consts.d.ts +4 -0
  329. package/dist/gguf/consts.js +12 -0
  330. package/dist/gguf/consts.js.map +1 -0
  331. package/dist/gguf/errors/InvalidGgufMagicError.d.ts +3 -0
  332. package/dist/gguf/errors/InvalidGgufMagicError.js +6 -0
  333. package/dist/gguf/errors/InvalidGgufMagicError.js.map +1 -0
  334. package/dist/gguf/errors/UnsupportedGgufValueTypeError.d.ts +4 -0
  335. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js +9 -0
  336. package/dist/gguf/errors/UnsupportedGgufValueTypeError.js.map +1 -0
  337. package/dist/gguf/fileReaders/GgufFileReader.d.ts +36 -0
  338. package/dist/gguf/fileReaders/GgufFileReader.js +109 -0
  339. package/dist/gguf/fileReaders/GgufFileReader.js.map +1 -0
  340. package/dist/gguf/fileReaders/GgufFsFileReader.d.ts +16 -0
  341. package/dist/gguf/fileReaders/GgufFsFileReader.js +62 -0
  342. package/dist/gguf/fileReaders/GgufFsFileReader.js.map +1 -0
  343. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.d.ts +25 -0
  344. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js +92 -0
  345. package/dist/gguf/fileReaders/GgufNetworkFetchFileReader.js.map +1 -0
  346. package/dist/gguf/insights/GgufInsights.d.ts +50 -0
  347. package/dist/gguf/insights/GgufInsights.js +401 -0
  348. package/dist/gguf/insights/GgufInsights.js.map +1 -0
  349. package/dist/gguf/insights/GgufInsightsConfigurationResolver.d.ts +146 -0
  350. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js +226 -0
  351. package/dist/gguf/insights/GgufInsightsConfigurationResolver.js.map +1 -0
  352. package/dist/gguf/insights/utils/resolveContextContextSizeOption.d.ts +19 -0
  353. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js +78 -0
  354. package/dist/gguf/insights/utils/resolveContextContextSizeOption.js.map +1 -0
  355. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.d.ts +15 -0
  356. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js +183 -0
  357. package/dist/gguf/insights/utils/resolveModelGpuLayersOption.js.map +1 -0
  358. package/dist/gguf/insights/utils/scoreLevels.d.ts +5 -0
  359. package/dist/gguf/insights/utils/scoreLevels.js +16 -0
  360. package/dist/gguf/insights/utils/scoreLevels.js.map +1 -0
  361. package/dist/gguf/parser/GgufV2Parser.d.ts +20 -0
  362. package/dist/gguf/parser/GgufV2Parser.js +156 -0
  363. package/dist/gguf/parser/GgufV2Parser.js.map +1 -0
  364. package/dist/gguf/parser/GgufV3Parser.d.ts +3 -0
  365. package/dist/gguf/parser/GgufV3Parser.js +4 -0
  366. package/dist/gguf/parser/GgufV3Parser.js.map +1 -0
  367. package/dist/gguf/parser/parseGguf.d.ts +8 -0
  368. package/dist/gguf/parser/parseGguf.js +61 -0
  369. package/dist/gguf/parser/parseGguf.js.map +1 -0
  370. package/dist/gguf/readGgufFileInfo.d.ts +45 -0
  371. package/dist/gguf/readGgufFileInfo.js +71 -0
  372. package/dist/gguf/readGgufFileInfo.js.map +1 -0
  373. package/dist/gguf/types/GgufFileInfoTypes.d.ts +84 -0
  374. package/dist/gguf/types/GgufFileInfoTypes.js +18 -0
  375. package/dist/gguf/types/GgufFileInfoTypes.js.map +1 -0
  376. package/dist/gguf/types/GgufMetadataTypes.d.ts +372 -0
  377. package/dist/gguf/types/GgufMetadataTypes.js +114 -0
  378. package/dist/gguf/types/GgufMetadataTypes.js.map +1 -0
  379. package/dist/gguf/types/GgufTensorInfoTypes.d.ts +37 -0
  380. package/dist/gguf/types/GgufTensorInfoTypes.js +33 -0
  381. package/dist/gguf/types/GgufTensorInfoTypes.js.map +1 -0
  382. package/dist/gguf/utils/GgufReadOffset.d.ts +6 -0
  383. package/dist/gguf/utils/GgufReadOffset.js +18 -0
  384. package/dist/gguf/utils/GgufReadOffset.js.map +1 -0
  385. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.d.ts +6 -0
  386. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js +76 -0
  387. package/dist/gguf/utils/convertMetadataKeyValueRecordToNestedObject.js.map +1 -0
  388. package/dist/gguf/utils/getGgufFileTypeName.d.ts +4 -0
  389. package/dist/gguf/utils/getGgufFileTypeName.js +13 -0
  390. package/dist/gguf/utils/getGgufFileTypeName.js.map +1 -0
  391. package/dist/gguf/utils/getGgufMetadataArchitectureData.d.ts +3 -0
  392. package/dist/gguf/utils/getGgufMetadataArchitectureData.js +4 -0
  393. package/dist/gguf/utils/getGgufMetadataArchitectureData.js.map +1 -0
  394. package/dist/gguf/utils/normalizeGgufDownloadUrl.d.ts +1 -0
  395. package/dist/gguf/utils/normalizeGgufDownloadUrl.js +16 -0
  396. package/dist/gguf/utils/normalizeGgufDownloadUrl.js.map +1 -0
  397. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.d.ts +2 -0
  398. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js +39 -0
  399. package/dist/gguf/utils/resolveBinarySplitGgufPartUrls.js.map +1 -0
  400. package/dist/gguf/utils/resolveSplitGgufParts.d.ts +7 -0
  401. package/dist/gguf/utils/resolveSplitGgufParts.js +55 -0
  402. package/dist/gguf/utils/resolveSplitGgufParts.js.map +1 -0
  403. package/dist/index.d.ts +39 -14
  404. package/dist/index.js +29 -8
  405. package/dist/index.js.map +1 -1
  406. package/dist/state.d.ts +2 -0
  407. package/dist/state.js +7 -0
  408. package/dist/state.js.map +1 -1
  409. package/dist/tsconfig.tsbuildinfo +1 -0
  410. package/dist/types.d.ts +131 -5
  411. package/dist/types.js.map +1 -1
  412. package/dist/utils/DisposeGuard.d.ts +13 -0
  413. package/dist/utils/DisposeGuard.js +120 -0
  414. package/dist/utils/DisposeGuard.js.map +1 -0
  415. package/dist/utils/InsufficientMemoryError.d.ts +3 -0
  416. package/dist/utils/InsufficientMemoryError.js +6 -0
  417. package/dist/utils/InsufficientMemoryError.js.map +1 -0
  418. package/dist/utils/LlamaText.d.ts +73 -26
  419. package/dist/utils/LlamaText.js +475 -157
  420. package/dist/utils/LlamaText.js.map +1 -1
  421. package/dist/utils/LruCache.d.ts +12 -0
  422. package/dist/utils/LruCache.js +44 -0
  423. package/dist/utils/LruCache.js.map +1 -0
  424. package/dist/utils/OverridesObject.d.ts +7 -0
  425. package/dist/utils/OverridesObject.js +2 -0
  426. package/dist/utils/OverridesObject.js.map +1 -0
  427. package/dist/utils/ReplHistory.js +5 -1
  428. package/dist/utils/ReplHistory.js.map +1 -1
  429. package/dist/utils/StopGenerationDetector.d.ts +27 -8
  430. package/dist/utils/StopGenerationDetector.js +108 -22
  431. package/dist/utils/StopGenerationDetector.js.map +1 -1
  432. package/dist/utils/ThreadsSplitter.d.ts +32 -0
  433. package/dist/utils/ThreadsSplitter.js +177 -0
  434. package/dist/utils/ThreadsSplitter.js.map +1 -0
  435. package/dist/utils/TokenStreamRegulator.d.ts +10 -4
  436. package/dist/utils/TokenStreamRegulator.js +102 -10
  437. package/dist/utils/TokenStreamRegulator.js.map +1 -1
  438. package/dist/utils/UnsupportedError.d.ts +2 -0
  439. package/dist/utils/UnsupportedError.js +7 -0
  440. package/dist/utils/UnsupportedError.js.map +1 -0
  441. package/dist/utils/appendUserMessageToChatHistory.d.ts +4 -0
  442. package/dist/utils/appendUserMessageToChatHistory.js +4 -0
  443. package/dist/utils/appendUserMessageToChatHistory.js.map +1 -1
  444. package/dist/utils/clearTempFolder.js.map +1 -1
  445. package/dist/utils/cmake.js +23 -10
  446. package/dist/utils/cmake.js.map +1 -1
  447. package/dist/utils/compareTokens.d.ts +1 -1
  448. package/dist/utils/compareTokens.js.map +1 -1
  449. package/dist/utils/createModelDownloader.d.ts +199 -0
  450. package/dist/utils/createModelDownloader.js +405 -0
  451. package/dist/utils/createModelDownloader.js.map +1 -0
  452. package/dist/utils/findBestOption.d.ts +4 -0
  453. package/dist/utils/findBestOption.js +15 -0
  454. package/dist/utils/findBestOption.js.map +1 -0
  455. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.d.ts +1 -0
  456. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js +23 -12
  457. package/dist/utils/findCharacterRemovalCountToFitChatHistoryInContext.js.map +1 -1
  458. package/dist/utils/gbnfJson/GbnfGrammarGenerator.js.map +1 -1
  459. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.d.ts +5 -0
  460. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js +11 -0
  461. package/dist/utils/gbnfJson/getGbnfGrammarForGbnfJsonSchema.js.map +1 -0
  462. package/dist/utils/gbnfJson/terminals/GbnfArray.d.ts +3 -1
  463. package/dist/utils/gbnfJson/terminals/GbnfArray.js +10 -5
  464. package/dist/utils/gbnfJson/terminals/GbnfArray.js.map +1 -1
  465. package/dist/utils/gbnfJson/terminals/GbnfBoolean.d.ts +1 -1
  466. package/dist/utils/gbnfJson/terminals/GbnfBoolean.js.map +1 -1
  467. package/dist/utils/gbnfJson/terminals/GbnfBooleanValue.js.map +1 -1
  468. package/dist/utils/gbnfJson/terminals/GbnfGrammar.js.map +1 -1
  469. package/dist/utils/gbnfJson/terminals/GbnfNull.d.ts +1 -1
  470. package/dist/utils/gbnfJson/terminals/GbnfNull.js.map +1 -1
  471. package/dist/utils/gbnfJson/terminals/GbnfNumber.d.ts +1 -1
  472. package/dist/utils/gbnfJson/terminals/GbnfNumber.js.map +1 -1
  473. package/dist/utils/gbnfJson/terminals/GbnfNumberValue.js.map +1 -1
  474. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.d.ts +3 -1
  475. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js +9 -4
  476. package/dist/utils/gbnfJson/terminals/GbnfObjectMap.js.map +1 -1
  477. package/dist/utils/gbnfJson/terminals/GbnfOr.js.map +1 -1
  478. package/dist/utils/gbnfJson/terminals/GbnfRepetition.d.ts +9 -0
  479. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js +37 -0
  480. package/dist/utils/gbnfJson/terminals/GbnfRepetition.js.map +1 -0
  481. package/dist/utils/gbnfJson/terminals/GbnfString.d.ts +1 -1
  482. package/dist/utils/gbnfJson/terminals/GbnfString.js +23 -5
  483. package/dist/utils/gbnfJson/terminals/GbnfString.js.map +1 -1
  484. package/dist/utils/gbnfJson/terminals/GbnfStringValue.js.map +1 -1
  485. package/dist/utils/gbnfJson/terminals/GbnfVerbatimText.js.map +1 -1
  486. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.d.ts +7 -4
  487. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js +37 -9
  488. package/dist/utils/gbnfJson/terminals/GbnfWhitespace.js.map +1 -1
  489. package/dist/utils/gbnfJson/terminals/gbnfConsts.d.ts +5 -4
  490. package/dist/utils/gbnfJson/terminals/gbnfConsts.js +14 -3
  491. package/dist/utils/gbnfJson/terminals/gbnfConsts.js.map +1 -1
  492. package/dist/utils/gbnfJson/types.d.ts +3 -0
  493. package/dist/utils/gbnfJson/types.js.map +1 -1
  494. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.d.ts +10 -0
  495. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js +15 -0
  496. package/dist/utils/gbnfJson/utils/GbnfJsonScopeState.js.map +1 -0
  497. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.d.ts +2 -1
  498. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js +6 -5
  499. package/dist/utils/gbnfJson/utils/getGbnfJsonTerminalForGbnfJsonSchema.js.map +1 -1
  500. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js +3 -3
  501. package/dist/utils/gbnfJson/utils/validateObjectAgainstGbnfSchema.js.map +1 -1
  502. package/dist/utils/getBuildDefaults.d.ts +1 -2
  503. package/dist/utils/getBuildDefaults.js +2 -3
  504. package/dist/utils/getBuildDefaults.js.map +1 -1
  505. package/dist/utils/getConsoleLogPrefix.d.ts +1 -1
  506. package/dist/utils/getConsoleLogPrefix.js +5 -4
  507. package/dist/utils/getConsoleLogPrefix.js.map +1 -1
  508. package/dist/utils/getGrammarsFolder.js +1 -1
  509. package/dist/utils/getGrammarsFolder.js.map +1 -1
  510. package/dist/utils/getQueuedTokensBeforeStopTrigger.d.ts +6 -0
  511. package/dist/utils/getQueuedTokensBeforeStopTrigger.js +22 -0
  512. package/dist/utils/getQueuedTokensBeforeStopTrigger.js.map +1 -0
  513. package/dist/utils/getReadableContextSize.d.ts +1 -0
  514. package/dist/utils/getReadableContextSize.js +7 -0
  515. package/dist/utils/getReadableContextSize.js.map +1 -0
  516. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js +15 -11
  517. package/dist/utils/getTypeScriptTypeStringForGbnfJsonSchema.js.map +1 -1
  518. package/dist/utils/gitReleaseBundles.js +68 -1
  519. package/dist/utils/gitReleaseBundles.js.map +1 -1
  520. package/dist/utils/isToken.d.ts +2 -0
  521. package/dist/utils/isToken.js +4 -0
  522. package/dist/utils/isToken.js.map +1 -0
  523. package/dist/utils/isUrl.d.ts +1 -0
  524. package/dist/utils/isUrl.js +15 -0
  525. package/dist/utils/isUrl.js.map +1 -0
  526. package/dist/utils/mergeUnionTypes.d.ts +10 -0
  527. package/dist/utils/mergeUnionTypes.js +2 -0
  528. package/dist/utils/mergeUnionTypes.js.map +1 -0
  529. package/dist/utils/modelFileAccesTokens.d.ts +4 -0
  530. package/dist/utils/modelFileAccesTokens.js +40 -0
  531. package/dist/utils/modelFileAccesTokens.js.map +1 -0
  532. package/dist/utils/parseModelFileName.d.ts +1 -0
  533. package/dist/utils/parseModelFileName.js +6 -1
  534. package/dist/utils/parseModelFileName.js.map +1 -1
  535. package/dist/utils/parseTextTemplate.d.ts +66 -0
  536. package/dist/utils/parseTextTemplate.js +116 -0
  537. package/dist/utils/parseTextTemplate.js.map +1 -0
  538. package/dist/utils/prettyPrintObject.d.ts +10 -1
  539. package/dist/utils/prettyPrintObject.js +61 -15
  540. package/dist/utils/prettyPrintObject.js.map +1 -1
  541. package/dist/utils/pushAll.d.ts +6 -0
  542. package/dist/utils/pushAll.js +11 -0
  543. package/dist/utils/pushAll.js.map +1 -0
  544. package/dist/utils/removeNullFields.d.ts +2 -2
  545. package/dist/utils/removeNullFields.js.map +1 -1
  546. package/dist/utils/resolveGithubRelease.d.ts +2 -2
  547. package/dist/utils/resolveGithubRelease.js.map +1 -1
  548. package/dist/utils/resolveLastTokens.d.ts +2 -0
  549. package/dist/utils/resolveLastTokens.js +12 -0
  550. package/dist/utils/resolveLastTokens.js.map +1 -0
  551. package/dist/utils/runtime.d.ts +4 -0
  552. package/dist/utils/runtime.js +8 -0
  553. package/dist/utils/runtime.js.map +1 -0
  554. package/dist/utils/safeEventCallback.d.ts +6 -0
  555. package/dist/utils/safeEventCallback.js +29 -0
  556. package/dist/utils/safeEventCallback.js.map +1 -0
  557. package/dist/utils/spawnCommand.d.ts +11 -2
  558. package/dist/utils/spawnCommand.js +55 -7
  559. package/dist/utils/spawnCommand.js.map +1 -1
  560. package/dist/utils/tokenizeInput.d.ts +1 -1
  561. package/dist/utils/tokenizeInput.js +6 -3
  562. package/dist/utils/tokenizeInput.js.map +1 -1
  563. package/dist/utils/transformPromisable.d.ts +40 -0
  564. package/dist/utils/transformPromisable.js +64 -0
  565. package/dist/utils/transformPromisable.js.map +1 -0
  566. package/dist/utils/truncateTextAndRoundToWords.d.ts +2 -0
  567. package/dist/utils/truncateTextAndRoundToWords.js +32 -0
  568. package/dist/utils/truncateTextAndRoundToWords.js.map +1 -1
  569. package/dist/utils/utilTypes.d.ts +3 -0
  570. package/dist/utils/utilTypes.js +2 -0
  571. package/dist/utils/utilTypes.js.map +1 -0
  572. package/dist/utils/waitForLockfileRelease.js.map +1 -1
  573. package/dist/utils/withLockfile.js.map +1 -1
  574. package/dist/utils/withOra.d.ts +2 -0
  575. package/dist/utils/withOra.js +16 -6
  576. package/dist/utils/withOra.js.map +1 -1
  577. package/dist/utils/withProgressLog.d.ts +22 -0
  578. package/dist/utils/withProgressLog.js +211 -0
  579. package/dist/utils/withProgressLog.js.map +1 -0
  580. package/dist/utils/withStatusLogs.js +1 -1
  581. package/dist/utils/withStatusLogs.js.map +1 -1
  582. package/dist/utils/wrapAbortSignal.d.ts +1 -0
  583. package/dist/utils/wrapAbortSignal.js +9 -0
  584. package/dist/utils/wrapAbortSignal.js.map +1 -0
  585. package/llama/CMakeLists.txt +134 -5
  586. package/llama/addon/AddonContext.cpp +629 -0
  587. package/llama/addon/AddonContext.h +52 -0
  588. package/llama/addon/AddonGrammar.cpp +39 -0
  589. package/llama/addon/AddonGrammar.h +19 -0
  590. package/llama/addon/AddonGrammarEvaluationState.cpp +25 -0
  591. package/llama/addon/AddonGrammarEvaluationState.h +17 -0
  592. package/llama/addon/AddonModel.cpp +672 -0
  593. package/llama/addon/AddonModel.h +61 -0
  594. package/llama/addon/AddonModelData.cpp +25 -0
  595. package/llama/addon/AddonModelData.h +15 -0
  596. package/llama/addon/AddonModelLora.cpp +105 -0
  597. package/llama/addon/AddonModelLora.h +28 -0
  598. package/llama/addon/AddonSampler.cpp +513 -0
  599. package/llama/addon/AddonSampler.h +65 -0
  600. package/llama/addon/RingBuffer.h +109 -0
  601. package/llama/addon/addon.cpp +223 -0
  602. package/llama/addon/addonGlobals.cpp +22 -0
  603. package/llama/addon/addonGlobals.h +12 -0
  604. package/llama/addon/globals/addonLog.cpp +136 -0
  605. package/llama/addon/globals/addonLog.h +21 -0
  606. package/llama/addon/globals/addonProgress.cpp +15 -0
  607. package/llama/addon/globals/addonProgress.h +15 -0
  608. package/llama/addon/globals/getGpuInfo.cpp +108 -0
  609. package/llama/addon/globals/getGpuInfo.h +6 -0
  610. package/llama/binariesGithubRelease.json +1 -1
  611. package/llama/gitRelease.bundle +0 -0
  612. package/llama/gpuInfo/cuda-gpu-info.cu +120 -0
  613. package/llama/gpuInfo/cuda-gpu-info.h +10 -0
  614. package/llama/gpuInfo/metal-gpu-info.h +8 -0
  615. package/llama/gpuInfo/metal-gpu-info.mm +30 -0
  616. package/llama/gpuInfo/vulkan-gpu-info.cpp +83 -0
  617. package/llama/gpuInfo/vulkan-gpu-info.h +9 -0
  618. package/llama/grammars/README.md +297 -6
  619. package/llama/grammars/json.gbnf +4 -4
  620. package/llama/grammars/json_arr.gbnf +4 -4
  621. package/llama/llama.cpp.info.json +1 -1
  622. package/llama/toolchains/win32.host-x64.target-arm64.cmake +41 -0
  623. package/package.json +109 -59
  624. package/templates/packed/electron-typescript-react.json +1 -0
  625. package/templates/packed/node-typescript.json +1 -0
  626. package/dist/AbortError.d.ts +0 -2
  627. package/dist/AbortError.js +0 -7
  628. package/dist/AbortError.js.map +0 -1
  629. package/dist/chatWrappers/LlamaChatWrapper.d.ts +0 -13
  630. package/dist/chatWrappers/LlamaChatWrapper.js.map +0 -1
  631. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.d.ts +0 -13
  632. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js +0 -57
  633. package/dist/chatWrappers/resolveChatWrapperBasedOnModel.js.map +0 -1
  634. package/dist/cli/commands/BuildCommand.d.ts +0 -11
  635. package/dist/cli/commands/BuildCommand.js +0 -106
  636. package/dist/cli/commands/BuildCommand.js.map +0 -1
  637. package/dist/cli/commands/ClearCommand.js.map +0 -1
  638. package/dist/cli/commands/DownloadCommand.js +0 -169
  639. package/dist/cli/commands/DownloadCommand.js.map +0 -1
  640. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.d.ts +0 -22
  641. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js +0 -121
  642. package/dist/evaluator/LlamaChat/utils/FunctionCallGrammar.js.map +0 -1
  643. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/firstInFirstOutStrategy.js.map +0 -1
  644. package/dist/evaluator/LlamaContext/utils/batchItemsPrioritizingStrategies/maximumParallelismStrategy.js.map +0 -1
  645. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.d.ts +0 -2
  646. package/dist/evaluator/LlamaContext/utils/resolveBatchItemsPrioritizingStrategy.js.map +0 -1
  647. package/dist/evaluator/LlamaModel.d.ts +0 -120
  648. package/dist/evaluator/LlamaModel.js +0 -320
  649. package/dist/evaluator/LlamaModel.js.map +0 -1
  650. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.d.ts +0 -2
  651. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js +0 -9
  652. package/dist/utils/getGbnfGrammarForGbnfJsonSchema.js.map +0 -1
  653. package/dist/utils/parseModelTypeDescription.d.ts +0 -6
  654. package/dist/utils/parseModelTypeDescription.js +0 -9
  655. package/dist/utils/parseModelTypeDescription.js.map +0 -1
  656. package/dist/utils/resolveChatWrapper.d.ts +0 -4
  657. package/dist/utils/resolveChatWrapper.js +0 -16
  658. package/dist/utils/resolveChatWrapper.js.map +0 -1
  659. package/llama/addon.cpp +0 -950
  660. package/llamaBins/linux-arm64/.buildMetadata.json +0 -1
  661. package/llamaBins/linux-arm64/llama-addon.node +0 -0
  662. package/llamaBins/linux-armv7l/.buildMetadata.json +0 -1
  663. package/llamaBins/linux-armv7l/llama-addon.node +0 -0
  664. package/llamaBins/linux-x64/.buildMetadata.json +0 -1
  665. package/llamaBins/linux-x64/llama-addon.node +0 -0
  666. package/llamaBins/linux-x64-cuda/.buildMetadata.json +0 -1
  667. package/llamaBins/linux-x64-cuda/llama-addon.node +0 -0
  668. package/llamaBins/mac-arm64-metal/.buildMetadata.json +0 -1
  669. package/llamaBins/mac-arm64-metal/ggml-metal.metal +0 -6119
  670. package/llamaBins/mac-arm64-metal/llama-addon.node +0 -0
  671. package/llamaBins/mac-x64/.buildMetadata.json +0 -1
  672. package/llamaBins/mac-x64/llama-addon.node +0 -0
  673. package/llamaBins/win-x64/.buildMetadata.json +0 -1
  674. package/llamaBins/win-x64/llama-addon.exp +0 -0
  675. package/llamaBins/win-x64/llama-addon.lib +0 -0
  676. package/llamaBins/win-x64/llama-addon.node +0 -0
  677. package/llamaBins/win-x64-cuda/.buildMetadata.json +0 -1
  678. package/llamaBins/win-x64-cuda/llama-addon.exp +0 -0
  679. package/llamaBins/win-x64-cuda/llama-addon.lib +0 -0
  680. package/llamaBins/win-x64-cuda/llama-addon.node +0 -0
  681. /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.d.ts +0 -0
  682. /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/firstInFirstOutStrategy.js +0 -0
  683. /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.d.ts +0 -0
  684. /package/dist/evaluator/LlamaContext/utils/{batchItemsPrioritizingStrategies → batchItemsPrioritizationStrategies}/maximumParallelismStrategy.js +0 -0
@@ -0,0 +1,10 @@
1
+ #pragma once
2
+
3
+ #include <stddef.h>
4
+ #include <vector>
5
+ #include <string>
6
+
7
+ typedef void (*gpuInfoCudaErrorLogCallback_t)(const char* message);
8
+
9
+ bool gpuInfoGetTotalCudaDevicesInfo(size_t * total, size_t * used, gpuInfoCudaErrorLogCallback_t errorLogCallback);
10
+ void gpuInfoGetCudaDeviceNames(std::vector<std::string> * deviceNames, gpuInfoCudaErrorLogCallback_t errorLogCallback);
@@ -0,0 +1,8 @@
1
+ #pragma once
2
+
3
+ #include <stdint.h>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ void getMetalGpuInfo(uint64_t * total, uint64_t * used);
8
+ void getMetalGpuDeviceNames(std::vector<std::string> * deviceNames);
@@ -0,0 +1,30 @@
1
+ #include <stdint.h>
2
+ #include <vector>
3
+ #include <string>
4
+ #import <Metal/Metal.h>
5
+
6
+ void getMetalGpuInfo(uint64_t * total, uint64_t * used) {
7
+ id<MTLDevice> device = MTLCreateSystemDefaultDevice();
8
+
9
+ if (device) {
10
+ *total = device.recommendedMaxWorkingSetSize;
11
+ *used = device.currentAllocatedSize;
12
+ } else {
13
+ *total = 0;
14
+ *used = 0;
15
+ }
16
+
17
+ [device release];
18
+ device = nil;
19
+ }
20
+
21
+ void getMetalGpuDeviceNames(std::vector<std::string> * deviceNames) {
22
+ NSArray<id<MTLDevice>> *devices = MTLCopyAllDevices();
23
+
24
+ for (id<MTLDevice> device in devices) {
25
+ (*deviceNames).push_back(std::string(([NSString stringWithUTF8String:device.name.UTF8String]).UTF8String));
26
+ }
27
+
28
+ [devices release];
29
+ devices = nil;
30
+ }
@@ -0,0 +1,83 @@
1
+ #include <stddef.h>
2
+ #include <vector>
3
+
4
+ #include <vulkan/vulkan.hpp>
5
+
6
+ typedef void (*gpuInfoVulkanWarningLogCallback_t)(const char* message);
7
+
8
+ static bool enumerateVulkanDevices(size_t* total, size_t* used, bool addDeviceNames, std::vector<std::string> * deviceNames, gpuInfoVulkanWarningLogCallback_t warningLogCallback) {
9
+ vk::ApplicationInfo appInfo("node-llama-cpp GPU info", 1, "llama.cpp", 1, VK_API_VERSION_1_2);
10
+ vk::InstanceCreateInfo createInfo(vk::InstanceCreateFlags(), &appInfo, {}, {});
11
+ vk::Instance instance = vk::createInstance(createInfo);
12
+
13
+ auto physicalDevices = instance.enumeratePhysicalDevices();
14
+
15
+ size_t usedMem = 0;
16
+ size_t totalMem = 0;
17
+
18
+ for (size_t i = 0; i < physicalDevices.size(); i++) {
19
+ vk::PhysicalDevice physicalDevice = physicalDevices[i];
20
+ vk::PhysicalDeviceMemoryProperties memProps = physicalDevice.getMemoryProperties();
21
+ vk::PhysicalDeviceProperties deviceProps = physicalDevice.getProperties();
22
+
23
+ if (deviceProps.deviceType == vk::PhysicalDeviceType::eCpu) {
24
+ // ignore CPU devices, as we don't want to count RAM from the CPU as VRAM
25
+ continue;
26
+ }
27
+
28
+ std::vector<vk::ExtensionProperties> extensionProperties = physicalDevice.enumerateDeviceExtensionProperties();
29
+ bool memoryBudgetExtensionSupported =
30
+ std::any_of(
31
+ extensionProperties.begin(),
32
+ extensionProperties.end(),
33
+ [](const vk::ExtensionProperties& ext) { return std::string(ext.extensionName.data()) == VK_EXT_MEMORY_BUDGET_EXTENSION_NAME;}
34
+ );
35
+
36
+ if (memoryBudgetExtensionSupported) {
37
+ vk::PhysicalDeviceMemoryBudgetPropertiesEXT memoryBudgetProperties;
38
+ vk::PhysicalDeviceMemoryProperties2 memProps2 = {};
39
+ memProps2.pNext = &memoryBudgetProperties;
40
+
41
+ physicalDevice.getMemoryProperties2(&memProps2);
42
+
43
+ for (uint32_t i = 0; i < memProps.memoryHeapCount; ++i) {
44
+ if (memProps.memoryHeaps[i].flags & vk::MemoryHeapFlagBits::eDeviceLocal) {
45
+ const auto size = memProps.memoryHeaps[i].size;
46
+ totalMem += size;
47
+ usedMem += memoryBudgetProperties.heapUsage[i];
48
+
49
+ if (size > 0 && addDeviceNames) {
50
+ (*deviceNames).push_back(std::string(deviceProps.deviceName.data()));
51
+ }
52
+
53
+ break;
54
+ }
55
+ }
56
+ } else {
57
+ // VK_EXT_memory_budget extension is not supported, so we cannot determine used memory
58
+ warningLogCallback(
59
+ (
60
+ "Vulkan VK_EXT_memory_budget extension not supported for device \"" +
61
+ std::string(deviceProps.deviceName.data()) + "\", so VRAM info cannot be determained for it"
62
+ )
63
+ .c_str()
64
+ );
65
+ return false;
66
+ }
67
+ }
68
+
69
+ *total = totalMem;
70
+ *used = usedMem;
71
+ return true;
72
+ }
73
+
74
+ bool gpuInfoGetTotalVulkanDevicesInfo(size_t* total, size_t* used, gpuInfoVulkanWarningLogCallback_t warningLogCallback) {
75
+ return enumerateVulkanDevices(total, used, false, nullptr, warningLogCallback);
76
+ }
77
+
78
+ bool gpuInfoGetVulkanDeviceNames(std::vector<std::string> * deviceNames, gpuInfoVulkanWarningLogCallback_t warningLogCallback) {
79
+ size_t vulkanDeviceTotal = 0;
80
+ size_t vulkanDeviceUsed = 0;
81
+
82
+ return enumerateVulkanDevices(&vulkanDeviceTotal, &vulkanDeviceUsed, true, deviceNames, warningLogCallback);
83
+ }
@@ -0,0 +1,9 @@
1
+ #pragma once
2
+
3
+ #include <stddef.h>
4
+ #include <vector>
5
+
6
+ typedef void (*gpuInfoVulkanWarningLogCallback_t)(const char* message);
7
+
8
+ bool gpuInfoGetTotalVulkanDevicesInfo(size_t* total, size_t* used, gpuInfoVulkanWarningLogCallback_t warningLogCallback);
9
+ bool gpuInfoGetVulkanDeviceNames(std::vector<std::string> * deviceNames, gpuInfoVulkanWarningLogCallback_t warningLogCallback);
@@ -4,7 +4,7 @@ GBNF (GGML BNF) is a format for defining [formal grammars](https://en.wikipedia.
4
4
 
5
5
  ## Background
6
6
 
7
- [Bakus-Naur Form (BNF)](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) is a notation for describing the syntax of formal languages like programming languages, file formats, and protocols. GBNF is an extension of BNF that primarily adds a few modern regex-like features.
7
+ [Backus-Naur Form (BNF)](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) is a notation for describing the syntax of formal languages like programming languages, file formats, and protocols. GBNF is an extension of BNF that primarily adds a few modern regex-like features.
8
8
 
9
9
  ## Basics
10
10
 
@@ -51,7 +51,7 @@ single-line ::= [^\n]+ "\n"`
51
51
 
52
52
  ## Sequences and Alternatives
53
53
 
54
- The order of symbols in a sequence matter. For example, in `"1. " move " " move "\n"`, the `"1. "` must come before the first `move`, etc.
54
+ The order of symbols in a sequence matters. For example, in `"1. " move " " move "\n"`, the `"1. "` must come before the first `move`, etc.
55
55
 
56
56
  Alternatives, denoted by `|`, give different sequences that are acceptable. For example, in `move ::= pawn | nonpawn | castle`, `move` can be a `pawn` move, a `nonpawn` move, or a `castle`.
57
57
 
@@ -59,9 +59,13 @@ Parentheses `()` can be used to group sequences, which allows for embedding alte
59
59
 
60
60
  ## Repetition and Optional Symbols
61
61
 
62
- - `*` after a symbol or sequence means that it can be repeated zero or more times.
63
- - `+` denotes that the symbol or sequence should appear one or more times.
64
- - `?` makes the preceding symbol or sequence optional.
62
+ - `*` after a symbol or sequence means that it can be repeated zero or more times (equivalent to `{0,}`).
63
+ - `+` denotes that the symbol or sequence should appear one or more times (equivalent to `{1,}`).
64
+ - `?` makes the preceding symbol or sequence optional (equivalent to `{0,1}`).
65
+ - `{m}` repeats the precedent symbol or sequence exactly `m` times
66
+ - `{m,}` repeats the precedent symbol or sequence at least `m` times
67
+ - `{m,n}` repeats the precedent symbol or sequence at between `m` and `n` times (included)
68
+ - `{0,n}` repeats the precedent symbol or sequence at most `n` times (included)
65
69
 
66
70
  ## Comments and newlines
67
71
 
@@ -87,5 +91,292 @@ item ::= [^\n]+ "\n"
87
91
 
88
92
  This guide provides a brief overview. Check out the GBNF files in this directory (`grammars/`) for examples of full grammars. You can try them out with:
89
93
  ```
90
- ./main -m <model> --grammar-file grammars/some-grammar.gbnf -p 'Some prompt'
94
+ ./llama-cli -m <model> --grammar-file grammars/some-grammar.gbnf -p 'Some prompt'
91
95
  ```
96
+
97
+ `llama.cpp` can also convert JSON schemas to grammars either ahead of time or at each request, see below.
98
+
99
+ ## Troubleshooting
100
+
101
+ Grammars currently have performance gotchas (see https://github.com/ggerganov/llama.cpp/issues/4218).
102
+
103
+ ### Efficient optional repetitions
104
+
105
+ A common pattern is to allow repetitions of a pattern `x` up to N times.
106
+
107
+ While semantically correct, the syntax `x? x? x?.... x?` (with N repetitions) may result in extremely slow sampling. Instead, you can write `x{0,N}` (or `(x (x (x ... (x)?...)?)?)?` w/ N-deep nesting in earlier llama.cpp versions).
108
+
109
+ ## Using GBNF grammars
110
+
111
+ You can use GBNF grammars:
112
+
113
+ - In [llama-server](../examples/server)'s completion endpoints, passed as the `grammar` body field
114
+ - In [llama-cli](../examples/main), passed as the `--grammar` & `--grammar-file` flags
115
+ - With [llama-gbnf-validator](../examples/gbnf-validator) tool, to test them against strings.
116
+
117
+ ## JSON Schemas → GBNF
118
+
119
+ `llama.cpp` supports converting a subset of https://json-schema.org/ to GBNF grammars:
120
+
121
+ - In [llama-server](../examples/server):
122
+ - For any completion endpoints, passed as the `json_schema` body field
123
+ - For the `/chat/completions` endpoint, passed inside the `response_format` body field (e.g. `{"type", "json_object", "schema": {"items": {}}}` or `{ type: "json_schema", json_schema: {"schema": ...} }`)
124
+ - In [llama-cli](../examples/main), passed as the `--json` / `-j` flag
125
+ - To convert to a grammar ahead of time:
126
+ - in CLI, with [examples/json_schema_to_grammar.py](../examples/json_schema_to_grammar.py)
127
+ - in JavaScript with [json-schema-to-grammar.mjs](../examples/server/public/json-schema-to-grammar.mjs) (this is used by the [server](../examples/server)'s Web UI)
128
+
129
+ Take a look at [tests](../tests/test-json-schema-to-grammar.cpp) to see which features are likely supported (you'll also find usage examples in https://github.com/ggerganov/llama.cpp/pull/5978, https://github.com/ggerganov/llama.cpp/pull/6659 & https://github.com/ggerganov/llama.cpp/pull/6555).
130
+
131
+ ```bash
132
+ llama-cli \
133
+ -hfr bartowski/Phi-3-medium-128k-instruct-GGUF \
134
+ -hff Phi-3-medium-128k-instruct-Q8_0.gguf \
135
+ -j '{
136
+ "type": "array",
137
+ "items": {
138
+ "type": "object",
139
+ "properties": {
140
+ "name": {
141
+ "type": "string",
142
+ "minLength": 1,
143
+ "maxLength": 100
144
+ },
145
+ "age": {
146
+ "type": "integer",
147
+ "minimum": 0,
148
+ "maximum": 150
149
+ }
150
+ },
151
+ "required": ["name", "age"],
152
+ "additionalProperties": false
153
+ },
154
+ "minItems": 10,
155
+ "maxItems": 100
156
+ }' \
157
+ -p 'Generate a {name, age}[] JSON array with famous actors of all ages.'
158
+ ```
159
+
160
+ <details>
161
+
162
+ <summary>Show grammar</summary>
163
+
164
+ You can convert any schema in command-line with:
165
+
166
+ ```bash
167
+ examples/json_schema_to_grammar.py name-age-schema.json
168
+ ```
169
+
170
+ ```
171
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
172
+ item ::= "{" space item-name-kv "," space item-age-kv "}" space
173
+ item-age ::= ([0-9] | ([1-8] [0-9] | [9] [0-9]) | "1" ([0-4] [0-9] | [5] "0")) space
174
+ item-age-kv ::= "\"age\"" space ":" space item-age
175
+ item-name ::= "\"" char{1,100} "\"" space
176
+ item-name-kv ::= "\"name\"" space ":" space item-name
177
+ root ::= "[" space item ("," space item){9,99} "]" space
178
+ space ::= | " " | "\n" [ \t]{0,20}
179
+ ```
180
+
181
+ </details>
182
+
183
+ Here is also a list of known limitations (contributions welcome):
184
+
185
+ - `additionalProperties` defaults to `false` (produces faster grammars + reduces hallucinations).
186
+ - `"additionalProperties": true` may produce keys that contain unescaped newlines.
187
+ - Unsupported features are skipped silently. It is currently advised to use the command-line Python converter (see above) to see any warnings, and to inspect the resulting grammar / test it w/ [llama-gbnf-validator](../examples/gbnf-validator/gbnf-validator.cpp).
188
+ - Can't mix `properties` w/ `anyOf` / `oneOf` in the same type (https://github.com/ggerganov/llama.cpp/issues/7703)
189
+ - [prefixItems](https://json-schema.org/draft/2020-12/json-schema-core#name-prefixitems) is broken (but [items](https://json-schema.org/draft/2020-12/json-schema-core#name-items) works)
190
+ - `minimum`, `exclusiveMinimum`, `maximum`, `exclusiveMaximum`: only supported for `"type": "integer"` for now, not `number`
191
+ - Nested `$ref`s are broken (https://github.com/ggerganov/llama.cpp/issues/8073)
192
+ - [pattern](https://json-schema.org/draft/2020-12/json-schema-validation#name-pattern)s must start with `^` and end with `$`
193
+ - Remote `$ref`s not supported in the C++ version (Python & JavaScript versions fetch https refs)
194
+ - `string` [formats](https://json-schema.org/draft/2020-12/json-schema-validation#name-defined-formats) lack `uri`, `email`
195
+ - No [`patternProperties`](https://json-schema.org/draft/2020-12/json-schema-core#name-patternproperties)
196
+
197
+ And a non-exhaustive list of other unsupported features that are unlikely to be implemented (hard and/or too slow to support w/ stateless grammars):
198
+
199
+ - [`uniqueItems`](https://json-schema.org/draft/2020-12/json-schema-validation#name-uniqueitems)
200
+ - [`contains`](https://json-schema.org/draft/2020-12/json-schema-core#name-contains) / `minContains`
201
+ - `$anchor` (cf. [dereferencing](https://json-schema.org/draft/2020-12/json-schema-core#name-dereferencing))
202
+ - [`not`](https://json-schema.org/draft/2020-12/json-schema-core#name-not)
203
+ - [Conditionals](https://json-schema.org/draft/2020-12/json-schema-core#name-keywords-for-applying-subsche) `if` / `then` / `else` / `dependentSchemas`
204
+
205
+ ### A word about additionalProperties
206
+
207
+ > [!WARNING]
208
+ > The JSON schemas spec states `object`s accept [additional properties](https://json-schema.org/understanding-json-schema/reference/object#additionalproperties) by default.
209
+ > Since this is slow and seems prone to hallucinations, we default to no additional properties.
210
+ > You can set `"additionalProperties": true` in the the schema of any object to explicitly allow additional properties.
211
+
212
+ If you're using [Pydantic](https://pydantic.dev/) to generate schemas, you can enable additional properties with the `extra` config on each model class:
213
+
214
+ ```python
215
+ # pip install pydantic
216
+ import json
217
+ from typing import Annotated, List
218
+ from pydantic import BaseModel, Extra, Field
219
+ class QAPair(BaseModel):
220
+ class Config:
221
+ extra = 'allow' # triggers additionalProperties: true in the JSON schema
222
+ question: str
223
+ concise_answer: str
224
+ justification: str
225
+
226
+ class Summary(BaseModel):
227
+ class Config:
228
+ extra = 'allow'
229
+ key_facts: List[Annotated[str, Field(pattern='- .{5,}')]]
230
+ question_answers: List[Annotated[List[QAPair], Field(min_items=5)]]
231
+
232
+ print(json.dumps(Summary.model_json_schema(), indent=2))
233
+ ```
234
+
235
+ <details>
236
+ <summary>Show JSON schema & grammar</summary>
237
+
238
+ ```json
239
+ {
240
+ "$defs": {
241
+ "QAPair": {
242
+ "additionalProperties": true,
243
+ "properties": {
244
+ "question": {
245
+ "title": "Question",
246
+ "type": "string"
247
+ },
248
+ "concise_answer": {
249
+ "title": "Concise Answer",
250
+ "type": "string"
251
+ },
252
+ "justification": {
253
+ "title": "Justification",
254
+ "type": "string"
255
+ }
256
+ },
257
+ "required": [
258
+ "question",
259
+ "concise_answer",
260
+ "justification"
261
+ ],
262
+ "title": "QAPair",
263
+ "type": "object"
264
+ }
265
+ },
266
+ "additionalProperties": true,
267
+ "properties": {
268
+ "key_facts": {
269
+ "items": {
270
+ "pattern": "^- .{5,}$",
271
+ "type": "string"
272
+ },
273
+ "title": "Key Facts",
274
+ "type": "array"
275
+ },
276
+ "question_answers": {
277
+ "items": {
278
+ "items": {
279
+ "$ref": "#/$defs/QAPair"
280
+ },
281
+ "minItems": 5,
282
+ "type": "array"
283
+ },
284
+ "title": "Question Answers",
285
+ "type": "array"
286
+ }
287
+ },
288
+ "required": [
289
+ "key_facts",
290
+ "question_answers"
291
+ ],
292
+ "title": "Summary",
293
+ "type": "object"
294
+ }
295
+ ```
296
+
297
+ ```
298
+ QAPair ::= "{" space QAPair-question-kv "," space QAPair-concise-answer-kv "," space QAPair-justification-kv ( "," space ( QAPair-additional-kv ( "," space QAPair-additional-kv )* ) )? "}" space
299
+ QAPair-additional-k ::= ["] ( [c] ([o] ([n] ([c] ([i] ([s] ([e] ([_] ([a] ([n] ([s] ([w] ([e] ([r] char+ | [^"r] char*) | [^"e] char*) | [^"w] char*) | [^"s] char*) | [^"n] char*) | [^"a] char*) | [^"_] char*) | [^"e] char*) | [^"s] char*) | [^"i] char*) | [^"c] char*) | [^"n] char*) | [^"o] char*) | [j] ([u] ([s] ([t] ([i] ([f] ([i] ([c] ([a] ([t] ([i] ([o] ([n] char+ | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"a] char*) | [^"c] char*) | [^"i] char*) | [^"f] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"u] char*) | [q] ([u] ([e] ([s] ([t] ([i] ([o] ([n] char+ | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"e] char*) | [^"u] char*) | [^"cjq] char* )? ["] space
300
+ QAPair-additional-kv ::= QAPair-additional-k ":" space value
301
+ QAPair-concise-answer-kv ::= "\"concise_answer\"" space ":" space string
302
+ QAPair-justification-kv ::= "\"justification\"" space ":" space string
303
+ QAPair-question-kv ::= "\"question\"" space ":" space string
304
+ additional-k ::= ["] ( [k] ([e] ([y] ([_] ([f] ([a] ([c] ([t] ([s] char+ | [^"s] char*) | [^"t] char*) | [^"c] char*) | [^"a] char*) | [^"f] char*) | [^"_] char*) | [^"y] char*) | [^"e] char*) | [q] ([u] ([e] ([s] ([t] ([i] ([o] ([n] ([_] ([a] ([n] ([s] ([w] ([e] ([r] ([s] char+ | [^"s] char*) | [^"r] char*) | [^"e] char*) | [^"w] char*) | [^"s] char*) | [^"n] char*) | [^"a] char*) | [^"_] char*) | [^"n] char*) | [^"o] char*) | [^"i] char*) | [^"t] char*) | [^"s] char*) | [^"e] char*) | [^"u] char*) | [^"kq] char* )? ["] space
305
+ additional-kv ::= additional-k ":" space value
306
+ array ::= "[" space ( value ("," space value)* )? "]" space
307
+ boolean ::= ("true" | "false") space
308
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
309
+ decimal-part ::= [0-9]{1,16}
310
+ dot ::= [^\x0A\x0D]
311
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
312
+ key-facts ::= "[" space (key-facts-item ("," space key-facts-item)*)? "]" space
313
+ key-facts-item ::= "\"" "- " key-facts-item-1{5,} "\"" space
314
+ key-facts-item-1 ::= dot
315
+ key-facts-kv ::= "\"key_facts\"" space ":" space key-facts
316
+ null ::= "null" space
317
+ number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
318
+ object ::= "{" space ( string ":" space value ("," space string ":" space value)* )? "}" space
319
+ question-answers ::= "[" space (question-answers-item ("," space question-answers-item)*)? "]" space
320
+ question-answers-item ::= "[" space question-answers-item-item ("," space question-answers-item-item){4,} "]" space
321
+ question-answers-item-item ::= QAPair
322
+ question-answers-kv ::= "\"question_answers\"" space ":" space question-answers
323
+ root ::= "{" space key-facts-kv "," space question-answers-kv ( "," space ( additional-kv ( "," space additional-kv )* ) )? "}" space
324
+ space ::= | " " | "\n" [ \t]{0,20}
325
+ string ::= "\"" char* "\"" space
326
+ value ::= object | array | string | number | boolean | null
327
+ ```
328
+
329
+ </details>
330
+
331
+ If you're using [Zod](https://zod.dev/), you can make your objects to explicitly allow extra properties w/ `nonstrict()` / `passthrough()` (or explicitly no extra props w/ `z.object(...).strict()` or `z.strictObject(...)`) but note that [zod-to-json-schema](https://github.com/StefanTerdell/zod-to-json-schema) currently always sets `"additionalProperties": false` anyway.
332
+
333
+ ```js
334
+ import { z } from 'zod';
335
+ import { zodToJsonSchema } from 'zod-to-json-schema';
336
+
337
+ const Foo = z.object({
338
+ age: z.number().positive(),
339
+ email: z.string().email(),
340
+ }).strict();
341
+
342
+ console.log(zodToJsonSchema(Foo));
343
+ ```
344
+
345
+ <details>
346
+ <summary>Show JSON schema & grammar</summary>
347
+
348
+ ```json
349
+ {
350
+ "type": "object",
351
+ "properties": {
352
+ "age": {
353
+ "type": "number",
354
+ "exclusiveMinimum": 0
355
+ },
356
+ "email": {
357
+ "type": "string",
358
+ "format": "email"
359
+ }
360
+ },
361
+ "required": [
362
+ "age",
363
+ "email"
364
+ ],
365
+ "additionalProperties": false,
366
+ "$schema": "http://json-schema.org/draft-07/schema#"
367
+ }
368
+ ```
369
+
370
+ ```
371
+ age-kv ::= "\"age\"" space ":" space number
372
+ char ::= [^"\\\x7F\x00-\x1F] | [\\] (["\\bfnrt] | "u" [0-9a-fA-F]{4})
373
+ decimal-part ::= [0-9]{1,16}
374
+ email-kv ::= "\"email\"" space ":" space string
375
+ integral-part ::= [0] | [1-9] [0-9]{0,15}
376
+ number ::= ("-"? integral-part) ("." decimal-part)? ([eE] [-+]? integral-part)? space
377
+ root ::= "{" space age-kv "," space email-kv "}" space
378
+ space ::= | " " | "\n" [ \t]{0,20}
379
+ string ::= "\"" char* "\"" space
380
+ ```
381
+
382
+ </details>
@@ -15,11 +15,11 @@ array ::=
15
15
 
16
16
  string ::=
17
17
  "\"" (
18
- [^"\\] |
19
- "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes
18
+ [^"\\\x7F\x00-\x1F] |
19
+ "\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes
20
20
  )* "\"" ws
21
21
 
22
- number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
22
+ number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [0-9] [1-9]{0,15})? ws
23
23
 
24
24
  # Optional space: by convention, applied in this grammar after literal chars when allowed
25
- ws ::= ([ \t\n] ws)?
25
+ ws ::= | " " | "\n" [ \t]{0,20}
@@ -24,11 +24,11 @@ array ::=
24
24
 
25
25
  string ::=
26
26
  "\"" (
27
- [^"\\] |
28
- "\\" (["\\/bfnrt] | "u" [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F] [0-9a-fA-F]) # escapes
27
+ [^"\\\x7F\x00-\x1F] |
28
+ "\\" (["\\bfnrt] | "u" [0-9a-fA-F]{4}) # escapes
29
29
  )* "\"" ws
30
30
 
31
- number ::= ("-"? ([0-9] | [1-9] [0-9]*)) ("." [0-9]+)? ([eE] [-+]? [0-9]+)? ws
31
+ number ::= ("-"? ([0-9] | [1-9] [0-9]{0,15})) ("." [0-9]+)? ([eE] [-+]? [1-9] [0-9]{0,15})? ws
32
32
 
33
33
  # Optional space: by convention, applied in this grammar after literal chars when allowed
34
- ws ::= ([ \t\n] ws)?
34
+ ws ::= | " " | "\n" [ \t]{0,20}
@@ -1,4 +1,4 @@
1
1
  {
2
- "tag": "b2074",
2
+ "tag": "b3808",
3
3
  "llamaCppGithubRepo": "ggerganov/llama.cpp"
4
4
  }
@@ -0,0 +1,41 @@
1
+ set(CMAKE_SYSTEM_NAME Windows)
2
+ set(CMAKE_SYSTEM_PROCESSOR ARM64)
3
+
4
+ # Look for cl.exe in the Visual Studio installation directories
5
+ set(PROGRAMFILES "$ENV{ProgramFiles}")
6
+ set(PROGRAMFILES_X86 "$ENV{ProgramFiles\(x86\)}")
7
+
8
+ set(VS_INSTALL_PATHS
9
+ "${PROGRAMFILES_X86}/Microsoft Visual Studio"
10
+ "${PROGRAMFILES}/Microsoft Visual Studio"
11
+ "C:/Program Files (x86)/Microsoft Visual Studio"
12
+ "C:/Program Files/Microsoft Visual Studio"
13
+ )
14
+ foreach(PATH IN LISTS VS_INSTALL_PATHS)
15
+ if(CL_EXE_PATH)
16
+ break()
17
+ endif()
18
+
19
+ file(GLOB_RECURSE FOUND_CL_EXE "${PATH}/*/VC/Tools/MSVC/*/bin/Hostx64/arm64/cl.exe")
20
+ if(FOUND_CL_EXE)
21
+ list(GET FOUND_CL_EXE 0 CL_EXE_PATH)
22
+ break()
23
+ endif()
24
+
25
+ if(CL_EXE_PATH)
26
+ break()
27
+ endif()
28
+
29
+ file(GLOB_RECURSE FOUND_CL_EXE "${PATH}/**/*/VC/Tools/MSVC/*/bin/Hostx64/arm64/cl.exe")
30
+ if(FOUND_CL_EXE)
31
+ list(GET FOUND_CL_EXE 0 CL_EXE_PATH)
32
+ break()
33
+ endif()
34
+ endforeach()
35
+
36
+ if(NOT CL_EXE_PATH)
37
+ message(FATAL_ERROR "cl.exe not found for ARM architecture.")
38
+ else()
39
+ set(CMAKE_C_COMPILER "${CL_EXE_PATH}")
40
+ set(CMAKE_CXX_COMPILER "${CL_EXE_PATH}")
41
+ endif()