@runanywhere/llamacpp 0.16.0

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 (50) hide show
  1. package/RunAnywhereLlama.podspec +131 -0
  2. package/android/CMakeLists.txt +105 -0
  3. package/android/build.gradle +288 -0
  4. package/android/src/main/AndroidManifest.xml +3 -0
  5. package/android/src/main/cpp/cpp-adapter.cpp +14 -0
  6. package/android/src/main/java/com/margelo/nitro/runanywhere/llama/RunAnywhereLlamaPackage.kt +35 -0
  7. package/android/src/main/jniLibs/arm64-v8a/librac_backend_llamacpp.so +0 -0
  8. package/android/src/main/jniLibs/arm64-v8a/librac_backend_llamacpp_jni.so +0 -0
  9. package/android/src/main/jniLibs/arm64-v8a/librunanywhere_llamacpp.so +0 -0
  10. package/cpp/HybridRunAnywhereLlama.cpp +346 -0
  11. package/cpp/HybridRunAnywhereLlama.hpp +107 -0
  12. package/cpp/bridges/LLMBridge.cpp +209 -0
  13. package/cpp/bridges/LLMBridge.hpp +109 -0
  14. package/cpp/bridges/StructuredOutputBridge.cpp +151 -0
  15. package/cpp/bridges/StructuredOutputBridge.hpp +66 -0
  16. package/cpp/rac_llm_llamacpp.h +34 -0
  17. package/ios/.testlocal +0 -0
  18. package/ios/Frameworks/RABackendLLAMACPP.xcframework/Info.plist +44 -0
  19. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Headers/RABackendLLAMACPP.h +2 -0
  20. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Info.plist +11 -0
  21. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/Modules/module.modulemap +5 -0
  22. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64/RABackendLLAMACPP.framework/RABackendLLAMACPP +0 -0
  23. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Headers/RABackendLLAMACPP.h +2 -0
  24. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Info.plist +11 -0
  25. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/Modules/module.modulemap +5 -0
  26. package/ios/Frameworks/RABackendLLAMACPP.xcframework/ios-arm64_x86_64-simulator/RABackendLLAMACPP.framework/RABackendLLAMACPP +0 -0
  27. package/ios/LlamaCPPBackend.podspec +127 -0
  28. package/nitro.json +16 -0
  29. package/nitrogen/generated/.gitattributes +1 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/runanywhere/llama/runanywherellamaOnLoad.kt +35 -0
  31. package/nitrogen/generated/android/runanywherellama+autolinking.cmake +81 -0
  32. package/nitrogen/generated/android/runanywherellama+autolinking.gradle +27 -0
  33. package/nitrogen/generated/android/runanywherellamaOnLoad.cpp +44 -0
  34. package/nitrogen/generated/android/runanywherellamaOnLoad.hpp +25 -0
  35. package/nitrogen/generated/ios/RunAnywhereLlama+autolinking.rb +60 -0
  36. package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Bridge.cpp +17 -0
  37. package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Bridge.hpp +27 -0
  38. package/nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Umbrella.hpp +38 -0
  39. package/nitrogen/generated/ios/RunAnywhereLlamaAutolinking.mm +35 -0
  40. package/nitrogen/generated/ios/RunAnywhereLlamaAutolinking.swift +12 -0
  41. package/nitrogen/generated/shared/c++/HybridRunAnywhereLlamaSpec.cpp +33 -0
  42. package/nitrogen/generated/shared/c++/HybridRunAnywhereLlamaSpec.hpp +77 -0
  43. package/package.json +60 -0
  44. package/react-native.config.js +14 -0
  45. package/src/LlamaCPP.ts +206 -0
  46. package/src/LlamaCppProvider.ts +120 -0
  47. package/src/index.ts +59 -0
  48. package/src/native/NativeRunAnywhereLlama.ts +58 -0
  49. package/src/native/index.ts +11 -0
  50. package/src/specs/RunAnywhereLlama.nitro.ts +160 -0
