cactus-react-native 0.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 (272) hide show
  1. package/README.md +230 -0
  2. package/android/build.gradle +104 -0
  3. package/android/gradle.properties +5 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/CMakeLists.txt +104 -0
  6. package/android/src/main/java/com/cactus/Cactus.java +646 -0
  7. package/android/src/main/java/com/cactus/CactusPackage.java +48 -0
  8. package/android/src/main/java/com/cactus/LlamaContext.java +579 -0
  9. package/android/src/main/jni-utils.h +100 -0
  10. package/android/src/main/jni.cpp +1254 -0
  11. package/android/src/main/jniLibs/arm64-v8a/libcactus.so +0 -0
  12. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8.so +0 -0
  13. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2.so +0 -0
  14. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod.so +0 -0
  15. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_dotprod_i8mm.so +0 -0
  16. package/android/src/main/jniLibs/arm64-v8a/libcactus_v8_2_i8mm.so +0 -0
  17. package/android/src/main/jniLibs/x86_64/libcactus.so +0 -0
  18. package/android/src/main/jniLibs/x86_64/libcactus_x86_64.so +0 -0
  19. package/android/src/newarch/java/com/cactus/CactusModule.java +124 -0
  20. package/android/src/oldarch/java/com/cactus/CactusModule.java +125 -0
  21. package/cactus-react-native.podspec +45 -0
  22. package/ios/CMakeLists.txt +109 -0
  23. package/ios/Cactus.h +6 -0
  24. package/ios/Cactus.mm +405 -0
  25. package/ios/CactusContext.h +57 -0
  26. package/ios/CactusContext.mm +835 -0
  27. package/ios/cactus.xcframework/info.plist +74 -0
  28. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/cactus.h +133 -0
  29. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/chat.h +143 -0
  30. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/common.h +683 -0
  31. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-alloc.h +76 -0
  32. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  33. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-backend.h +354 -0
  34. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-common.h +1851 -0
  35. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpp.h +39 -0
  36. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  37. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  38. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  39. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  40. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-cpu.h +138 -0
  41. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-impl.h +567 -0
  42. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  43. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-metal.h +66 -0
  44. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-opt.h +216 -0
  45. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-quants.h +100 -0
  46. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml-threading.h +14 -0
  47. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/ggml.h +2221 -0
  48. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/gguf.h +202 -0
  49. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  50. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/json.hpp +24766 -0
  51. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-adapter.h +76 -0
  52. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-arch.h +421 -0
  53. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-batch.h +88 -0
  54. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-chat.h +53 -0
  55. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-context.h +265 -0
  56. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cparams.h +38 -0
  57. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-cpp.h +30 -0
  58. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-grammar.h +173 -0
  59. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-graph.h +574 -0
  60. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-hparams.h +148 -0
  61. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-impl.h +61 -0
  62. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-io.h +35 -0
  63. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-kv-cache.h +287 -0
  64. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-memory.h +21 -0
  65. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-mmap.h +68 -0
  66. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model-loader.h +167 -0
  67. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-model.h +403 -0
  68. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-sampling.h +32 -0
  69. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama-vocab.h +125 -0
  70. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/llama.h +1416 -0
  71. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/log.h +103 -0
  72. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  73. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/minja/minja.hpp +2915 -0
  74. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sampling.h +107 -0
  75. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/sgemm.h +14 -0
  76. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode-data.h +20 -0
  77. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Headers/unicode.h +66 -0
  78. package/ios/cactus.xcframework/ios-arm64/cactus.framework/Info.plist +0 -0
  79. package/ios/cactus.xcframework/ios-arm64/cactus.framework/cactus +0 -0
  80. package/ios/cactus.xcframework/ios-arm64/cactus.framework/ggml-llama.metallib +0 -0
  81. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +133 -0
  82. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +143 -0
  83. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/common.h +683 -0
  84. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +76 -0
  85. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  86. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +354 -0
  87. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +1851 -0
  88. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +39 -0
  89. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  90. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  91. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  92. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  93. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +138 -0
  94. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +567 -0
  95. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  96. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +66 -0
  97. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +216 -0
  98. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +100 -0
  99. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +14 -0
  100. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +2221 -0
  101. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +202 -0
  102. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  103. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +24766 -0
  104. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +76 -0
  105. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +421 -0
  106. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +88 -0
  107. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +53 -0
  108. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +265 -0
  109. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +38 -0
  110. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +30 -0
  111. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +173 -0
  112. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +574 -0
  113. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +148 -0
  114. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +61 -0
  115. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +35 -0
  116. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +287 -0
  117. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +21 -0
  118. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +68 -0
  119. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +167 -0
  120. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +403 -0
  121. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +32 -0
  122. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +125 -0
  123. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +1416 -0
  124. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/log.h +103 -0
  125. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  126. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +2915 -0
  127. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +107 -0
  128. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +14 -0
  129. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +20 -0
  130. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +66 -0
  131. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  132. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +101 -0
  133. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  134. package/ios/cactus.xcframework/ios-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  135. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/cactus.h +133 -0
  136. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/chat.h +143 -0
  137. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/common.h +683 -0
  138. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-alloc.h +76 -0
  139. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  140. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-backend.h +354 -0
  141. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-common.h +1851 -0
  142. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpp.h +39 -0
  143. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  144. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  145. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  146. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  147. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-cpu.h +138 -0
  148. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-impl.h +567 -0
  149. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  150. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-metal.h +66 -0
  151. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-opt.h +216 -0
  152. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-quants.h +100 -0
  153. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml-threading.h +14 -0
  154. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/ggml.h +2221 -0
  155. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/gguf.h +202 -0
  156. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  157. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/json.hpp +24766 -0
  158. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-adapter.h +76 -0
  159. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-arch.h +421 -0
  160. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-batch.h +88 -0
  161. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-chat.h +53 -0
  162. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-context.h +265 -0
  163. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cparams.h +38 -0
  164. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-cpp.h +30 -0
  165. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-grammar.h +173 -0
  166. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-graph.h +574 -0
  167. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-hparams.h +148 -0
  168. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-impl.h +61 -0
  169. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-io.h +35 -0
  170. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-kv-cache.h +287 -0
  171. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-memory.h +21 -0
  172. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-mmap.h +68 -0
  173. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model-loader.h +167 -0
  174. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-model.h +403 -0
  175. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-sampling.h +32 -0
  176. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama-vocab.h +125 -0
  177. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/llama.h +1416 -0
  178. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/log.h +103 -0
  179. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  180. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/minja/minja.hpp +2915 -0
  181. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sampling.h +107 -0
  182. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/sgemm.h +14 -0
  183. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode-data.h +20 -0
  184. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Headers/unicode.h +66 -0
  185. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/Info.plist +0 -0
  186. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/cactus +0 -0
  187. package/ios/cactus.xcframework/tvos-arm64/cactus.framework/ggml-llama.metallib +0 -0
  188. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/cactus.h +133 -0
  189. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/chat.h +143 -0
  190. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/common.h +683 -0
  191. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-alloc.h +76 -0
  192. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend-impl.h +255 -0
  193. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-backend.h +354 -0
  194. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-common.h +1851 -0
  195. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpp.h +39 -0
  196. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-aarch64.h +8 -0
  197. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-impl.h +531 -0
  198. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-quants.h +63 -0
  199. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu-traits.h +38 -0
  200. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-cpu.h +138 -0
  201. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-impl.h +567 -0
  202. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal-impl.h +530 -0
  203. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-metal.h +66 -0
  204. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-opt.h +216 -0
  205. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-quants.h +100 -0
  206. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml-threading.h +14 -0
  207. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/ggml.h +2221 -0
  208. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/gguf.h +202 -0
  209. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json-schema-to-grammar.h +21 -0
  210. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/json.hpp +24766 -0
  211. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-adapter.h +76 -0
  212. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-arch.h +421 -0
  213. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-batch.h +88 -0
  214. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-chat.h +53 -0
  215. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-context.h +265 -0
  216. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cparams.h +38 -0
  217. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-cpp.h +30 -0
  218. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-grammar.h +173 -0
  219. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-graph.h +574 -0
  220. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-hparams.h +148 -0
  221. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-impl.h +61 -0
  222. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-io.h +35 -0
  223. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-kv-cache.h +287 -0
  224. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-memory.h +21 -0
  225. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-mmap.h +68 -0
  226. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model-loader.h +167 -0
  227. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-model.h +403 -0
  228. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-sampling.h +32 -0
  229. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama-vocab.h +125 -0
  230. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/llama.h +1416 -0
  231. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/log.h +103 -0
  232. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/chat-template.hpp +529 -0
  233. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/minja/minja.hpp +2915 -0
  234. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sampling.h +107 -0
  235. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/sgemm.h +14 -0
  236. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode-data.h +20 -0
  237. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Headers/unicode.h +66 -0
  238. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/Info.plist +0 -0
  239. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/_CodeSignature/CodeResources +101 -0
  240. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/cactus +0 -0
  241. package/ios/cactus.xcframework/tvos-arm64_x86_64-simulator/cactus.framework/ggml-llama-sim.metallib +0 -0
  242. package/lib/commonjs/NativeCactus.js +9 -0
  243. package/lib/commonjs/NativeCactus.js.map +1 -0
  244. package/lib/commonjs/chat.js +37 -0
  245. package/lib/commonjs/chat.js.map +1 -0
  246. package/lib/commonjs/grammar.js +560 -0
  247. package/lib/commonjs/grammar.js.map +1 -0
  248. package/lib/commonjs/index.js +300 -0
  249. package/lib/commonjs/index.js.map +1 -0
  250. package/lib/commonjs/package.json +1 -0
  251. package/lib/module/NativeCactus.js +5 -0
  252. package/lib/module/NativeCactus.js.map +1 -0
  253. package/lib/module/chat.js +33 -0
  254. package/lib/module/chat.js.map +1 -0
  255. package/lib/module/grammar.js +553 -0
  256. package/lib/module/grammar.js.map +1 -0
  257. package/lib/module/index.js +277 -0
  258. package/lib/module/index.js.map +1 -0
  259. package/lib/module/package.json +1 -0
  260. package/lib/typescript/NativeCactus.d.ts +357 -0
  261. package/lib/typescript/NativeCactus.d.ts.map +1 -0
  262. package/lib/typescript/chat.d.ts +10 -0
  263. package/lib/typescript/chat.d.ts.map +1 -0
  264. package/lib/typescript/grammar.d.ts +37 -0
  265. package/lib/typescript/grammar.d.ts.map +1 -0
  266. package/lib/typescript/index.d.ts +96 -0
  267. package/lib/typescript/index.d.ts.map +1 -0
  268. package/package.json +223 -0
  269. package/src/NativeCactus.ts +418 -0
  270. package/src/chat.ts +44 -0
  271. package/src/grammar.ts +854 -0
  272. package/src/index.ts +482 -0
