@fugood/llama.node 0.6.3 → 1.0.0-beta.2

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 (377) hide show
  1. package/CMakeLists.txt +40 -30
  2. package/README.md +4 -1
  3. package/lib/binding.js +41 -29
  4. package/lib/binding.ts +26 -25
  5. package/package.json +40 -7
  6. package/scripts/build.js +47 -0
  7. package/scripts/llama.cpp.patch +109 -0
  8. package/src/anyascii.c +22223 -0
  9. package/src/anyascii.h +42 -0
  10. package/src/tts_utils.cpp +20 -7
  11. package/src/tts_utils.h +2 -0
  12. package/bin/darwin/arm64/llama-node.node +0 -0
  13. package/bin/darwin/x64/llama-node.node +0 -0
  14. package/bin/linux/arm64/llama-node.node +0 -0
  15. package/bin/linux/x64/llama-node.node +0 -0
  16. package/bin/linux-cuda/arm64/llama-node.node +0 -0
  17. package/bin/linux-cuda/x64/llama-node.node +0 -0
  18. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  19. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  20. package/bin/win32/x64/llama-node.node +0 -0
  21. package/bin/win32/x64/node.lib +0 -0
  22. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  23. package/bin/win32-vulkan/arm64/node.lib +0 -0
  24. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  25. package/bin/win32-vulkan/x64/node.lib +0 -0
  26. package/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
  27. package/src/llama.cpp/.github/workflows/build.yml +0 -1078
  28. package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
  29. package/src/llama.cpp/.github/workflows/docker.yml +0 -178
  30. package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
  31. package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
  32. package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
  33. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
  34. package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
  35. package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
  36. package/src/llama.cpp/.github/workflows/release.yml +0 -739
  37. package/src/llama.cpp/.github/workflows/server.yml +0 -237
  38. package/src/llama.cpp/.github/workflows/winget.yml +0 -42
  39. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
  40. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
  41. package/src/llama.cpp/cmake/build-info.cmake +0 -64
  42. package/src/llama.cpp/cmake/common.cmake +0 -35
  43. package/src/llama.cpp/cmake/git-vars.cmake +0 -22
  44. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
  45. package/src/llama.cpp/common/build-info.cpp.in +0 -4
  46. package/src/llama.cpp/docs/build.md +0 -561
  47. package/src/llama.cpp/examples/CMakeLists.txt +0 -43
  48. package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
  49. package/src/llama.cpp/examples/batched/batched.cpp +0 -246
  50. package/src/llama.cpp/examples/chat-13B.bat +0 -57
  51. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
  52. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
  53. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
  54. package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
  55. package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
  56. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
  57. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
  58. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
  59. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
  60. package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
  61. package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
  62. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
  63. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
  64. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
  65. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
  66. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
  67. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
  68. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
  69. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
  70. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
  71. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
  72. package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
  73. package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
  74. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
  75. package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
  76. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
  77. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
  78. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
  79. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
  80. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
  81. package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
  82. package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
  83. package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
  84. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
  85. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
  86. package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
  87. package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
  88. package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
  89. package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
  90. package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
  91. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
  92. package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
  93. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
  94. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
  95. package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
  96. package/src/llama.cpp/examples/simple/simple.cpp +0 -206
  97. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
  98. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
  99. package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
  100. package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
  101. package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
  102. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
  103. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
  104. package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
  105. package/src/llama.cpp/examples/sycl/build.sh +0 -23
  106. package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
  107. package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
  108. package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
  109. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
  110. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
  111. package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
  112. package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
  113. package/src/llama.cpp/examples/training/finetune.cpp +0 -96
  114. package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
  115. package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
  116. package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
  117. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
  118. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
  119. package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
  120. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
  121. package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
  122. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
  123. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
  124. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
  125. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
  126. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
  127. package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
  128. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
  129. package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
  130. package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
  131. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
  132. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
  133. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
  134. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
  135. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
  136. package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
  137. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  138. package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  139. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
  140. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
  141. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
  142. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
  143. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
  144. package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
  145. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
  146. package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
  147. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
  148. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
  149. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
  150. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
  151. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
  152. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
  153. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
  154. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
  155. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
  156. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
  157. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
  158. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
  159. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
  160. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
  161. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
  162. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
  163. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
  164. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
  165. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
  166. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
  167. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
  168. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
  169. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
  170. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
  171. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
  172. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
  173. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
  174. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
  175. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
  176. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
  177. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
  178. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
  179. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
  180. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
  181. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
  182. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
  183. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
  184. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
  185. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
  186. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
  187. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
  188. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
  189. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
  190. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
  191. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
  192. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
  193. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
  194. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
  195. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
  196. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
  197. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
  198. package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
  199. package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
  200. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
  201. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
  202. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
  203. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
  204. package/src/llama.cpp/ggml/src/ggml.c +0 -6550
  205. package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
  206. package/src/llama.cpp/models/.editorconfig +0 -1
  207. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  208. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  209. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  210. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
  211. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
  212. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
  213. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
  214. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  215. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
  216. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
  217. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  218. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
  219. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
  220. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  221. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
  222. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
  223. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
  225. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  226. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
  227. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
  228. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  229. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
  230. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
  231. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
  232. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
  233. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  234. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
  236. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
  237. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  238. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
  239. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
  240. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
  241. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
  242. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
  245. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  246. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
  248. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
  249. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
  250. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
  253. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
  256. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
  257. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
  258. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  259. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
  260. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
  261. package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
  262. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
  263. package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
  264. package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
  265. package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
  266. package/src/llama.cpp/prompts/alpaca.txt +0 -1
  267. package/src/llama.cpp/prompts/assistant.txt +0 -31
  268. package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
  269. package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
  270. package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
  271. package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
  272. package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
  273. package/src/llama.cpp/prompts/chat.txt +0 -28
  274. package/src/llama.cpp/prompts/dan-modified.txt +0 -1
  275. package/src/llama.cpp/prompts/dan.txt +0 -1
  276. package/src/llama.cpp/prompts/mnemonics.txt +0 -93
  277. package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
  278. package/src/llama.cpp/prompts/reason-act.txt +0 -18
  279. package/src/llama.cpp/requirements/requirements-all.txt +0 -15
  280. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
  281. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
  282. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
  283. package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
  284. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
  285. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
  286. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
  287. package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
  288. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
  289. package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
  290. package/src/llama.cpp/requirements.txt +0 -13
  291. package/src/llama.cpp/scripts/build-info.sh +0 -30
  292. package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
  293. package/src/llama.cpp/scripts/xxd.cmake +0 -16
  294. package/src/llama.cpp/tests/CMakeLists.txt +0 -177
  295. package/src/llama.cpp/tests/get-model.cpp +0 -21
  296. package/src/llama.cpp/tests/get-model.h +0 -2
  297. package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
  298. package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
  299. package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
  300. package/src/llama.cpp/tests/test-barrier.cpp +0 -94
  301. package/src/llama.cpp/tests/test-c.c +0 -7
  302. package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
  303. package/src/llama.cpp/tests/test-chat.cpp +0 -985
  304. package/src/llama.cpp/tests/test-double-float.cpp +0 -57
  305. package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
  306. package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
  307. package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
  308. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
  309. package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
  310. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
  311. package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
  312. package/src/llama.cpp/tests/test-log.cpp +0 -39
  313. package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
  314. package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
  315. package/src/llama.cpp/tests/test-opt.cpp +0 -904
  316. package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
  317. package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
  318. package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
  319. package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
  320. package/src/llama.cpp/tests/test-rope.cpp +0 -262
  321. package/src/llama.cpp/tests/test-sampling.cpp +0 -399
  322. package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
  323. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
  324. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
  325. package/src/llama.cpp/tools/CMakeLists.txt +0 -39
  326. package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
  327. package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
  328. package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
  329. package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
  330. package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
  331. package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
  332. package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
  333. package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
  334. package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
  335. package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
  336. package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
  337. package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
  338. package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
  339. package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
  340. package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
  341. package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
  342. package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
  343. package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
  344. package/src/llama.cpp/tools/main/main.cpp +0 -977
  345. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
  346. package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
  347. package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
  348. package/src/llama.cpp/tools/mtmd/clip.h +0 -101
  349. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
  350. package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
  351. package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
  352. package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
  353. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
  354. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
  355. package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
  356. package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
  357. package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
  358. package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
  359. package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
  360. package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
  361. package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
  362. package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
  363. package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
  364. package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
  365. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
  366. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
  367. package/src/llama.cpp/tools/run/run.cpp +0 -1261
  368. package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
  369. package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
  370. package/src/llama.cpp/tools/server/httplib.h +0 -10506
  371. package/src/llama.cpp/tools/server/server.cpp +0 -4966
  372. package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
  373. package/src/llama.cpp/tools/server/utils.hpp +0 -1337
  374. package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
  375. package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
  376. package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
  377. package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