@@ -0,0 +1,81 @@
1
+ #
2
+ # runanywherellama+autolinking.cmake
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © 2026 Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a CMake file that adds all files generated by Nitrogen
9
+ # to the current CMake project.
10
+ #
11
+ # To use it, add this to your CMakeLists.txt:
12
+ # ```cmake
13
+ # include(${CMAKE_SOURCE_DIR}/../nitrogen/generated/android/runanywherellama+autolinking.cmake)
14
+ # ```
15
+
16
+ # Define a flag to check if we are building properly
17
+ add_definitions(-DBUILDING_RUNANYWHERELLAMA_WITH_GENERATED_CMAKE_PROJECT)
18
+
19
+ # Enable Raw Props parsing in react-native (for Nitro Views)
20
+ add_definitions(-DRN_SERIALIZABLE_STATE)
21
+
22
+ # Add all headers that were generated by Nitrogen
23
+ include_directories(
24
+ "../nitrogen/generated/shared/c++"
25
+ "../nitrogen/generated/android/c++"
26
+ "../nitrogen/generated/android/"
27
+ )
28
+
29
+ # Add all .cpp sources that were generated by Nitrogen
30
+ target_sources(
31
+ # CMake project name (Android C++ library name)
32
+ runanywherellama PRIVATE
33
+ # Autolinking Setup
34
+ ../nitrogen/generated/android/runanywherellamaOnLoad.cpp
35
+ # Shared Nitrogen C++ sources
36
+ ../nitrogen/generated/shared/c++/HybridRunAnywhereLlamaSpec.cpp
37
+ # Android-specific Nitrogen C++ sources
38
+
39
+ )
40
+
41
+ # From node_modules/react-native/ReactAndroid/cmake-utils/folly-flags.cmake
42
+ # Used in node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
43
+ target_compile_definitions(
44
+ runanywherellama PRIVATE
45
+ -DFOLLY_NO_CONFIG=1
46
+ -DFOLLY_HAVE_CLOCK_GETTIME=1
47
+ -DFOLLY_USE_LIBCPP=1
48
+ -DFOLLY_CFG_NO_COROUTINES=1
49
+ -DFOLLY_MOBILE=1
50
+ -DFOLLY_HAVE_RECVMMSG=1
51
+ -DFOLLY_HAVE_PTHREAD=1
52
+ # Once we target android-23 above, we can comment
53
+ # the following line. NDK uses GNU style stderror_r() after API 23.
54
+ -DFOLLY_HAVE_XSI_STRERROR_R=1
55
+ )
56
+
57
+ # Add all libraries required by the generated specs
58
+ find_package(fbjni REQUIRED) # <-- Used for communication between Java <-> C++
59
+ find_package(ReactAndroid REQUIRED) # <-- Used to set up React Native bindings (e.g. CallInvoker/TurboModule)
60
+ find_package(react-native-nitro-modules REQUIRED) # <-- Used to create all HybridObjects and use the Nitro core library
61
+
62
+ # Link all libraries together
63
+ target_link_libraries(
64
+ runanywherellama
65
+ fbjni::fbjni # <-- Facebook C++ JNI helpers
66
+ ReactAndroid::jsi # <-- RN: JSI
67
+ react-native-nitro-modules::NitroModules # <-- NitroModules Core :)
68
+ )
69
+
70
+ # Link react-native (different prefab between RN 0.75 and RN 0.76)
71
+ if(ReactAndroid_VERSION_MINOR GREATER_EQUAL 76)
72
+ target_link_libraries(
73
+ runanywherellama
74
+ ReactAndroid::reactnative # <-- RN: Native Modules umbrella prefab
75
+ )
76
+ else()
77
+ target_link_libraries(
78
+ runanywherellama
79
+ ReactAndroid::react_nativemodule_core # <-- RN: TurboModules Core
80
+ )
81
+ endif()
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// runanywherellama+autolinking.gradle
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ /// This is a Gradle file that adds all files generated by Nitrogen
9
+ /// to the current Gradle project.
10
+ ///
11
+ /// To use it, add this to your build.gradle:
12
+ /// ```gradle
13
+ /// apply from: '../nitrogen/generated/android/runanywherellama+autolinking.gradle'
14
+ /// ```
15
+
16
+ logger.warn("[NitroModules] 🔥 runanywherellama is boosted by nitro!")
17
+
18
+ android {
19
+ sourceSets {
20
+ main {
21
+ java.srcDirs += [
22
+ // Nitrogen files
23
+ "${project.projectDir}/../nitrogen/generated/android/kotlin"
24
+ ]
25
+ }
26
+ }
27
+ }
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// runanywherellamaOnLoad.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #ifndef BUILDING_RUNANYWHERELLAMA_WITH_GENERATED_CMAKE_PROJECT
9
+ #error runanywherellamaOnLoad.cpp is not being built with the autogenerated CMakeLists.txt project. Is a different CMakeLists.txt building this?
10
+ #endif
11
+
12
+ #include "runanywherellamaOnLoad.hpp"
13
+
14
+ #include <jni.h>
15
+ #include <fbjni/fbjni.h>
16
+ #include <NitroModules/HybridObjectRegistry.hpp>
17
+
18
+ #include "HybridRunAnywhereLlama.hpp"
19
+
20
+ namespace margelo::nitro::runanywhere::llama {
21
+
22
+ int initialize(JavaVM* vm) {
23
+ using namespace margelo::nitro;
24
+ using namespace margelo::nitro::runanywhere::llama;
25
+ using namespace facebook;
26
+
27
+ return facebook::jni::initialize(vm, [] {
28
+ // Register native JNI methods
29
+
30
+
31
+ // Register Nitro Hybrid Objects
32
+ HybridObjectRegistry::registerHybridObjectConstructor(
33
+ "RunAnywhereLlama",
34
+ []() -> std::shared_ptr<HybridObject> {
35
+ static_assert(std::is_default_constructible_v<HybridRunAnywhereLlama>,
36
+ "The HybridObject \"HybridRunAnywhereLlama\" is not default-constructible! "
37
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
38
+ return std::make_shared<HybridRunAnywhereLlama>();
39
+ }
40
+ );
41
+ });
42
+ }
43
+
44
+ } // namespace margelo::nitro::runanywhere::llama
@@ -0,0 +1,25 @@
1
+ ///
2
+ /// runanywherellamaOnLoad.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include <jni.h>
9
+ #include <NitroModules/NitroDefines.hpp>
10
+
11
+ namespace margelo::nitro::runanywhere::llama {
12
+
13
+ /**
14
+ * Initializes the native (C++) part of runanywherellama, and autolinks all Hybrid Objects.
15
+ * Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`).
16
+ * Example:
17
+ * ```cpp (cpp-adapter.cpp)
18
+ * JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
19
+ * return margelo::nitro::runanywhere::llama::initialize(vm);
20
+ * }
21
+ * ```
22
+ */
23
+ int initialize(JavaVM* vm);
24
+
25
+ } // namespace margelo::nitro::runanywhere::llama
@@ -0,0 +1,60 @@
1
+ #
2
+ # RunAnywhereLlama+autolinking.rb
3
+ # This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ # https://github.com/mrousavy/nitro
5
+ # Copyright © 2026 Marc Rousavy @ Margelo
6
+ #
7
+
8
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/RunAnywhereLlama+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 RunAnywhereLlama is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/RunAnywhereLlama-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only C)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ })
60
+ end
@@ -0,0 +1,17 @@
1
+ ///
2
+ /// RunAnywhereLlama-Swift-Cxx-Bridge.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "RunAnywhereLlama-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+
12
+
13
+ namespace margelo::nitro::runanywhere::llama::bridge::swift {
14
+
15
+
16
+
17
+ } // namespace margelo::nitro::runanywhere::llama::bridge::swift
@@ -0,0 +1,27 @@
1
+ ///
2
+ /// RunAnywhereLlama-Swift-Cxx-Bridge.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Forward declarations of Swift defined types
14
+
15
+
16
+ // Include C++ defined types
17
+
18
+
19
+ /**
20
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
21
+ * as well as helper functions to interact with those C++ types from Swift.
22
+ */
23
+ namespace margelo::nitro::runanywhere::llama::bridge::swift {
24
+
25
+
26
+
27
+ } // namespace margelo::nitro::runanywhere::llama::bridge::swift
@@ -0,0 +1,38 @@
1
+ ///
2
+ /// RunAnywhereLlama-Swift-Cxx-Umbrella.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ // Forward declarations of C++ defined types
11
+
12
+
13
+ // Include C++ defined types
14
+
15
+
16
+ // C++ helpers for Swift
17
+ #include "RunAnywhereLlama-Swift-Cxx-Bridge.hpp"
18
+
19
+ // Common C++ types used in Swift
20
+ #include <NitroModules/ArrayBufferHolder.hpp>
21
+ #include <NitroModules/AnyMapUtils.hpp>
22
+ #include <NitroModules/RuntimeError.hpp>
23
+ #include <NitroModules/DateToChronoDate.hpp>
24
+
25
+ // Forward declarations of Swift defined types
26
+
27
+
28
+ // Include Swift defined types
29
+ #if __has_include("RunAnywhereLlama-Swift.h")
30
+ // This header is generated by Xcode/Swift on every app build.
31
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "RunAnywhereLlama".
32
+ #include "RunAnywhereLlama-Swift.h"
33
+ // Same as above, but used when building with frameworks (`use_frameworks`)
34
+ #elif __has_include(<RunAnywhereLlama/RunAnywhereLlama-Swift.h>)
35
+ #include <RunAnywhereLlama/RunAnywhereLlama-Swift.h>
36
+ #else
37
+ #error RunAnywhereLlama's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "RunAnywhereLlama", and try building the app first.
38
+ #endif
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// RunAnywhereLlamaAutolinking.mm
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+
11
+ #import <type_traits>
12
+
13
+ #include "HybridRunAnywhereLlama.hpp"
14
+
15
+ @interface RunAnywhereLlamaAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation RunAnywhereLlamaAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::runanywhere::llama;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "RunAnywhereLlama",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ static_assert(std::is_default_constructible_v<HybridRunAnywhereLlama>,
28
+ "The HybridObject \"HybridRunAnywhereLlama\" is not default-constructible! "
29
+ "Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
30
+ return std::make_shared<HybridRunAnywhereLlama>();
31
+ }
32
+ );
33
+ }
34
+
35
+ @end
@@ -0,0 +1,12 @@
1
+ ///
2
+ /// RunAnywhereLlamaAutolinking.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ public final class RunAnywhereLlamaAutolinking {
9
+ public typealias bridge = margelo.nitro.runanywhere.llama.bridge.swift
10
+
11
+
12
+ }
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// HybridRunAnywhereLlamaSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridRunAnywhereLlamaSpec.hpp"
9
+
10
+ namespace margelo::nitro::runanywhere::llama {
11
+
12
+ void HybridRunAnywhereLlamaSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("registerBackend", &HybridRunAnywhereLlamaSpec::registerBackend);
18
+ prototype.registerHybridMethod("unregisterBackend", &HybridRunAnywhereLlamaSpec::unregisterBackend);
19
+ prototype.registerHybridMethod("isBackendRegistered", &HybridRunAnywhereLlamaSpec::isBackendRegistered);
20
+ prototype.registerHybridMethod("loadModel", &HybridRunAnywhereLlamaSpec::loadModel);
21
+ prototype.registerHybridMethod("isModelLoaded", &HybridRunAnywhereLlamaSpec::isModelLoaded);
22
+ prototype.registerHybridMethod("unloadModel", &HybridRunAnywhereLlamaSpec::unloadModel);
23
+ prototype.registerHybridMethod("getModelInfo", &HybridRunAnywhereLlamaSpec::getModelInfo);
24
+ prototype.registerHybridMethod("generate", &HybridRunAnywhereLlamaSpec::generate);
25
+ prototype.registerHybridMethod("generateStream", &HybridRunAnywhereLlamaSpec::generateStream);
26
+ prototype.registerHybridMethod("cancelGeneration", &HybridRunAnywhereLlamaSpec::cancelGeneration);
27
+ prototype.registerHybridMethod("generateStructured", &HybridRunAnywhereLlamaSpec::generateStructured);
28
+ prototype.registerHybridMethod("getLastError", &HybridRunAnywhereLlamaSpec::getLastError);
29
+ prototype.registerHybridMethod("getMemoryUsage", &HybridRunAnywhereLlamaSpec::getMemoryUsage);
30
+ });
31
+ }
32
+
33
+ } // namespace margelo::nitro::runanywhere::llama
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// HybridRunAnywhereLlamaSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2026 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+
17
+
18
+ #include <NitroModules/Promise.hpp>
19
+ #include <string>
20
+ #include <optional>
21
+ #include <functional>
22
+
23
+ namespace margelo::nitro::runanywhere::llama {
24
+
25
+ using namespace margelo::nitro;
26
+
27
+ /**
28
+ * An abstract base class for `RunAnywhereLlama`
29
+ * Inherit this class to create instances of `HybridRunAnywhereLlamaSpec` in C++.
30
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
31
+ * @example
32
+ * ```cpp
33
+ * class HybridRunAnywhereLlama: public HybridRunAnywhereLlamaSpec {
34
+ * public:
35
+ * HybridRunAnywhereLlama(...): HybridObject(TAG) { ... }
36
+ * // ...
37
+ * };
38
+ * ```
39
+ */
40
+ class HybridRunAnywhereLlamaSpec: public virtual HybridObject {
41
+ public:
42
+ // Constructor
43
+ explicit HybridRunAnywhereLlamaSpec(): HybridObject(TAG) { }
44
+
45
+ // Destructor
46
+ ~HybridRunAnywhereLlamaSpec() override = default;
47
+
48
+ public:
49
+ // Properties
50
+
51
+
52
+ public:
53
+ // Methods
54
+ virtual std::shared_ptr<Promise<bool>> registerBackend() = 0;
55
+ virtual std::shared_ptr<Promise<bool>> unregisterBackend() = 0;
56
+ virtual std::shared_ptr<Promise<bool>> isBackendRegistered() = 0;
57
+ virtual std::shared_ptr<Promise<bool>> loadModel(const std::string& path, const std::optional<std::string>& modelId, const std::optional<std::string>& modelName, const std::optional<std::string>& configJson) = 0;
58
+ virtual std::shared_ptr<Promise<bool>> isModelLoaded() = 0;
59
+ virtual std::shared_ptr<Promise<bool>> unloadModel() = 0;
60
+ virtual std::shared_ptr<Promise<std::string>> getModelInfo() = 0;
61
+ virtual std::shared_ptr<Promise<std::string>> generate(const std::string& prompt, const std::optional<std::string>& optionsJson) = 0;
62
+ virtual std::shared_ptr<Promise<std::string>> generateStream(const std::string& prompt, const std::string& optionsJson, const std::function<void(const std::string& /* token */, bool /* isComplete */)>& callback) = 0;
63
+ virtual std::shared_ptr<Promise<bool>> cancelGeneration() = 0;
64
+ virtual std::shared_ptr<Promise<std::string>> generateStructured(const std::string& prompt, const std::string& schema, const std::optional<std::string>& optionsJson) = 0;
65
+ virtual std::shared_ptr<Promise<std::string>> getLastError() = 0;
66
+ virtual std::shared_ptr<Promise<double>> getMemoryUsage() = 0;
67
+
68
+ protected:
69
+ // Hybrid Setup
70
+ void loadHybridMethods() override;
71
+
72
+ protected:
73
+ // Tag for logging
74
+ static constexpr auto TAG = "RunAnywhereLlama";
75
+ };
76
+
77
+ } // namespace margelo::nitro::runanywhere::llama
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@runanywhere/llamacpp",
3
+ "version": "0.16.0",
4
+ "description": "LlamaCpp backend for RunAnywhere React Native SDK - GGUF model support for on-device LLM",
5
+ "main": "src/index.ts",
6
+ "types": "src/index.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.ts",
10
+ "types": "./src/index.ts",
11
+ "default": "./src/index.ts"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "react-native": "src/index",
16
+ "source": "src/index",
17
+ "files": [
18
+ "src",
19
+ "cpp",
20
+ "ios",
21
+ "android",
22
+ "nitrogen",
23
+ "nitro.json",
24
+ "react-native.config.js",
25
+ "*.podspec"
26
+ ],
27
+ "scripts": {
28
+ "typecheck": "tsc --noEmit",
29
+ "lint": "eslint \"src/**/*.ts\"",
30
+ "lint:fix": "eslint \"src/**/*.ts\" --fix",
31
+ "nitrogen": "nitrogen",
32
+ "prepare": "nitrogen"
33
+ },
34
+ "keywords": [
35
+ "react-native",
36
+ "runanywhere",
37
+ "llm",
38
+ "llamacpp",
39
+ "llama",
40
+ "gguf",
41
+ "on-device",
42
+ "nitro"
43
+ ],
44
+ "license": "MIT",
45
+ "peerDependencies": {
46
+ "@runanywhere/core": "^0.16.0",
47
+ "react": "*",
48
+ "react-native": "*",
49
+ "react-native-nitro-modules": "^0.31.3"
50
+ },
51
+ "devDependencies": {
52
+ "nitrogen": "^0.31.10",
53
+ "react-native-nitro-modules": "^0.31.10",
54
+ "typescript": "^5.2.2"
55
+ },
56
+ "create-react-native-library": {
57
+ "languages": "kotlin-swift",
58
+ "type": "nitro-module"
59
+ }
60
+ }
@@ -0,0 +1,14 @@
1
+ module.exports = {
2
+ dependency: {
3
+ platforms: {
4
+ android: {
5
+ sourceDir: './android',
6
+ packageImportPath: 'import com.margelo.nitro.runanywhere.llama.RunAnywhereLlamaPackage;',
7
+ packageInstance: 'new RunAnywhereLlamaPackage()',
8
+ },
9
+ ios: {
10
+ podspecPath: './RunAnywhereLlama.podspec',
11
+ },
12
+ },
13
+ },
14
+ };