@@ -0,0 +1,277 @@
1
+ "use strict";
2
+
3
+ import { NativeEventEmitter, DeviceEventEmitter, Platform } from 'react-native';
4
+ import Cactus from './NativeCactus';
5
+ import { SchemaGrammarConverter, convertJsonSchemaToGrammar } from './grammar';
6
+ import { formatChat } from './chat';
7
+ export { SchemaGrammarConverter, convertJsonSchemaToGrammar };
8
+ const EVENT_ON_INIT_CONTEXT_PROGRESS = '@Cactus_onInitContextProgress';
9
+ const EVENT_ON_TOKEN = '@Cactus_onToken';
10
+ const EVENT_ON_NATIVE_LOG = '@Cactus_onNativeLog';
11
+ let EventEmitter;
12
+ if (Platform.OS === 'ios') {
13
+ // @ts-ignore
14
+ EventEmitter = new NativeEventEmitter(Cactus);
15
+ }
16
+ if (Platform.OS === 'android') {
17
+ EventEmitter = DeviceEventEmitter;
18
+ }
19
+ const logListeners = [];
20
+
21
+ // @ts-ignore
22
+ if (EventEmitter) {
23
+ EventEmitter.addListener(EVENT_ON_NATIVE_LOG, evt => {
24
+ logListeners.forEach(listener => listener(evt.level, evt.text));
25
+ });
26
+ // Trigger unset to use default log callback
27
+ Cactus?.toggleNativeLog?.(false)?.catch?.(() => {});
28
+ }
29
+ const getJsonSchema = responseFormat => {
30
+ if (responseFormat?.type === 'json_schema') {
31
+ return responseFormat.json_schema?.schema;
32
+ }
33
+ if (responseFormat?.type === 'json_object') {
34
+ return responseFormat.schema || {};
35
+ }
36
+ return null;
37
+ };
38
+ export class LlamaContext {
39
+ gpu = false;
40
+ reasonNoGPU = '';
41
+ constructor({
42
+ contextId,
43
+ gpu,
44
+ reasonNoGPU,
45
+ model
46
+ }) {
47
+ this.id = contextId;
48
+ this.gpu = gpu;
49
+ this.reasonNoGPU = reasonNoGPU;
50
+ this.model = model;
51
+ }
52
+
53
+ /**
54
+ * Load cached prompt & completion state from a file.
55
+ */
56
+ async loadSession(filepath) {
57
+ let path = filepath;
58
+ if (path.startsWith('file://')) path = path.slice(7);
59
+ return Cactus.loadSession(this.id, path);
60
+ }
61
+
62
+ /**
63
+ * Save current cached prompt & completion state to a file.
64
+ */
65
+ async saveSession(filepath, options) {
66
+ return Cactus.saveSession(this.id, filepath, options?.tokenSize || -1);
67
+ }
68
+ isLlamaChatSupported() {
69
+ return !!this.model.chatTemplates.llamaChat;
70
+ }
71
+ isJinjaSupported() {
72
+ const {
73
+ minja
74
+ } = this.model.chatTemplates;
75
+ return !!minja?.toolUse || !!minja?.default;
76
+ }
77
+ async getFormattedChat(messages, template, params) {
78
+ const chat = formatChat(messages);
79
+ const useJinja = this.isJinjaSupported() && params?.jinja;
80
+ let tmpl = this.isLlamaChatSupported() || useJinja ? undefined : 'chatml';
81
+ if (template) tmpl = template; // Force replace if provided
82
+ const jsonSchema = getJsonSchema(params?.response_format);
83
+ return Cactus.getFormattedChat(this.id, JSON.stringify(chat), tmpl, {
84
+ jinja: useJinja,
85
+ json_schema: jsonSchema ? JSON.stringify(jsonSchema) : undefined,
86
+ tools: params?.tools ? JSON.stringify(params.tools) : undefined,
87
+ parallel_tool_calls: params?.parallel_tool_calls ? JSON.stringify(params.parallel_tool_calls) : undefined,
88
+ tool_choice: params?.tool_choice
89
+ });
90
+ }
91
+ async completion(params, callback) {
92
+ const nativeParams = {
93
+ ...params,
94
+ prompt: params.prompt || '',
95
+ emit_partial_completion: !!callback
96
+ };
97
+ if (params.messages) {
98
+ // messages always win
99
+ const formattedResult = await this.getFormattedChat(params.messages, params.chat_template || params.chatTemplate, {
100
+ jinja: params.jinja,
101
+ tools: params.tools,
102
+ parallel_tool_calls: params.parallel_tool_calls,
103
+ tool_choice: params.tool_choice
104
+ });
105
+ if (typeof formattedResult === 'string') {
106
+ nativeParams.prompt = formattedResult || '';
107
+ } else {
108
+ nativeParams.prompt = formattedResult.prompt || '';
109
+ if (typeof formattedResult.chat_format === 'number') nativeParams.chat_format = formattedResult.chat_format;
110
+ if (formattedResult.grammar) nativeParams.grammar = formattedResult.grammar;
111
+ if (typeof formattedResult.grammar_lazy === 'boolean') nativeParams.grammar_lazy = formattedResult.grammar_lazy;
112
+ if (formattedResult.grammar_triggers) nativeParams.grammar_triggers = formattedResult.grammar_triggers;
113
+ if (formattedResult.preserved_tokens) nativeParams.preserved_tokens = formattedResult.preserved_tokens;
114
+ if (formattedResult.additional_stops) {
115
+ if (!nativeParams.stop) nativeParams.stop = [];
116
+ nativeParams.stop.push(...formattedResult.additional_stops);
117
+ }
118
+ }
119
+ } else {
120
+ nativeParams.prompt = params.prompt || '';
121
+ }
122
+ if (nativeParams.response_format && !nativeParams.grammar) {
123
+ const jsonSchema = getJsonSchema(params.response_format);
124
+ if (jsonSchema) nativeParams.json_schema = JSON.stringify(jsonSchema);
125
+ }
126
+ let tokenListener = callback && EventEmitter.addListener(EVENT_ON_TOKEN, evt => {
127
+ const {
128
+ contextId,
129
+ tokenResult
130
+ } = evt;
131
+ if (contextId !== this.id) return;
132
+ callback(tokenResult);
133
+ });
134
+ if (!nativeParams.prompt) throw new Error('Prompt is required');
135
+ const promise = Cactus.completion(this.id, nativeParams);
136
+ return promise.then(completionResult => {
137
+ tokenListener?.remove();
138
+ tokenListener = null;
139
+ return completionResult;
140
+ }).catch(err => {
141
+ tokenListener?.remove();
142
+ tokenListener = null;
143
+ throw err;
144
+ });
145
+ }
146
+ stopCompletion() {
147
+ return Cactus.stopCompletion(this.id);
148
+ }
149
+ tokenize(text) {
150
+ return Cactus.tokenize(this.id, text);
151
+ }
152
+ detokenize(tokens) {
153
+ return Cactus.detokenize(this.id, tokens);
154
+ }
155
+ embedding(text, params) {
156
+ return Cactus.embedding(this.id, text, params || {});
157
+ }
158
+ async bench(pp, tg, pl, nr) {
159
+ const result = await Cactus.bench(this.id, pp, tg, pl, nr);
160
+ const [modelDesc, modelSize, modelNParams, ppAvg, ppStd, tgAvg, tgStd] = JSON.parse(result);
161
+ return {
162
+ modelDesc,
163
+ modelSize,
164
+ modelNParams,
165
+ ppAvg,
166
+ ppStd,
167
+ tgAvg,
168
+ tgStd
169
+ };
170
+ }
171
+ async applyLoraAdapters(loraList) {
172
+ let loraAdapters = [];
173
+ if (loraList) loraAdapters = loraList.map(l => ({
174
+ path: l.path.replace(/file:\/\//, ''),
175
+ scaled: l.scaled
176
+ }));
177
+ return Cactus.applyLoraAdapters(this.id, loraAdapters);
178
+ }
179
+ async removeLoraAdapters() {
180
+ return Cactus.removeLoraAdapters(this.id);
181
+ }
182
+ async getLoadedLoraAdapters() {
183
+ return Cactus.getLoadedLoraAdapters(this.id);
184
+ }
185
+ async release() {
186
+ return Cactus.releaseContext(this.id);
187
+ }
188
+ }
189
+ export async function toggleNativeLog(enabled) {
190
+ return Cactus.toggleNativeLog(enabled);
191
+ }
192
+ export function addNativeLogListener(listener) {
193
+ logListeners.push(listener);
194
+ return {
195
+ remove: () => {
196
+ logListeners.splice(logListeners.indexOf(listener), 1);
197
+ }
198
+ };
199
+ }
200
+ export async function setContextLimit(limit) {
201
+ return Cactus.setContextLimit(limit);
202
+ }
203
+ let contextIdCounter = 0;
204
+ const contextIdRandom = () => process.env.NODE_ENV === 'test' ? 0 : Math.floor(Math.random() * 100000);
205
+ const modelInfoSkip = [
206
+ // Large fields
207
+ 'tokenizer.ggml.tokens', 'tokenizer.ggml.token_type', 'tokenizer.ggml.merges', 'tokenizer.ggml.scores'];
208
+ export async function loadLlamaModelInfo(model) {
209
+ let path = model;
210
+ if (path.startsWith('file://')) path = path.slice(7);
211
+ return Cactus.modelInfo(path, modelInfoSkip);
212
+ }
213
+ const poolTypeMap = {
214
+ // -1 is unspecified as undefined
215
+ none: 0,
216
+ mean: 1,
217
+ cls: 2,
218
+ last: 3,
219
+ rank: 4
220
+ };
221
+ export async function initLlama({
222
+ model,
223
+ is_model_asset: isModelAsset,
224
+ pooling_type: poolingType,
225
+ lora,
226
+ lora_list: loraList,
227
+ ...rest
228
+ }, onProgress) {
229
+ let path = model;
230
+ if (path.startsWith('file://')) path = path.slice(7);
231
+ let loraPath = lora;
232
+ if (loraPath?.startsWith('file://')) loraPath = loraPath.slice(7);
233
+ let loraAdapters = [];
234
+ if (loraList) loraAdapters = loraList.map(l => ({
235
+ path: l.path.replace(/file:\/\//, ''),
236
+ scaled: l.scaled
237
+ }));
238
+ const contextId = contextIdCounter + contextIdRandom();
239
+ contextIdCounter += 1;
240
+ let removeProgressListener = null;
241
+ if (onProgress) {
242
+ removeProgressListener = EventEmitter.addListener(EVENT_ON_INIT_CONTEXT_PROGRESS, evt => {
243
+ if (evt.contextId !== contextId) return;
244
+ onProgress(evt.progress);
245
+ });
246
+ }
247
+ const poolType = poolTypeMap[poolingType];
248
+ const {
249
+ gpu,
250
+ reasonNoGPU,
251
+ model: modelDetails,
252
+ androidLib
253
+ } = await Cactus.initContext(contextId, {
254
+ model: path,
255
+ is_model_asset: !!isModelAsset,
256
+ use_progress_callback: !!onProgress,
257
+ pooling_type: poolType,
258
+ lora: loraPath,
259
+ lora_list: loraAdapters,
260
+ ...rest
261
+ }).catch(err => {
262
+ removeProgressListener?.remove();
263
+ throw err;
264
+ });
265
+ removeProgressListener?.remove();
266
+ return new LlamaContext({
267
+ contextId,
268
+ gpu,
269
+ reasonNoGPU,
270
+ model: modelDetails,
271
+ androidLib
272
+ });
273
+ }
274
+ export async function releaseAllLlama() {
275
+ return Cactus.releaseAllContexts();
276
+ }
277
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","DeviceEventEmitter","Platform","Cactus","SchemaGrammarConverter","convertJsonSchemaToGrammar","formatChat","EVENT_ON_INIT_CONTEXT_PROGRESS","EVENT_ON_TOKEN","EVENT_ON_NATIVE_LOG","EventEmitter","OS","logListeners","addListener","evt","forEach","listener","level","text","toggleNativeLog","catch","getJsonSchema","responseFormat","type","json_schema","schema","LlamaContext","gpu","reasonNoGPU","constructor","contextId","model","id","loadSession","filepath","path","startsWith","slice","saveSession","options","tokenSize","isLlamaChatSupported","chatTemplates","llamaChat","isJinjaSupported","minja","toolUse","default","getFormattedChat","messages","template","params","chat","useJinja","jinja","tmpl","undefined","jsonSchema","response_format","JSON","stringify","tools","parallel_tool_calls","tool_choice","completion","callback","nativeParams","prompt","emit_partial_completion","formattedResult","chat_template","chatTemplate","chat_format","grammar","grammar_lazy","grammar_triggers","preserved_tokens","additional_stops","stop","push","tokenListener","tokenResult","Error","promise","then","completionResult","remove","err","stopCompletion","tokenize","detokenize","tokens","embedding","bench","pp","tg","pl","nr","result","modelDesc","modelSize","modelNParams","ppAvg","ppStd","tgAvg","tgStd","parse","applyLoraAdapters","loraList","loraAdapters","map","l","replace","scaled","removeLoraAdapters","getLoadedLoraAdapters","release","releaseContext","enabled","addNativeLogListener","splice","indexOf","setContextLimit","limit","contextIdCounter","contextIdRandom","process","env","NODE_ENV","Math","floor","random","modelInfoSkip","loadLlamaModelInfo","modelInfo","poolTypeMap","none","mean","cls","last","rank","initLlama","is_model_asset","isModelAsset","pooling_type","poolingType","lora","lora_list","rest","onProgress","loraPath","removeProgressListener","progress","poolType","modelDetails","androidLib","initContext","use_progress_callback","releaseAllLlama","releaseAllContexts"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,kBAAkB,EAAEC,kBAAkB,EAAEC,QAAQ,QAAQ,cAAc;AAE/E,OAAOC,MAAM,MAAM,gBAAgB;AAmBnC,SAASC,sBAAsB,EAAEC,0BAA0B,QAAQ,WAAW;AAE9E,SAASC,UAAU,QAAQ,QAAQ;AAuBnC,SAASF,sBAAsB,EAAEC,0BAA0B;AAE3D,MAAME,8BAA8B,GAAG,+BAA+B;AACtE,MAAMC,cAAc,GAAG,iBAAiB;AACxC,MAAMC,mBAAmB,GAAG,qBAAqB;AAEjD,IAAIC,YAA2D;AAC/D,IAAIR,QAAQ,CAACS,EAAE,KAAK,KAAK,EAAE;EACzB;EACAD,YAAY,GAAG,IAAIV,kBAAkB,CAACG,MAAM,CAAC;AAC/C;AACA,IAAID,QAAQ,CAACS,EAAE,KAAK,SAAS,EAAE;EAC7BD,YAAY,GAAGT,kBAAkB;AACnC;AAEA,MAAMW,YAA0D,GAAG,EAAE;;AAErE;AACA,IAAIF,YAAY,EAAE;EAChBA,YAAY,CAACG,WAAW,CACtBJ,mBAAmB,EAClBK,GAAoC,IAAK;IACxCF,YAAY,CAACG,OAAO,CAAEC,QAAQ,IAAKA,QAAQ,CAACF,GAAG,CAACG,KAAK,EAAEH,GAAG,CAACI,IAAI,CAAC,CAAC;EACnE,CACF,CAAC;EACD;EACAf,MAAM,EAA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AIF,UAAU,EAAE;IACdE,sBAAsB,GAAG7I,YAAY,CAACG,WAAW,CAC/CN,8BAA8B,EAC7BO,GAA4C,IAAK;MAChD,IAAIA,GAAG,CAACgB,SAAS,KAAKA,SAAS,EAAE;MACjCuH,UAAU,CAACvI,GAAG,CAAC0I,QAAQ,CAAC;IAC1B,CACF,CAAC;EACH;EAEA,MAAMC,QAAQ,GAAGlB,WAAW,CAACU,WAAW,CAA6B;EACrE,MAAM;IACJtH,GAAG;IACHC,WAAW;IACXG,KAAK,EAAE2H,YAAY;IACnBC;EACF,CAAC,GAAG,MAAMxJ,MAAM,CAACyJ,WAAW,CAAC9H,SAAS,EAAE;IACtCC,KAAK,EAAEI,IAAI;IACX2G,cAAc,EAAE,CAAC,CAACC,YAAY;IAC9Bc,qBAAqB,EAAE,CAAC,CAACR,UAAU;IACnCL,YAAY,EAAES,QAAQ;IACtBP,IAAI,EAAEI,QAAQ;IACdH,SAAS,EAAEtC,YAAY;IACvB,GAAGuC;EACL,CAAC,CAAC,CAAChI,KAAK,CAAEmE,GAAQ,IAAK;IACrBgE,sBAAsB,EAAEjE,MAAM,CAAC,CAAC;IAChC,MAAMC,GAAG;EACX,CAAC,CAAC;EACFgE,sBAAsB,EAAEjE,MAAM,CAAC,CAAC;EAChC,OAAO,IAAI5D,YAAY,CAAC;IACtBI,SAAS;IACTH,GAAG;IACHC,WAAW;IACXG,KAAK,EAAE2H,YAAY;IACnBC;EACF,CAAC,CAAC;AACJ;AAEA,OAAO,eAAeG,eAAeA,CAAA,EAAkB;EACrD,OAAO3J,MAAM,CAAC4J,kBAAkB,CAAC,CAAC;AACpC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,357 @@
1
+ import type { TurboModule } from 'react-native';
2
+ export type NativeEmbeddingParams = {
3
+ embd_normalize?: number;
4
+ };
5
+ export type NativeContextParams = {
6
+ model: string;
7
+ /**
8
+ * Chat template to override the default one from the model.
9
+ */
10
+ chat_template?: string;
11
+ reasoning_format?: string;
12
+ is_model_asset?: boolean;
13
+ use_progress_callback?: boolean;
14
+ n_ctx?: number;
15
+ n_batch?: number;
16
+ n_ubatch?: number;
17
+ n_threads?: number;
18
+ /**
19
+ * Number of layers to store in VRAM (Currently only for iOS)
20
+ */
21
+ n_gpu_layers?: number;
22
+ /**
23
+ * Skip GPU devices (iOS only)
24
+ */
25
+ no_gpu_devices?: boolean;
26
+ /**
27
+ * Enable flash attention, only recommended in GPU device (Experimental in llama.cpp)
28
+ */
29
+ flash_attn?: boolean;
30
+ /**
31
+ * KV cache data type for the K (Experimental in llama.cpp)
32
+ */
33
+ cache_type_k?: string;
34
+ /**
35
+ * KV cache data type for the V (Experimental in llama.cpp)
36
+ */
37
+ cache_type_v?: string;
38
+ use_mlock?: boolean;
39
+ use_mmap?: boolean;
40
+ vocab_only?: boolean;
41
+ /**
42
+ * Single LoRA adapter path
43
+ */
44
+ lora?: string;
45
+ /**
46
+ * Single LoRA adapter scale
47
+ */
48
+ lora_scaled?: number;
49
+ /**
50
+ * LoRA adapter list
51
+ */
52
+ lora_list?: Array<{
53
+ path: string;
54
+ scaled?: number;
55
+ }>;
56
+ rope_freq_base?: number;
57
+ rope_freq_scale?: number;
58
+ pooling_type?: number;
59
+ embedding?: boolean;
60
+ embd_normalize?: number;
61
+ };
62
+ export type NativeCompletionParams = {
63
+ prompt: string;
64
+ n_threads?: number;
65
+ /**
66
+ * JSON schema for convert to grammar for structured JSON output.
67
+ * It will be override by grammar if both are set.
68
+ */
69
+ json_schema?: string;
70
+ /**
71
+ * Set grammar for grammar-based sampling. Default: no grammar
72
+ */
73
+ grammar?: string;
74
+ /**
75
+ * Lazy grammar sampling, trigger by grammar_triggers. Default: false
76
+ */
77
+ grammar_lazy?: boolean;
78
+ /**
79
+ * Lazy grammar triggers. Default: []
80
+ */
81
+ grammar_triggers?: Array<{
82
+ type: number;
83
+ value: string;
84
+ token: number;
85
+ }>;
86
+ preserved_tokens?: Array<string>;
87
+ chat_format?: number;
88
+ /**
89
+ * Specify a JSON array of stopping strings.
90
+ * These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`
91
+ */
92
+ stop?: Array<string>;
93
+ /**
94
+ * Set the maximum number of tokens to predict when generating text.
95
+ * **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.
96
+ * When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.
97
+ */
98
+ n_predict?: number;
99
+ /**
100
+ * If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.
101
+ * Note that for temperature < 0 the tokens are sampled greedily but token probabilities are still being calculated via a simple softmax of the logits without considering any other sampler settings.
102
+ * Default: `0`
103
+ */
104
+ n_probs?: number;
105
+ /**
106
+ * Limit the next token selection to the K most probable tokens. Default: `40`
107
+ */
108
+ top_k?: number;
109
+ /**
110
+ * Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`
111
+ */
112
+ top_p?: number;
113
+ /**
114
+ * The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`
115
+ */
116
+ min_p?: number;
117
+ /**
118
+ * Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.
119
+ */
120
+ xtc_probability?: number;
121
+ /**
122
+ * Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)
123
+ */
124
+ xtc_threshold?: number;
125
+ /**
126
+ * Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.
127
+ */
128
+ typical_p?: number;
129
+ /**
130
+ * Adjust the randomness of the generated text. Default: `0.8`
131
+ */
132
+ temperature?: number;
133
+ /**
134
+ * Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.
135
+ */
136
+ penalty_last_n?: number;
137
+ /**
138
+ * Control the repetition of token sequences in the generated text. Default: `1.0`
139
+ */
140
+ penalty_repeat?: number;
141
+ /**
142
+ * Repeat alpha frequency penalty. Default: `0.0`, which is disabled.
143
+ */
144
+ penalty_freq?: number;
145
+ /**
146
+ * Repeat alpha presence penalty. Default: `0.0`, which is disabled.
147
+ */
148
+ penalty_present?: number;
149
+ /**
150
+ * Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.
151
+ */
152
+ mirostat?: number;
153
+ /**
154
+ * Set the Mirostat target entropy, parameter tau. Default: `5.0`
155
+ */
156
+ mirostat_tau?: number;
157
+ /**
158
+ * Set the Mirostat learning rate, parameter eta. Default: `0.1`
159
+ */
160
+ mirostat_eta?: number;
161
+ /**
162
+ * Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.
163
+ */
164
+ dry_multiplier?: number;
165
+ /**
166
+ * Set the DRY repetition penalty base value. Default: `1.75`
167
+ */
168
+ dry_base?: number;
169
+ /**
170
+ * Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`
171
+ */
172
+ dry_allowed_length?: number;
173
+ /**
174
+ * How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.
175
+ */
176
+ dry_penalty_last_n?: number;
177
+ /**
178
+ * Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\n', ':', '"', '*']`
179
+ */
180
+ dry_sequence_breakers?: Array<string>;
181
+ /**
182
+ * Top n sigma sampling as described in academic paper "Top-nσ: Not All Logits Are You Need" https://arxiv.org/pdf/2411.07641. Default: `-1.0` (Disabled)
183
+ */
184
+ top_n_sigma?: number;
185
+ /**
186
+ * Ignore end of stream token and continue generating. Default: `false`
187
+ */
188
+ ignore_eos?: boolean;
189
+ /**
190
+ * Modify the likelihood of a token appearing in the generated text completion.
191
+ * For example, use `"logit_bias": [[15043,1.0]]` to increase the likelihood of the token 'Hello', or `"logit_bias": [[15043,-1.0]]` to decrease its likelihood.
192
+ * Setting the value to false, `"logit_bias": [[15043,false]]` ensures that the token `Hello` is never produced. The tokens can also be represented as strings,
193
+ * e.g.`[["Hello, World!",-0.5]]` will reduce the likelihood of all the individual tokens that represent the string `Hello, World!`, just like the `presence_penalty` does.
194
+ * Default: `[]`
195
+ */
196
+ logit_bias?: Array<Array<number>>;
197
+ /**
198
+ * Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.
199
+ */
200
+ seed?: number;
201
+ emit_partial_completion: boolean;
202
+ };
203
+ export type NativeCompletionTokenProbItem = {
204
+ tok_str: string;
205
+ prob: number;
206
+ };
207
+ export type NativeCompletionTokenProb = {
208
+ content: string;
209
+ probs: Array<NativeCompletionTokenProbItem>;
210
+ };
211
+ export type NativeCompletionResultTimings = {
212
+ prompt_n: number;
213
+ prompt_ms: number;
214
+ prompt_per_token_ms: number;
215
+ prompt_per_second: number;
216
+ predicted_n: number;
217
+ predicted_ms: number;
218
+ predicted_per_token_ms: number;
219
+ predicted_per_second: number;
220
+ };
221
+ export type NativeCompletionResult = {
222
+ /**
223
+ * Original text (Ignored reasoning_content / tool_calls)
224
+ */
225
+ text: string;
226
+ /**
227
+ * Reasoning content (parsed for reasoning model)
228
+ */
229
+ reasoning_content: string;
230
+ /**
231
+ * Tool calls
232
+ */
233
+ tool_calls: Array<{
234
+ type: 'function';
235
+ function: {
236
+ name: string;
237
+ arguments: string;
238
+ };
239
+ id?: string;
240
+ }>;
241
+ /**
242
+ * Content text (Filtered text by reasoning_content / tool_calls)
243
+ */
244
+ content: string;
245
+ tokens_predicted: number;
246
+ tokens_evaluated: number;
247
+ truncated: boolean;
248
+ stopped_eos: boolean;
249
+ stopped_word: string;
250
+ stopped_limit: number;
251
+ stopping_word: string;
252
+ tokens_cached: number;
253
+ timings: NativeCompletionResultTimings;
254
+ completion_probabilities?: Array<NativeCompletionTokenProb>;
255
+ };
256
+ export type NativeTokenizeResult = {
257
+ tokens: Array<number>;
258
+ };
259
+ export type NativeEmbeddingResult = {
260
+ embedding: Array<number>;
261
+ };
262
+ export type NativeLlamaContext = {
263
+ contextId: number;
264
+ model: {
265
+ desc: string;
266
+ size: number;
267
+ nEmbd: number;
268
+ nParams: number;
269
+ chatTemplates: {
270
+ llamaChat: boolean;
271
+ minja: {
272
+ default: boolean;
273
+ defaultCaps: {
274
+ tools: boolean;
275
+ toolCalls: boolean;
276
+ toolResponses: boolean;
277
+ systemRole: boolean;
278
+ parallelToolCalls: boolean;
279
+ toolCallId: boolean;
280
+ };
281
+ toolUse: boolean;
282
+ toolUseCaps: {
283
+ tools: boolean;
284
+ toolCalls: boolean;
285
+ toolResponses: boolean;
286
+ systemRole: boolean;
287
+ parallelToolCalls: boolean;
288
+ toolCallId: boolean;
289
+ };
290
+ };
291
+ };
292
+ metadata: Object;
293
+ isChatTemplateSupported: boolean;
294
+ };
295
+ /**
296
+ * Loaded library name for Android
297
+ */
298
+ androidLib?: string;
299
+ gpu: boolean;
300
+ reasonNoGPU: string;
301
+ };
302
+ export type NativeSessionLoadResult = {
303
+ tokens_loaded: number;
304
+ prompt: string;
305
+ };
306
+ export type NativeLlamaChatMessage = {
307
+ role: string;
308
+ content: string;
309
+ };
310
+ export type JinjaFormattedChatResult = {
311
+ prompt: string;
312
+ chat_format?: number;
313
+ grammar?: string;
314
+ grammar_lazy?: boolean;
315
+ grammar_triggers?: Array<{
316
+ type: number;
317
+ value: string;
318
+ token: number;
319
+ }>;
320
+ preserved_tokens?: Array<string>;
321
+ additional_stops?: Array<string>;
322
+ };
323
+ export interface Spec extends TurboModule {
324
+ toggleNativeLog(enabled: boolean): Promise<void>;
325
+ setContextLimit(limit: number): Promise<void>;
326
+ modelInfo(path: string, skip?: string[]): Promise<Object>;
327
+ initContext(contextId: number, params: NativeContextParams): Promise<NativeLlamaContext>;
328
+ getFormattedChat(contextId: number, messages: string, chatTemplate?: string, params?: {
329
+ jinja?: boolean;
330
+ json_schema?: string;
331
+ tools?: string;
332
+ parallel_tool_calls?: string;
333
+ tool_choice?: string;
334
+ }): Promise<JinjaFormattedChatResult | string>;
335
+ loadSession(contextId: number, filepath: string): Promise<NativeSessionLoadResult>;
336
+ saveSession(contextId: number, filepath: string, size: number): Promise<number>;
337
+ completion(contextId: number, params: NativeCompletionParams): Promise<NativeCompletionResult>;
338
+ stopCompletion(contextId: number): Promise<void>;
339
+ tokenize(contextId: number, text: string): Promise<NativeTokenizeResult>;
340
+ detokenize(contextId: number, tokens: number[]): Promise<string>;
341
+ embedding(contextId: number, text: string, params: NativeEmbeddingParams): Promise<NativeEmbeddingResult>;
342
+ bench(contextId: number, pp: number, tg: number, pl: number, nr: number): Promise<string>;
343
+ applyLoraAdapters(contextId: number, loraAdapters: Array<{
344
+ path: string;
345
+ scaled?: number;
346
+ }>): Promise<void>;
347
+ removeLoraAdapters(contextId: number): Promise<void>;
348
+ getLoadedLoraAdapters(contextId: number): Promise<Array<{
349
+ path: string;
350
+ scaled?: number;
351
+ }>>;
352
+ releaseContext(contextId: number): Promise<void>;
353
+ releaseAllContexts(): Promise<void>;
354
+ }
355
+ declare const _default: Spec;
356
+ export default _default;
357
+ //# sourceMappingURL=NativeCactus.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeCactus.d.ts","sourceRoot":"","sources":["../../src/NativeCactus.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAG/C,MAAM,MAAM,qBAAqB,GAAG;IAClC,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,MAAM,CAAA;IACb;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAA;IAE/B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,SAAS,CAAC,EAAE,MAAM,C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AAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,GACrD,OAAO,CAAC,IAAI,CAAC,CAAA;IAChB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACpD,qBAAqB,CACnB,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAA;IAEpD,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhD,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACpC;wBAEyD,IAAI;AAA9D,wBAA8D"}
@@ -0,0 +1,10 @@
1
+ import type { NativeLlamaChatMessage } from './NativeCactus';
2
+ export type CactusMessagePart = {
3
+ text?: string;
4
+ };
5
+ export type CactusOAICompatibleMessage = {
6
+ role: string;
7
+ content?: string | CactusMessagePart[] | any;
8
+ };
9
+ export declare function formatChat(messages: CactusOAICompatibleMessage[]): NativeLlamaChatMessage[];
10
+ //# sourceMappingURL=chat.d.ts.map