@@ -1,1308 +0,0 @@
1
- #ifdef NDEBUG
2
- #undef NDEBUG
3
- #endif
4
-
5
- #include "json-schema-to-grammar.h"
6
-
7
- #include "../src/unicode.h"
8
- #include "../src/llama-grammar.h"
9
-
10
- #include <cassert>
11
- #include <string>
12
- #include <vector>
13
-
14
- using json = nlohmann::ordered_json;
15
-
16
- static llama_grammar * build_grammar(const std::string & grammar_str) {
17
- return llama_grammar_init_impl(nullptr, grammar_str.c_str(), "root", false, nullptr, 0, nullptr, 0);
18
- }
19
-
20
- static bool test_build_grammar_fails(const std::string & grammar_str) {
21
- fprintf(stderr, "⚫ Testing failure for grammar: %s\n", grammar_str.c_str());
22
- bool grammar_fails = false;
23
- llama_grammar * grammar = build_grammar(grammar_str);
24
- if (grammar != nullptr) {
25
- fprintf(stderr, " ❌ Expected build failure, but succeeded\n");
26
- } else {
27
- grammar_fails = true;
28
- fprintf(stdout, " ✅︎\n");
29
- }
30
- return grammar_fails;
31
- }
32
-
33
- static bool match_string(const std::string & input, llama_grammar * grammar) {
34
- const auto cpts = unicode_cpts_from_utf8(input);
35
-
36
- auto & stacks_cur = llama_grammar_get_stacks(grammar);
37
-
38
- for (const auto & cpt : cpts) {
39
- llama_grammar_accept(grammar, cpt);
40
-
41
- if (stacks_cur.empty()) {
42
- // no stacks means that the grammar failed to match at this point
43
- return false;
44
- }
45
- }
46
-
47
- for (const auto & stack : stacks_cur) {
48
- if (stack.empty()) {
49
- // An empty stack means that the grammar has been completed
50
- return true;
51
- }
52
- }
53
-
54
- return false;
55
- }
56
-
57
- static void test(const std::string & test_desc, const std::string & grammar_str, const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
58
- fprintf(stderr, "⚫ Testing %s\n%s\n", test_desc.c_str(), grammar_str.c_str());
59
- fflush(stderr);
60
-
61
- auto * grammar = build_grammar(grammar_str);
62
-
63
- // Save the original grammar stacks so that we can reset after every new string we want to test
64
- const llama_grammar_stacks stacks_org = llama_grammar_get_stacks(grammar); // copy
65
-
66
- llama_grammar_stacks & stacks_cur = llama_grammar_get_stacks(grammar);
67
-
68
- fprintf(stderr, " 🔵 Valid strings:\n");
69
-
70
- // Passing strings
71
- for (const auto & test_string : passing_strings) {
72
- fprintf(stderr, " \"%s\" ", test_string.c_str());
73
- fflush(stderr);
74
-
75
- bool matched = match_string(test_string, grammar);
76
-
77
- if (!matched) {
78
- fprintf(stderr, "❌ (failed to match)\n");
79
-
80
- // DEBUG: Write strings to files so that we can analyze more easily with gbnf-validator program to see exactly where things failed.
81
- // DEBUG: Write the grammar_str to test-grammar-integration.grammar.gbnf
82
- FILE* grammar_file = fopen("test-grammar-integration.grammar.gbnf", "w");
83
- if (grammar_file) {
84
- fprintf(grammar_file, "%s", grammar_str.c_str());
85
- fclose(grammar_file);
86
- }
87
-
88
- // DEBUG: Write the test string to test-grammar-integration.string.txt
89
- FILE* string_file = fopen("test-grammar-integration.string.txt", "w");
90
- if (string_file) {
91
- fprintf(string_file, "%s", test_string.c_str());
92
- fclose(string_file);
93
- }
94
-
95
- fprintf(stderr, "\n NOTE: Debug grammar file generated. To analyze this failure in detail, run the following command: ./llama-gbnf-validator test-grammar-integration.grammar.gbnf test-grammar-integration.string.txt\n\n");
96
- } else {
97
- fprintf(stdout, "✅︎\n");
98
- }
99
-
100
- assert(matched);
101
-
102
- // Reset the grammar stacks
103
- stacks_cur = stacks_org;
104
- }
105
-
106
- fprintf(stderr, " 🟠 Invalid strings:\n");
107
-
108
- // Failing strings
109
- for (const auto & test_string : failing_strings) {
110
- fprintf(stderr, " \"%s\" ", test_string.c_str());
111
- fflush(stderr);
112
-
113
- bool matched = match_string(test_string, grammar);
114
-
115
- if (matched) {
116
- fprintf(stderr, "❌ (incorrectly matched)\n");
117
- } else {
118
- fprintf(stdout, "✅︎\n");
119
- }
120
- assert(!matched);
121
-
122
- // Reset the grammar stacks
123
- stacks_cur = stacks_org;
124
- }
125
-
126
- // Clean up allocated memory
127
- llama_grammar_free_impl(grammar);
128
- }
129
- static void test_grammar(const std::string & test_desc, const std::string & grammar_str, const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
130
- test(test_desc + ". Grammar: " + grammar_str, grammar_str, passing_strings, failing_strings);
131
- }
132
- static void test_schema(const std::string & test_desc, const std::string & schema_str, const std::vector<std::string> & passing_strings, const std::vector<std::string> & failing_strings) {
133
- test(test_desc + ". Schema: " + schema_str, json_schema_to_grammar(json::parse(schema_str), true), passing_strings, failing_strings);
134
- }
135
-
136
- static void test_simple_grammar() {
137
- test_schema(
138
- "min 0",
139
- R"""({
140
- "type": "integer",
141
- "minimum": 0
142
- })""",
143
- // Passing strings
144
- {
145
- "0",
146
- "10",
147
- "12",
148
- "10000",
149
- },
150
- // Failing strings
151
- {
152
- "-1",
153
- "-10",
154
- "-10000",
155
- "-100000000000000000000000000000000",
156
- "100000000000000000000000000000000",
157
- "00",
158
- "01",
159
- "-0",
160
- }
161
- );
162
- test_schema(
163
- "min 2",
164
- // Schema
165
- R"""({
166
- "type": "integer",
167
- "minimum": 2
168
- })""",
169
- // Passing strings
170
- {
171
- "2",
172
- "3",
173
- "4",
174
- "10",
175
- "20",
176
- "1234567890000000",
177
- },
178
- // Failing strings
179
- {
180
- "0",
181
- "1",
182
- "-1",
183
- "-100",
184
- "0",
185
- "1",
186
- "01",
187
- "02",
188
- "12345678900000000",
189
- }
190
- );
191
- test_schema(
192
- "min 456",
193
- R"""({
194
- "type": "integer",
195
- "minimum": 456
196
- })""",
197
- // Passing strings
198
- {
199
- "456",
200
- "4560",
201
- "457",
202
- "460",
203
- "500",
204
- },
205
- // Failing strings
206
- {
207
- "455",
208
- "356",
209
- "50",
210
- "050",
211
- "-1",
212
- "-456",
213
- }
214
- );
215
- test_schema(
216
- "min -123",
217
- R"""({
218
- "type": "integer",
219
- "minimum": -123
220
- })""",
221
- // Passing strings
222
- {
223
- "-123",
224
- "-122",
225
- "-11",
226
- "-1",
227
- "0",
228
- "1",
229
- "123",
230
- "1234",
231
- "2345",
232
- },
233
- // Failing strings
234
- {
235
- "-1234",
236
- "-124",
237
- }
238
- );
239
-
240
- test_schema(
241
- "max 9999",
242
- // Schema
243
- R"""({
244
- "type": "integer",
245
- "maximum": 9999
246
- })""",
247
- // Passing strings
248
- {
249
- "-99999",
250
- "0",
251
- "9999",
252
- },
253
- // Failing strings
254
- {
255
- "10000",
256
- "99991",
257
- }
258
- );
259
- test_schema(
260
- "max -9999",
261
- // Schema
262
- R"""({
263
- "type": "integer",
264
- "maximum": -9999
265
- })""",
266
- // Passing strings
267
- {
268
- "-10000",
269
- "-9999",
270
- },
271
- // Failing strings
272
- {
273
- "-9998",
274
- "0",
275
- "9999",
276
- }
277
- );
278
- test_schema(
279
- "min 5 max 30",
280
- // Schema
281
- R"""({
282
- "type": "integer",
283
- "minimum": 5,
284
- "maximum": 30
285
- })""",
286
- // Passing strings
287
- {
288
- "5",
289
- "10",
290
- "30",
291
- },
292
- // Failing strings
293
- {
294
- "05",
295
- "4",
296
- "-1",
297
- "31",
298
- "123",
299
- "0123",
300
- }
301
- );
302
- test_schema(
303
- "min -1 max 1",
304
- R"""({
305
- "type": "integer",
306
- "minimum": -1,
307
- "maximum": 1
308
- })""",
309
- // Passing strings
310
- {
311
- "-1",
312
- "0",
313
- "1",
314
- },
315
- // Failing strings
316
- {
317
- "-11",
318
- "-10",
319
- "-2",
320
- "2",
321
- "10",
322
- "11",
323
- }
324
- );
325
- test_schema(
326
- "min -123 max 42",
327
- R"""({
328
- "type": "integer",
329
- "minimum": -123,
330
- "maximum": 42
331
- })""",
332
- // Passing strings
333
- {
334
- "-123",
335
- "-122",
336
- "-13",
337
- "-11",
338
- "-2",
339
- "-1",
340
- "0",
341
- "1",
342
- "5",
343
- "10",
344
- "39",
345
- "40",
346
- "42",
347
- },
348
- // Failing strings
349
- {
350
- "-0123",
351
- "-124",
352
- "-1123",
353
- "-200",
354
- "43",
355
- "123",
356
- "0123",
357
- }
358
- );
359
- test_schema(
360
- "exclusive min / max",
361
- // Schema
362
- R"""({
363
- "type": "integer",
364
- "exclusiveMinimum": 0,
365
- "exclusiveMaximum": 10000
366
- })""",
367
- // Passing strings
368
- {
369
- "1",
370
- "9999",
371
- },
372
- // Failing strings
373
- {
374
- "0",
375
- "01",
376
- "10000",
377
- "99999",
378
- }
379
- );
380
-
381
- // Test case for a simple grammar
382
- test_grammar(
383
- "simple grammar",
384
- R"""(
385
- root ::= expr
386
- expr ::= term ("+" term)*
387
- term ::= number
388
- number ::= [0-9]+)""",
389
- // Passing strings
390
- {
391
- "42",
392
- "1+2+3+4+5",
393
- "123+456",
394
- },
395
- // Failing strings
396
- {
397
- "+",
398
- "/ 3",
399
- "1+2+3+4+5+",
400
- "12a45",
401
- }
402
- );
403
- }
404
-
405
- static void test_complex_grammar() {
406
- // Test case for a more complex grammar, with both failure strings and success strings
407
- test_grammar(
408
- "medium complexity grammar",
409
- // Grammar
410
- R"""(
411
- root ::= expression
412
- expression ::= term ws (("+"|"-") ws term)*
413
- term ::= factor ws (("*"|"/") ws factor)*
414
- factor ::= number | variable | "(" expression ")" | function-call
415
- number ::= [0-9]+
416
- variable ::= [a-zA-Z_][a-zA-Z0-9_]*
417
- function-call ::= variable ws "(" (expression ("," ws expression)*)? ")"
418
- ws ::= [ \t\n\r]?)""",
419
- // Passing strings
420
- {
421
- "42",
422
- "1*2*3*4*5",
423
- "x",
424
- "x+10",
425
- "x1+y2",
426
- "(a+b)*(c-d)",
427
- "func()",
428
- "func(x,y+2)",
429
- "a*(b+c)-d/e",
430
- "f(g(x),h(y,z))",
431
- "x + 10",
432
- "x1 + y2",
433
- "(a + b) * (c - d)",
434
- "func()",
435
- "func(x, y + 2)",
436
- "a * (b + c) - d / e",
437
- "f(g(x), h(y, z))",
438
- "123+456",
439
- "123*456*789-123/456+789*123",
440
- "123+456*789-123/456+789*123-456/789+123*456-789/123+456*789-123/456+789*123-456"
441
- },
442
- // Failing strings
443
- {
444
- "+",
445
- "/ 3x",
446
- "x + + y",
447
- "a * / b",
448
- "func(,)",
449
- "func(x y)",
450
- "(a + b",
451
- "x + y)",
452
- "a + b * (c - d",
453
- "42 +",
454
- "x +",
455
- "x + 10 +",
456
- "(a + b) * (c - d",
457
- "func(",
458
- "func(x, y + 2",
459
- "a * (b + c) - d /",
460
- "f(g(x), h(y, z)",
461
- "123+456*789-123/456+789*123-456/789+123*456-789/123+456*789-123/456+789*123-456/",
462
- }
463
- );
464
- }
465
-
466
- static void test_special_chars() {
467
- // A collection of tests to exercise special characters such as "."
468
- test_grammar(
469
- "special characters",
470
- // Grammar
471
- R"""(
472
- root ::= ... "abc" ...
473
- )""",
474
- // Passing strings
475
- {
476
- "abcabcabc",
477
- "aaaabcccc",
478
- // NOTE: Also ensures that multi-byte characters still count as a single character
479
- "🔵🟠✅abc❌🟠🔵"
480
- },
481
- // Failing strings
482
- {
483
- "aaabcccc",
484
- "aaaaabcccc",
485
- "aaaabccc",
486
- "aaaabccccc",
487
- "🔵🟠✅❌abc❌✅🟠🔵",
488
- "🔵🟠abc🟠🔵"
489
- }
490
- );
491
- }
492
-
493
- static void test_quantifiers() {
494
- // A collection of tests to exercise * + and ? quantifiers
495
-
496
- test_grammar(
497
- "* quantifier",
498
- // Grammar
499
- R"""(root ::= "a"*)""",
500
- // Passing strings
501
- {
502
- "",
503
- "a",
504
- "aaaaa",
505
- "aaaaaaaaaaaaaaaaaa",
506
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
507
- },
508
- // Failing strings
509
- {
510
- "b",
511
- "ab",
512
- "aab",
513
- "ba",
514
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
515
- }
516
- );
517
- test_grammar(
518
- "+ quantifier",
519
- // Grammar
520
- R"""(root ::= "a"+)""",
521
- // Passing strings
522
- {
523
- "a",
524
- "aaaaa",
525
- "aaaaaaaaaaaaaaaaaa",
526
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
527
- },
528
- // Failing strings
529
- {
530
- "",
531
- "b",
532
- "ab",
533
- "aab",
534
- "ba",
535
- "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"
536
- }
537
- );
538
- test_grammar(
539
- "? quantifier",
540
- // Grammar
541
- R"""(root ::= "a"?)""",
542
- // Passing strings
543
- {
544
- "",
545
- "a"
546
- },
547
- // Failing strings
548
- {
549
- "b",
550
- "ab",
551
- "aa",
552
- "ba",
553
- }
554
- );
555
- test_grammar(
556
- "mixed quantifiers",
557
- // Grammar
558
- R"""(
559
- root ::= cons+ vowel* cons? (vowel cons)*
560
- vowel ::= [aeiouy]
561
- cons ::= [bcdfghjklmnpqrstvwxyz]
562
- )""",
563
- // Passing strings
564
- {
565
- "yes",
566
- "no",
567
- "noyes",
568
- "crwth",
569
- "four",
570
- "bryyyy",
571
- },
572
- // Failing strings
573
- {
574
- "yess",
575
- "yesno",
576
- "forty",
577
- "catyyy",
578
- }
579
- );
580
- test_grammar(
581
- "simple exact repetition",
582
- // Grammar
583
- R"""(
584
- root ::= [ab]{4}
585
- )""",
586
- // Passing strings
587
- {
588
- "aaaa",
589
- "bbbb",
590
- "abab",
591
- },
592
- // Failing strings
593
- {
594
- "a",
595
- "b",
596
- "aaaaa",
597
- }
598
- );
599
- test_grammar(
600
- "simple min repetition",
601
- // Grammar
602
- R"""(
603
- root ::= [ab]{4,}
604
- )""",
605
- // Passing strings
606
- {
607
- "aaaa",
608
- "aaaaab",
609
- "bbbb",
610
- "ababab",
611
- },
612
- // Failing strings
613
- {
614
- "",
615
- "aba",
616
- }
617
- );
618
- test_grammar(
619
- "simple max repetition",
620
- // Grammar
621
- R"""(
622
- root ::= [ab]{0,4}
623
- )""",
624
- // Passing strings
625
- {
626
- "",
627
- "a",
628
- "aa",
629
- "aaa",
630
- "aaab",
631
- },
632
- // Failing strings
633
- {
634
- "aaaaa",
635
- }
636
- );
637
- test_grammar(
638
- "min / max repetition",
639
- // Grammar
640
- R"""(
641
- root ::= ("0x" [A-F0-9]{2} " "?){3,5}
642
- )""",
643
- // Passing strings
644
- {
645
- "0xFF 0x12 0xAB",
646
- "0xFF 0x12 0xAB 0x00 0x00",
647
- },
648
- // Failing strings
649
- {
650
- "",
651
- "0xFF",
652
- "0xFF 0x12",
653
- "0xFF 0x12 0xAB 0x00 0x00 0x00",
654
- }
655
- );
656
- }
657
-
658
- static void test_failure_missing_root() {
659
- fprintf(stderr, "⚫ Testing missing root node:\n");
660
- // Test case for a grammar that is missing a root rule
661
- const std::string grammar_str = R"""(
662
- rot ::= expr
663
- expr ::= term ("+" term)*
664
- term ::= number
665
- number ::= [0-9]+)""";
666
-
667
- llama_grammar_parser parsed_grammar;
668
- parsed_grammar.parse(grammar_str.c_str());
669
-
670
- // Ensure we parsed correctly
671
- assert(!parsed_grammar.rules.empty());
672
-
673
- // Ensure we do NOT have a root node
674
- assert(parsed_grammar.symbol_ids.find("root") == parsed_grammar.symbol_ids.end());
675
- fprintf(stderr, " ✅︎ Passed\n");
676
- }
677
-
678
- static void test_failure_missing_reference() {
679
- fprintf(stderr, "⚫ Testing missing reference node:\n");
680
-
681
- // Test case for a grammar that is missing a referenced rule
682
- const std::string grammar_str =
683
- R"""(root ::= expr
684
- expr ::= term ("+" term)*
685
- term ::= numero
686
- number ::= [0-9]+)""";
687
-
688
- fprintf(stderr, " Expected error: ");
689
-
690
- llama_grammar_parser parsed_grammar;
691
- parsed_grammar.parse(grammar_str.c_str());
692
-
693
- // Ensure we did NOT parsed correctly
694
- assert(parsed_grammar.rules.empty());
695
-
696
- fprintf(stderr, " End of expected error.\n");
697
- fprintf(stderr, " ✅︎ Passed\n");
698
- }
699
-
700
- static void test_failure_left_recursion() {
701
- fprintf(stderr, "⚫ Testing left recursion detection:\n");
702
-
703
- // Test simple left recursion detection
704
- const std::string simple_str = R"""(root ::= "a" | root "a")""";
705
- assert(test_build_grammar_fails(simple_str));
706
-
707
- // Test more complicated left recursion detection
708
- const std::string medium_str = R"""(
709
- root ::= asdf
710
- asdf ::= "a" | asdf "a"
711
- )""";
712
- assert(test_build_grammar_fails(medium_str));
713
-
714
- // Test even more complicated left recursion detection
715
- const std::string hard_str = R"""(
716
- root ::= asdf
717
- asdf ::= "a" | foo "b"
718
- foo ::= "c" | asdf "d" | "e")""";
719
- assert(test_build_grammar_fails(hard_str));
720
-
721
- // Test yet even more complicated left recursion detection
722
- const std::string hardest_str = R"""(
723
- root ::= asdf
724
- asdf ::= "a" | foo "b"
725
- foo ::= "c" | empty asdf "d" | "e"
726
- empty ::= "blah" | )""";
727
- assert(test_build_grammar_fails(hardest_str));
728
-
729
- fprintf(stderr, " ✅︎ Passed\n");
730
- }
731
-
732
- static void test_json_schema() {
733
- // Note that this is similar to the regular grammar tests,
734
- // but we convert each json schema to a grammar before parsing.
735
- // Otherwise, this test structure is the same.
736
-
737
- test_schema(
738
- "empty schema (object)",
739
- // Schema
740
- R"""(
741
- {}
742
- )""",
743
- // Passing strings
744
- {
745
- R"""({})""",
746
- R"""({"foo": "bar"})""",
747
- },
748
- // Failing strings
749
- {
750
- "",
751
- "[]",
752
- "null",
753
- R"""("")""",
754
- "true",
755
- }
756
- );
757
-
758
- test_schema(
759
- "exotic formats (list)",
760
- // Schema
761
- R"""({
762
- "items": [
763
- { "format": "date" },
764
- { "format": "uuid" },
765
- { "format": "time" },
766
- { "format": "date-time" }
767
- ]
768
- })""",
769
- // Passing strings
770
- {
771
- // "{}", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
772
- // "[]", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
773
- R"""(["2012-04-23", "12345678-1234-1234-1234-1234567890ab", "18:25:43.511Z", "2012-04-23T18:25:43.511Z"])""",
774
- //R"""(["2012-04-23","12345678-1234-1234-1234-1234567890ab"])""", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
775
- //R"""({"foo": "bar"})""", // NOTE: This string passes for this schema on https://www.jsonschemavalidator.net/ -- should it?
776
- },
777
- // Failing strings
778
- {
779
- R"""(["foo", "bar"])""",
780
- R"""(["12345678-1234-1234-1234-1234567890ab"])""",
781
- }
782
- );
783
-
784
- test_schema(
785
- "string",
786
- // Schema
787
- R"""({
788
- "type": "string"
789
- })""",
790
- // Passing strings
791
- {
792
- R"""("foo")""",
793
- R"""("bar")""",
794
- R"""("")""",
795
- },
796
- // Failing strings
797
- {
798
- R"""({})""",
799
- R"""("foo": "bar")""",
800
- }
801
- );
802
-
803
- test_schema(
804
- "string w/ min length 1",
805
- // Schema
806
- R"""({
807
- "type": "string",
808
- "minLength": 1
809
- })""",
810
- // Passing strings
811
- {
812
- R"""("foo")""",
813
- R"""("bar")""",
814
- },
815
- // Failing strings
816
- {
817
- R"""("")""",
818
- R"""({})""",
819
- R"""("foo": "bar")""",
820
- }
821
- );
822
-
823
- test_schema(
824
- "string w/ min length 3",
825
- // Schema
826
- R"""({
827
- "type": "string",
828
- "minLength": 3
829
- })""",
830
- // Passing strings
831
- {
832
- R"""("foo")""",
833
- R"""("bar")""",
834
- R"""("foobar")""",
835
- },
836
- // Failing strings
837
- {
838
- R"""("")""",
839
- R"""("f")""",
840
- R"""("fo")""",
841
- }
842
- );
843
-
844
- test_schema(
845
- "string w/ max length",
846
- // Schema
847
- R"""({
848
- "type": "string",
849
- "maxLength": 3
850
- })""",
851
- // Passing strings
852
- {
853
- R"""("foo")""",
854
- R"""("bar")""",
855
- R"""("")""",
856
- R"""("f")""",
857
- R"""("fo")""",
858
- },
859
- // Failing strings
860
- {
861
- R"""("foobar")""",
862
- }
863
- );
864
-
865
- test_schema(
866
- "string w/ min & max length",
867
- // Schema
868
- R"""({
869
- "type": "string",
870
- "minLength": 1,
871
- "maxLength": 4
872
- })""",
873
- // Passing strings
874
- {
875
- R"""("foo")""",
876
- R"""("bar")""",
877
- R"""("f")""",
878
- R"""("barf")""",
879
- },
880
- // Failing strings
881
- {
882
- R"""("")""",
883
- R"""("barfo")""",
884
- R"""("foobar")""",
885
- }
886
- );
887
-
888
- test_schema(
889
- "boolean",
890
- // Schema
891
- R"""({
892
- "type": "boolean"
893
- })""",
894
- // Passing strings
895
- {
896
- "true",
897
- "false",
898
- },
899
- // Failing strings
900
- {
901
- R"""("")""",
902
- R"""("true")""",
903
- R"""(True)""",
904
- R"""(FALSE)""",
905
- }
906
- );
907
-
908
- test_schema(
909
- "integer",
910
- // Schema
911
- R"""({
912
- "type": "integer"
913
- })""",
914
- // Passing strings
915
- {
916
- R"""(0)""",
917
- R"""(12345)""",
918
- R"""(1234567890123456)""",
919
- },
920
- // Failing strings
921
- {
922
- R"""()""",
923
- R"""(01)""",
924
- R"""(007)""",
925
- R"""(12345678901234567 )""",
926
- }
927
- );
928
-
929
- test_schema(
930
- "string const",
931
- // Schema
932
- R"""({
933
- "const": "foo"
934
- })""",
935
- // Passing strings
936
- {
937
- R"""("foo")""",
938
- },
939
- // Failing strings
940
- {
941
- R"""(foo)""",
942
- R"""("bar")""",
943
- }
944
- );
945
-
946
- test_schema(
947
- "non-string const",
948
- // Schema
949
- R"""({
950
- "const": true
951
- })""",
952
- // Passing strings
953
- {
954
- R"""(true)""",
955
- },
956
- // Failing strings
957
- {
958
- R"""()""",
959
- R"""(foo)""",
960
- R"""("true")""",
961
- }
962
- );
963
-
964
- test_schema(
965
- "non-string const",
966
- // Schema
967
- R"""({
968
- "enum": ["red", "amber", "green", null, 42, ["foo"]]
969
- })""",
970
- // Passing strings
971
- {
972
- R"""("red")""",
973
- R"""(null)""",
974
- R"""(42)""",
975
- R"""(["foo"])""",
976
- },
977
- // Failing strings
978
- {
979
- R"""()""",
980
- R"""(420)""",
981
- R"""(true)""",
982
- R"""(foo)""",
983
- }
984
- );
985
-
986
- test_schema(
987
- "simple pattern",
988
- // Schema
989
- R"""({
990
- "pattern": "^[a-zA-Z0-9_-]*$"
991
- })""",
992
- // Passing strings
993
- {
994
- R"""("")""",
995
- R"""("He_llo-12")""",
996
- },
997
- // Failing strings
998
- {
999
- R"""("!")""",
1000
- R"""("Hello World")""",
1001
- }
1002
- );
1003
-
1004
- test_schema(
1005
- "pattern with escapes",
1006
- // Schema
1007
- R"""({
1008
- "pattern": "^a\\^\\$\\.\\[\\]\\(\\)\\|\\{\\}\\*\\+\\?b$"
1009
- })""",
1010
- // Passing strings
1011
- {
1012
- R"""("a^$.[]()|{}*+?b")""",
1013
- },
1014
- // Failing strings
1015
- {
1016
- R"""("ab")""",
1017
- }
1018
- );
1019
-
1020
- test_schema(
1021
- "",
1022
- // Schema
1023
- R"""(
1024
- {
1025
- "type": ["array", "null"],
1026
- "items": { "type": "string" }
1027
- }
1028
- )""",
1029
- // Passing strings
1030
- {
1031
- "null",
1032
- "[]",
1033
- "[\"123\"]",
1034
- "[\"foo\", \"bar\"]",
1035
- },
1036
- // Failing strings
1037
- {
1038
- "",
1039
- "[123]",
1040
- "\"foo\"",
1041
- "[\"foo\", 42]",
1042
- }
1043
- );
1044
-
1045
- test_schema(
1046
- "min+max items",
1047
- // Schema
1048
- R"""({
1049
- "items": {
1050
- "type": ["number", "integer"]
1051
- },
1052
- "minItems": 3,
1053
- "maxItems": 5
1054
- })""",
1055
- // Passing strings
1056
- {
1057
- R"""([1, 2, 3])""",
1058
- R"""([1, 2, 3, 4])""",
1059
- R"""([1, 2, 3, 4, 5])""",
1060
- },
1061
- // Failing strings
1062
- {
1063
- R"""([1, 2])""",
1064
- R"""([1, 2, 3, 4, 5, 6])""",
1065
- R"""(1)""",
1066
- }
1067
- );
1068
-
1069
- // Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties)
1070
- test_schema(
1071
- "object properties",
1072
- // Schema
1073
- R"""({
1074
- "type": "object",
1075
- "properties": {
1076
- "number": { "type": "number" },
1077
- "street_name": { "type": "string" },
1078
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
1079
- }
1080
- })""",
1081
- // Passing strings
1082
- {
1083
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue"})""",
1084
- // "By default, leaving out properties is valid"
1085
- R"""({ "street_name": "Pennsylvania" })""",
1086
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
1087
- // "By extension, even an empty object is valid"
1088
- R"""({})""",
1089
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
1090
- },
1091
- // Failing strings
1092
- {
1093
- // Change datatype from number to string
1094
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
1095
- // Reorder properties
1096
- R"""({ "street_name": "Pennsylvania", "number": 1600 })""",
1097
- // Reorder properties
1098
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
1099
- // "Additional properties default to false for generation, even though the spec says true.
1100
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue", "direction":"NW"})""",
1101
-
1102
- }
1103
- );
1104
-
1105
- test_schema(
1106
- "additional properties can't override other properties",
1107
- R"""({
1108
- "properties": {
1109
- "a": {"type": "integer"},
1110
- "b": {"type": "integer"}
1111
- },
1112
- "additionalProperties": true
1113
- })""",
1114
- // Passing strings
1115
- {
1116
- R"""({"a": 42})""",
1117
- R"""({"c": ""})""",
1118
- R"""({"a": 42, "c": ""})""",
1119
- R"""({"a_": ""})""",
1120
- },
1121
- // Failing strings
1122
- {
1123
- R"""()""",
1124
- R"""({"a": ""})""",
1125
- R"""({"a": "", "b": ""})""",
1126
- }
1127
- );
1128
-
1129
- // Properties (from: https://json-schema.org/understanding-json-schema/reference/object#properties)
1130
- test_schema(
1131
- "object properties, additionalProperties: true",
1132
- // Schema
1133
- R"""({
1134
- "type": "object",
1135
- "properties": {
1136
- "number": { "type": "number" },
1137
- "street_name": { "type": "string" },
1138
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
1139
- },
1140
- "additionalProperties": true
1141
- })""",
1142
- // Passing strings
1143
- {
1144
- // "By extension, even an empty object is valid"
1145
- R"""({})""",
1146
- R"""({"number":1600,"street_name":"Pennsylvania","street_type":"Avenue"})""",
1147
- // "By default, leaving out properties is valid"
1148
- R"""({ "street_name": "Pennsylvania" })""",
1149
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
1150
- // "By default, providing additional properties is valid"
1151
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue", "direction":"NW"})""",
1152
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
1153
- },
1154
- // Failing strings
1155
- {
1156
- // Change datatype from number to string
1157
- R"""({ "number": "1600", "street_name": "Pennsylvania", "street_type":"Avenue"})""",
1158
- // Reorder properties
1159
- R"""({ "street_name": "Pennsylvania", "number": 1600, "street_type":"Avenue"})""",
1160
- }
1161
- );
1162
-
1163
- // Additional properties: false
1164
- test_schema(
1165
- "required + optional props each in original order",
1166
- // Schema
1167
- R"""({
1168
- "type": "object",
1169
- "properties": {
1170
- "number": { "type": "number" },
1171
- "street_name": { "type": "string" },
1172
- "street_type": { "enum": ["Street", "Avenue", "Boulevard"] }
1173
- },
1174
- "additionalProperties": false
1175
- })""",
1176
- // Passing strings
1177
- {
1178
- R"""({ "street_name": "Pennsylvania" })""",
1179
- R"""({ "number": 1600, "street_type":"Avenue"})""",
1180
- R"""({ "number": 1600, "street_name": "Pennsylvania" })""",
1181
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type":"Avenue"})""",
1182
- // Spaces are permitted around enum values
1183
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue" })""",
1184
- },
1185
- // Failing strings
1186
- {
1187
- // Reorder properties
1188
- R"""({ "street_type": "Avenue", "number": 1600 })""",
1189
- // Add "direction"
1190
- R"""({ "number": 1600, "street_name": "Pennsylvania", "street_type": "Avenue", "direction": "NW" })""",
1191
- }
1192
- );
1193
-
1194
- test_schema(
1195
- "required + optional props each in original order",
1196
- // Schema
1197
- R"""({
1198
- "properties": {
1199
- "b": {"type": "string"},
1200
- "a": {"type": "string"},
1201
- "d": {"type": "string"},
1202
- "c": {"type": "string"}
1203
- },
1204
- "required": ["a", "b"],
1205
- "additionalProperties": false
1206
- })""",
1207
- // Passing strings
1208
- {
1209
- R"""({"b": "foo", "a": "bar"})""",
1210
- R"""({"b":"foo","a":"bar","d":"qux"})""",
1211
- R"""({"b":"foo", "a":"bar", "d":"qux", "c":"baz"})""",
1212
- },
1213
- // Failing strings
1214
- {
1215
- R"""({"a": "foo", "b": "bar"})""",
1216
- R"""({"b": "bar"})""",
1217
- R"""({"a": "foo", "c": "baz"})""",
1218
- R"""({"a":"foo", "b":"bar", "c":"baz", "d":"qux"})""",
1219
- }
1220
- );
1221
-
1222
- // NOTE: Example from https://json-schema.org/learn/getting-started-step-by-step#define-required-properties
1223
- test_schema(
1224
- "required props",
1225
- // Schema
1226
- R"""({
1227
- "$schema": "https://json-schema.org/draft/2020-12/schema",
1228
- "$id": "https://example.com/product.schema.json",
1229
- "title": "Product",
1230
- "description": "A product from Acme's catalog",
1231
- "type": "object",
1232
- "properties": {
1233
- "productId": {
1234
- "description": "The unique identifier for a product",
1235
- "type": "integer"
1236
- },
1237
- "productName": {
1238
- "description": "Name of the product",
1239
- "type": "string"
1240
- },
1241
- "price": {
1242
- "description": "The price of the product",
1243
- "type": "number",
1244
- "exclusiveMinimum": 0
1245
- },
1246
- "tags": {
1247
- "description": "Tags for the product",
1248
- "type": "array",
1249
- "items": {
1250
- "type": "string"
1251
- },
1252
- "minItems": 1,
1253
- "uniqueItems": true
1254
- },
1255
- "dimensions": {
1256
- "type": "object",
1257
- "properties": {
1258
- "length": {
1259
- "type": "number"
1260
- },
1261
- "width": {
1262
- "type": "number"
1263
- },
1264
- "height": {
1265
- "type": "number"
1266
- }
1267
- },
1268
- "required": [ "length", "width", "height" ]
1269
- }
1270
- },
1271
- "required": [ "productId", "productName", "price" ]
1272
- })""",
1273
- // Passing strings
1274
- {
1275
- R"""({"productId": 1, "productName": "A green door", "price": 12.50})""",
1276
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"]})""",
1277
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green"], "dimensions": {"length": 785, "width": 250.5, "height": -0.359}})""",
1278
- },
1279
- // Failing strings
1280
- {
1281
- R"""({})""", // Missing all required properties
1282
- R"""({"productName": "A green door", "price": 12.50, "productId": 1})""", // Out of order properties
1283
- // TODO: The following line should fail, but currently it passes. `exclusiveMinimum` is not supported, as it would likely be too difficult to implement.
1284
- // Perhaps special checks for minimum and maximum values of 0 could be added (since that's relatively easy to do with grammars), but anything else would likely be too complex.
1285
- // R"""({"productId": 1, "productName": "A green door", "price": -12.50})""",
1286
- R"""({"productId": 1, "productName": "A green door"})""", // Missing required property (price)
1287
- R"""({"productName": "A green door", "price": 12.50})""", // Missing required property (productId)
1288
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": []})""", // tags is empty, but minItems is 1
1289
- R"""({"productId": 1, "productName": "A green door", "price": 12.50, "dimensions": {"length": 785, "width": 250.5, "height": -0.359}, "tags": ["home", "green"]})""", // Tags and dimensions are out of order
1290
- // TODO: The following line should fail, but currently it passes. `uniqueItems` is not supported, as it would likely be too difficult to implement.
1291
- // R"""({"productId": 1, "productName": "A green door", "price": 12.50, "tags": ["home", "green", "home"]})""",
1292
- }
1293
- );
1294
- }
1295
-
1296
- int main() {
1297
- fprintf(stdout, "Running grammar integration tests...\n");
1298
- test_simple_grammar();
1299
- test_complex_grammar();
1300
- test_special_chars();
1301
- test_quantifiers();
1302
- test_failure_missing_root();
1303
- test_failure_missing_reference();
1304
- test_failure_left_recursion();
1305
- test_json_schema();
1306
- fprintf(stdout, "All tests passed.\n");
1307
- return 0;
1308
- }