@dr33m/react-native-litert-lm 0.5.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.
- package/LICENSE +21 -0
- package/README.md +627 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +104 -0
- package/android/src/main/AndroidManifest.xml +19 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLM.kt +888 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridModelStore.kt +189 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/LiteRTLMRegistry.kt +32 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/MultimodalPartFactories.kt +15 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/StreamingCallbackListener.kt +89 -0
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMInitProvider.kt +57 -0
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMPackage.kt +43 -0
- package/android/src/test/java/com/margelo/nitro/core/Promise.kt +46 -0
- package/android/src/test/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMTest.kt +122 -0
- package/app.plugin.js +58 -0
- package/cpp/cpp-adapter.cpp +21 -0
- package/cpp/include/README.md +32 -0
- package/cpp/include/litert_lm_engine.h +516 -0
- package/cpp/include/stb_image.h +7988 -0
- package/ios/HybridLiteRTLM+Execute.swift +287 -0
- package/ios/HybridLiteRTLM+Streaming.swift +153 -0
- package/ios/HybridLiteRTLM.swift +541 -0
- package/ios/HybridModelStore.swift +206 -0
- package/ios/MultimodalPart+Factories.swift +22 -0
- package/ios/Tests/HybridLiteRTLMTests.swift +187 -0
- package/lib/__mocks__/react-native-nitro-modules.d.ts +81 -0
- package/lib/__mocks__/react-native-nitro-modules.js +98 -0
- package/lib/__tests__/hooks.test.d.ts +1 -0
- package/lib/__tests__/hooks.test.js +175 -0
- package/lib/__tests__/inferenceRouting.test.d.ts +1 -0
- package/lib/__tests__/inferenceRouting.test.js +28 -0
- package/lib/__tests__/memoryTracker.test.d.ts +1 -0
- package/lib/__tests__/memoryTracker.test.js +74 -0
- package/lib/__tests__/modelFactory.test.d.ts +1 -0
- package/lib/__tests__/modelFactory.test.js +107 -0
- package/lib/__tests__/modelPath.test.d.ts +1 -0
- package/lib/__tests__/modelPath.test.js +12 -0
- package/lib/__tests__/modelRegistry.test.d.ts +1 -0
- package/lib/__tests__/modelRegistry.test.js +61 -0
- package/lib/hooks.d.ts +46 -0
- package/lib/hooks.js +159 -0
- package/lib/index.d.ts +142 -0
- package/lib/index.js +184 -0
- package/lib/inferenceRouting.d.ts +18 -0
- package/lib/inferenceRouting.js +63 -0
- package/lib/memoryTracker.d.ts +128 -0
- package/lib/memoryTracker.js +155 -0
- package/lib/modelFactory.d.ts +24 -0
- package/lib/modelFactory.js +128 -0
- package/lib/modelPath.d.ts +8 -0
- package/lib/modelPath.js +18 -0
- package/lib/modelRegistry.d.ts +55 -0
- package/lib/modelRegistry.js +82 -0
- package/lib/specs/LiteRTLM.nitro.d.ts +380 -0
- package/lib/specs/LiteRTLM.nitro.js +2 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/LiteRTLM+autolinking.cmake +83 -0
- package/nitrogen/generated/android/LiteRTLM+autolinking.gradle +27 -0
- package/nitrogen/generated/android/LiteRTLMOnLoad.cpp +74 -0
- package/nitrogen/generated/android/LiteRTLMOnLoad.hpp +34 -0
- package/nitrogen/generated/android/c++/JBackend.hpp +61 -0
- package/nitrogen/generated/android/c++/JExecuteResult.hpp +86 -0
- package/nitrogen/generated/android/c++/JFunc_void_double.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string_bool.hpp +76 -0
- package/nitrogen/generated/android/c++/JGenerationStats.hpp +77 -0
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.cpp +371 -0
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.hpp +83 -0
- package/nitrogen/generated/android/c++/JHybridModelStoreSpec.cpp +101 -0
- package/nitrogen/generated/android/c++/JHybridModelStoreSpec.hpp +67 -0
- package/nitrogen/generated/android/c++/JLLMConfig.hpp +125 -0
- package/nitrogen/generated/android/c++/JMemoryUsage.hpp +69 -0
- package/nitrogen/generated/android/c++/JMessage.hpp +63 -0
- package/nitrogen/generated/android/c++/JModelFile.hpp +69 -0
- package/nitrogen/generated/android/c++/JMultimodalPart.hpp +78 -0
- package/nitrogen/generated/android/c++/JPartType.hpp +61 -0
- package/nitrogen/generated/android/c++/JRole.hpp +61 -0
- package/nitrogen/generated/android/c++/JToolCall.hpp +61 -0
- package/nitrogen/generated/android/c++/JToolDefinition.hpp +65 -0
- package/nitrogen/generated/android/c++/JToolResponse.hpp +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Backend.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ExecuteResult.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Func_void_double.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Func_void_std__string_bool.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/GenerationStats.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMSpec.kt +165 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridModelStoreSpec.kt +76 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LLMConfig.kt +106 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LiteRTLMOnLoad.kt +35 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MemoryUsage.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Message.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ModelFile.kt +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MultimodalPart.kt +71 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/PartType.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Role.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolCall.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolDefinition.kt +61 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ToolResponse.kt +56 -0
- package/nitrogen/generated/ios/LiteRTLM+autolinking.rb +62 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.cpp +98 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.hpp +585 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Umbrella.hpp +93 -0
- package/nitrogen/generated/ios/LiteRTLMAutolinking.mm +41 -0
- package/nitrogen/generated/ios/LiteRTLMAutolinking.swift +38 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.hpp +279 -0
- package/nitrogen/generated/ios/c++/HybridModelStoreSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridModelStoreSpecSwift.hpp +117 -0
- package/nitrogen/generated/ios/swift/Backend.swift +44 -0
- package/nitrogen/generated/ios/swift/ExecuteResult.swift +45 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_ExecuteResult.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_double.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/GenerationStats.swift +54 -0
- package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec.swift +75 -0
- package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec_cxx.swift +516 -0
- package/nitrogen/generated/ios/swift/HybridModelStoreSpec.swift +59 -0
- package/nitrogen/generated/ios/swift/HybridModelStoreSpec_cxx.swift +203 -0
- package/nitrogen/generated/ios/swift/LLMConfig.swift +239 -0
- package/nitrogen/generated/ios/swift/MemoryUsage.swift +44 -0
- package/nitrogen/generated/ios/swift/Message.swift +34 -0
- package/nitrogen/generated/ios/swift/ModelFile.swift +44 -0
- package/nitrogen/generated/ios/swift/MultimodalPart.swift +101 -0
- package/nitrogen/generated/ios/swift/PartType.swift +44 -0
- package/nitrogen/generated/ios/swift/Role.swift +44 -0
- package/nitrogen/generated/ios/swift/ToolCall.swift +34 -0
- package/nitrogen/generated/ios/swift/ToolDefinition.swift +39 -0
- package/nitrogen/generated/ios/swift/ToolResponse.swift +34 -0
- package/nitrogen/generated/shared/c++/Backend.hpp +80 -0
- package/nitrogen/generated/shared/c++/ExecuteResult.hpp +94 -0
- package/nitrogen/generated/shared/c++/GenerationStats.hpp +103 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.cpp +41 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.hpp +109 -0
- package/nitrogen/generated/shared/c++/HybridModelStoreSpec.cpp +25 -0
- package/nitrogen/generated/shared/c++/HybridModelStoreSpec.hpp +71 -0
- package/nitrogen/generated/shared/c++/LLMConfig.hpp +134 -0
- package/nitrogen/generated/shared/c++/MemoryUsage.hpp +95 -0
- package/nitrogen/generated/shared/c++/Message.hpp +89 -0
- package/nitrogen/generated/shared/c++/ModelFile.hpp +95 -0
- package/nitrogen/generated/shared/c++/MultimodalPart.hpp +103 -0
- package/nitrogen/generated/shared/c++/PartType.hpp +80 -0
- package/nitrogen/generated/shared/c++/Role.hpp +80 -0
- package/nitrogen/generated/shared/c++/ToolCall.hpp +87 -0
- package/nitrogen/generated/shared/c++/ToolDefinition.hpp +91 -0
- package/nitrogen/generated/shared/c++/ToolResponse.hpp +87 -0
- package/package.json +115 -0
- package/react-native-litert-lm.podspec +62 -0
- package/react-native.config.js +16 -0
- package/scripts/download-ios-frameworks.sh +39 -0
- package/scripts/framework-source.js +46 -0
- package/scripts/postinstall.js +145 -0
- package/src/__mocks__/react-native-nitro-modules.ts +132 -0
- package/src/__tests__/hooks.test.ts +216 -0
- package/src/__tests__/inferenceRouting.test.ts +36 -0
- package/src/__tests__/memoryTracker.test.ts +87 -0
- package/src/__tests__/modelFactory.test.ts +153 -0
- package/src/__tests__/modelPath.test.ts +14 -0
- package/src/__tests__/modelRegistry.test.ts +73 -0
- package/src/hooks.ts +234 -0
- package/src/index.ts +214 -0
- package/src/inferenceRouting.ts +80 -0
- package/src/memoryTracker.ts +268 -0
- package/src/modelFactory.ts +163 -0
- package/src/modelPath.ts +16 -0
- package/src/modelRegistry.ts +104 -0
- package/src/specs/LiteRTLM.nitro.ts +451 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JToolResponse.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "ToolResponse.hpp"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::litertlm {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "ToolResponse" and the the Kotlin data class "ToolResponse".
|
|
21
|
+
*/
|
|
22
|
+
struct JToolResponse final: public jni::JavaClass<JToolResponse> {
|
|
23
|
+
public:
|
|
24
|
+
static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/dev/litert/litertlm/ToolResponse;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct ToolResponse by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
ToolResponse toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldName = clazz->getField<jni::JString>("name");
|
|
35
|
+
jni::local_ref<jni::JString> name = this->getFieldValue(fieldName);
|
|
36
|
+
static const auto fieldResponseJson = clazz->getField<jni::JString>("responseJson");
|
|
37
|
+
jni::local_ref<jni::JString> responseJson = this->getFieldValue(fieldResponseJson);
|
|
38
|
+
return ToolResponse(
|
|
39
|
+
name->toStdString(),
|
|
40
|
+
responseJson->toStdString()
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public:
|
|
45
|
+
/**
|
|
46
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
47
|
+
*/
|
|
48
|
+
[[maybe_unused]]
|
|
49
|
+
static jni::local_ref<JToolResponse::javaobject> fromCpp(const ToolResponse& value) {
|
|
50
|
+
using JSignature = JToolResponse(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
|
|
51
|
+
static const auto clazz = javaClassStatic();
|
|
52
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
53
|
+
return create(
|
|
54
|
+
clazz,
|
|
55
|
+
jni::make_jstring(value.name),
|
|
56
|
+
jni::make_jstring(value.responseJson)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
} // namespace margelo::nitro::litertlm
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Backend.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Represents the JavaScript enum/union "Backend".
|
|
15
|
+
*/
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
@Keep
|
|
18
|
+
enum class Backend(@DoNotStrip @Keep val value: Int) {
|
|
19
|
+
CPU(0),
|
|
20
|
+
GPU(1),
|
|
21
|
+
NPU(2);
|
|
22
|
+
|
|
23
|
+
companion object
|
|
24
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/ExecuteResult.kt
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ExecuteResult.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
import java.util.Objects
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the JavaScript object/struct "ExecuteResult".
|
|
17
|
+
*/
|
|
18
|
+
@DoNotStrip
|
|
19
|
+
@Keep
|
|
20
|
+
data class ExecuteResult(
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
val text: String,
|
|
24
|
+
@DoNotStrip
|
|
25
|
+
@Keep
|
|
26
|
+
val toolCalls: Array<ToolCall>,
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
@Keep
|
|
29
|
+
val thinkingText: String
|
|
30
|
+
) {
|
|
31
|
+
/* primary constructor */
|
|
32
|
+
|
|
33
|
+
override fun equals(other: Any?): Boolean {
|
|
34
|
+
if (this === other) return true
|
|
35
|
+
if (other !is ExecuteResult) return false
|
|
36
|
+
return Objects.deepEquals(this.text, other.text)
|
|
37
|
+
&& Objects.deepEquals(this.toolCalls, other.toolCalls)
|
|
38
|
+
&& Objects.deepEquals(this.thinkingText, other.thinkingText)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
override fun hashCode(): Int {
|
|
42
|
+
return arrayOf<Any?>(
|
|
43
|
+
text,
|
|
44
|
+
toolCalls,
|
|
45
|
+
thinkingText
|
|
46
|
+
).contentDeepHashCode()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
companion object {
|
|
50
|
+
/**
|
|
51
|
+
* Constructor called from C++
|
|
52
|
+
*/
|
|
53
|
+
@DoNotStrip
|
|
54
|
+
@Keep
|
|
55
|
+
@Suppress("unused")
|
|
56
|
+
@JvmStatic
|
|
57
|
+
private fun fromCpp(text: String, toolCalls: Array<ToolCall>, thinkingText: String): ExecuteResult {
|
|
58
|
+
return ExecuteResult(text, toolCalls, thinkingText)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Func_void_double.kt
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_double.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `(progress: number) => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void_double: (Double) -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(progress: Double): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(progress: number) => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_double_cxx: Func_void_double {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(progress: Double): Unit
|
|
60
|
+
= invoke_cxx(progress)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(progress: Double): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(progress: number) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(Double) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_double_java(private val function: (Double) -> Unit): Func_void_double {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(progress: Double): Unit {
|
|
78
|
+
return this.function(progress)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string_bool.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `(token: string, done: boolean) => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void_std__string_bool: (String, Boolean) -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(token: String, done: Boolean): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(token: string, done: boolean) => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_std__string_bool_cxx: Func_void_std__string_bool {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(token: String, done: Boolean): Unit
|
|
60
|
+
= invoke_cxx(token,done)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(token: String, done: Boolean): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(token: string, done: boolean) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(String, Boolean) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_std__string_bool_java(private val function: (String, Boolean) -> Unit): Func_void_std__string_bool {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(token: String, done: Boolean): Unit {
|
|
78
|
+
return this.function(token, done)
|
|
79
|
+
}
|
|
80
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/GenerationStats.kt
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// GenerationStats.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
import java.util.Objects
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the JavaScript object/struct "GenerationStats".
|
|
17
|
+
*/
|
|
18
|
+
@DoNotStrip
|
|
19
|
+
@Keep
|
|
20
|
+
data class GenerationStats(
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
val promptTokens: Double,
|
|
24
|
+
@DoNotStrip
|
|
25
|
+
@Keep
|
|
26
|
+
val completionTokens: Double,
|
|
27
|
+
@DoNotStrip
|
|
28
|
+
@Keep
|
|
29
|
+
val totalTokens: Double,
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
@Keep
|
|
32
|
+
val timeToFirstToken: Double,
|
|
33
|
+
@DoNotStrip
|
|
34
|
+
@Keep
|
|
35
|
+
val totalTime: Double,
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
@Keep
|
|
38
|
+
val tokensPerSecond: Double
|
|
39
|
+
) {
|
|
40
|
+
/* primary constructor */
|
|
41
|
+
|
|
42
|
+
override fun equals(other: Any?): Boolean {
|
|
43
|
+
if (this === other) return true
|
|
44
|
+
if (other !is GenerationStats) return false
|
|
45
|
+
return Objects.deepEquals(this.promptTokens, other.promptTokens)
|
|
46
|
+
&& Objects.deepEquals(this.completionTokens, other.completionTokens)
|
|
47
|
+
&& Objects.deepEquals(this.totalTokens, other.totalTokens)
|
|
48
|
+
&& Objects.deepEquals(this.timeToFirstToken, other.timeToFirstToken)
|
|
49
|
+
&& Objects.deepEquals(this.totalTime, other.totalTime)
|
|
50
|
+
&& Objects.deepEquals(this.tokensPerSecond, other.tokensPerSecond)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
override fun hashCode(): Int {
|
|
54
|
+
return arrayOf<Any?>(
|
|
55
|
+
promptTokens,
|
|
56
|
+
completionTokens,
|
|
57
|
+
totalTokens,
|
|
58
|
+
timeToFirstToken,
|
|
59
|
+
totalTime,
|
|
60
|
+
tokensPerSecond
|
|
61
|
+
).contentDeepHashCode()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
companion object {
|
|
65
|
+
/**
|
|
66
|
+
* Constructor called from C++
|
|
67
|
+
*/
|
|
68
|
+
@DoNotStrip
|
|
69
|
+
@Keep
|
|
70
|
+
@Suppress("unused")
|
|
71
|
+
@JvmStatic
|
|
72
|
+
private fun fromCpp(promptTokens: Double, completionTokens: Double, totalTokens: Double, timeToFirstToken: Double, totalTime: Double, tokensPerSecond: Double): GenerationStats {
|
|
73
|
+
return GenerationStats(promptTokens, completionTokens, totalTokens, timeToFirstToken, totalTime, tokensPerSecond)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLiteRTLMSpec.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
import com.margelo.nitro.core.HybridObject
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Kotlin class representing the LiteRTLM HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of LiteRTLM.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress(
|
|
23
|
+
"KotlinJniMissingFunction", "unused",
|
|
24
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
|
+
)
|
|
27
|
+
abstract class HybridLiteRTLMSpec: HybridObject() {
|
|
28
|
+
// Properties
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// Methods
|
|
32
|
+
@DoNotStrip
|
|
33
|
+
@Keep
|
|
34
|
+
abstract fun loadModel(modelPath: String, config: LLMConfig?): Promise<Unit>
|
|
35
|
+
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
@Keep
|
|
38
|
+
abstract fun sendMessage(message: String): Promise<ExecuteResult>
|
|
39
|
+
|
|
40
|
+
@DoNotStrip
|
|
41
|
+
@Keep
|
|
42
|
+
abstract fun sendMessageWithImage(message: String, imagePath: String): Promise<ExecuteResult>
|
|
43
|
+
|
|
44
|
+
abstract fun sendMessageWithImageAsync(message: String, imagePath: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
|
|
45
|
+
|
|
46
|
+
@DoNotStrip
|
|
47
|
+
@Keep
|
|
48
|
+
private fun sendMessageWithImageAsync_cxx(message: String, imagePath: String, onToken: Func_void_std__string_bool): Promise<Unit> {
|
|
49
|
+
val __result = sendMessageWithImageAsync(message, imagePath, onToken)
|
|
50
|
+
return __result
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
abstract fun downloadModel(url: String, fileName: String, onProgress: ((progress: Double) -> Unit)?): Promise<String>
|
|
54
|
+
|
|
55
|
+
@DoNotStrip
|
|
56
|
+
@Keep
|
|
57
|
+
private fun downloadModel_cxx(url: String, fileName: String, onProgress: Func_void_double?): Promise<String> {
|
|
58
|
+
val __result = downloadModel(url, fileName, onProgress?.let { it })
|
|
59
|
+
return __result
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@DoNotStrip
|
|
63
|
+
@Keep
|
|
64
|
+
abstract fun deleteModel(fileName: String): Promise<Unit>
|
|
65
|
+
|
|
66
|
+
@DoNotStrip
|
|
67
|
+
@Keep
|
|
68
|
+
abstract fun sendMessageWithAudio(message: String, audioPath: String): Promise<ExecuteResult>
|
|
69
|
+
|
|
70
|
+
abstract fun sendMessageWithAudioAsync(message: String, audioPath: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
|
|
71
|
+
|
|
72
|
+
@DoNotStrip
|
|
73
|
+
@Keep
|
|
74
|
+
private fun sendMessageWithAudioAsync_cxx(message: String, audioPath: String, onToken: Func_void_std__string_bool): Promise<Unit> {
|
|
75
|
+
val __result = sendMessageWithAudioAsync(message, audioPath, onToken)
|
|
76
|
+
return __result
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@DoNotStrip
|
|
80
|
+
@Keep
|
|
81
|
+
abstract fun sendMultimodalMessage(parts: Array<MultimodalPart>): Promise<ExecuteResult>
|
|
82
|
+
|
|
83
|
+
abstract fun sendMessageAsync(message: String, onToken: (token: String, done: Boolean) -> Unit): Promise<Unit>
|
|
84
|
+
|
|
85
|
+
@DoNotStrip
|
|
86
|
+
@Keep
|
|
87
|
+
private fun sendMessageAsync_cxx(message: String, onToken: Func_void_std__string_bool): Promise<Unit> {
|
|
88
|
+
val __result = sendMessageAsync(message, onToken)
|
|
89
|
+
return __result
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@DoNotStrip
|
|
93
|
+
@Keep
|
|
94
|
+
abstract fun getHistory(): Array<Message>
|
|
95
|
+
|
|
96
|
+
@DoNotStrip
|
|
97
|
+
@Keep
|
|
98
|
+
abstract fun resetConversation(): Unit
|
|
99
|
+
|
|
100
|
+
@DoNotStrip
|
|
101
|
+
@Keep
|
|
102
|
+
abstract fun isReady(): Boolean
|
|
103
|
+
|
|
104
|
+
@DoNotStrip
|
|
105
|
+
@Keep
|
|
106
|
+
abstract fun getStats(): GenerationStats
|
|
107
|
+
|
|
108
|
+
@DoNotStrip
|
|
109
|
+
@Keep
|
|
110
|
+
abstract fun countTokens(text: String): Double
|
|
111
|
+
|
|
112
|
+
@DoNotStrip
|
|
113
|
+
@Keep
|
|
114
|
+
abstract fun getMemoryUsage(): MemoryUsage
|
|
115
|
+
|
|
116
|
+
abstract fun execute(parts: Array<MultimodalPart>, onToken: ((token: String, done: Boolean) -> Unit)?): Promise<ExecuteResult>
|
|
117
|
+
|
|
118
|
+
@DoNotStrip
|
|
119
|
+
@Keep
|
|
120
|
+
private fun execute_cxx(parts: Array<MultimodalPart>, onToken: Func_void_std__string_bool?): Promise<ExecuteResult> {
|
|
121
|
+
val __result = execute(parts, onToken?.let { it })
|
|
122
|
+
return __result
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
abstract fun sendToolResponse(responses: Array<ToolResponse>, onToken: ((token: String, done: Boolean) -> Unit)?): Promise<ExecuteResult>
|
|
126
|
+
|
|
127
|
+
@DoNotStrip
|
|
128
|
+
@Keep
|
|
129
|
+
private fun sendToolResponse_cxx(responses: Array<ToolResponse>, onToken: Func_void_std__string_bool?): Promise<ExecuteResult> {
|
|
130
|
+
val __result = sendToolResponse(responses, onToken?.let { it })
|
|
131
|
+
return __result
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@DoNotStrip
|
|
135
|
+
@Keep
|
|
136
|
+
abstract fun getActiveBackend(): Backend
|
|
137
|
+
|
|
138
|
+
@DoNotStrip
|
|
139
|
+
@Keep
|
|
140
|
+
abstract fun stopGeneration(): Unit
|
|
141
|
+
|
|
142
|
+
@DoNotStrip
|
|
143
|
+
@Keep
|
|
144
|
+
abstract fun close(): Unit
|
|
145
|
+
|
|
146
|
+
// Default implementation of `HybridObject.toString()`
|
|
147
|
+
override fun toString(): String {
|
|
148
|
+
return "[HybridObject LiteRTLM]"
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// C++ backing class
|
|
152
|
+
@DoNotStrip
|
|
153
|
+
@Keep
|
|
154
|
+
protected open class CxxPart(javaPart: HybridLiteRTLMSpec): HybridObject.CxxPart(javaPart) {
|
|
155
|
+
// C++ JHybridLiteRTLMSpec::CxxPart::initHybrid(...)
|
|
156
|
+
external override fun initHybrid(): HybridData
|
|
157
|
+
}
|
|
158
|
+
override fun createCxxPart(): CxxPart {
|
|
159
|
+
return CxxPart(this)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
companion object {
|
|
163
|
+
protected const val TAG = "HybridLiteRTLMSpec"
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridModelStoreSpec.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
package com.margelo.nitro.dev.litert.litertlm
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
import com.margelo.nitro.core.HybridObject
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Kotlin class representing the ModelStore HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of ModelStore.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress(
|
|
23
|
+
"KotlinJniMissingFunction", "unused",
|
|
24
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
|
+
)
|
|
27
|
+
abstract class HybridModelStoreSpec: HybridObject() {
|
|
28
|
+
// Properties
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// Methods
|
|
32
|
+
@DoNotStrip
|
|
33
|
+
@Keep
|
|
34
|
+
abstract fun isCached(fileName: String): Boolean
|
|
35
|
+
|
|
36
|
+
@DoNotStrip
|
|
37
|
+
@Keep
|
|
38
|
+
abstract fun getFilePath(fileName: String): String
|
|
39
|
+
|
|
40
|
+
@DoNotStrip
|
|
41
|
+
@Keep
|
|
42
|
+
abstract fun listCachedFiles(): Array<ModelFile>
|
|
43
|
+
|
|
44
|
+
@DoNotStrip
|
|
45
|
+
@Keep
|
|
46
|
+
abstract fun deleteFile(fileName: String): Unit
|
|
47
|
+
|
|
48
|
+
abstract fun downloadFile(url: String, fileName: String, headersJson: String, onProgress: (progress: Double) -> Unit): Promise<String>
|
|
49
|
+
|
|
50
|
+
@DoNotStrip
|
|
51
|
+
@Keep
|
|
52
|
+
private fun downloadFile_cxx(url: String, fileName: String, headersJson: String, onProgress: Func_void_double): Promise<String> {
|
|
53
|
+
val __result = downloadFile(url, fileName, headersJson, onProgress)
|
|
54
|
+
return __result
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Default implementation of `HybridObject.toString()`
|
|
58
|
+
override fun toString(): String {
|
|
59
|
+
return "[HybridObject ModelStore]"
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// C++ backing class
|
|
63
|
+
@DoNotStrip
|
|
64
|
+
@Keep
|
|
65
|
+
protected open class CxxPart(javaPart: HybridModelStoreSpec): HybridObject.CxxPart(javaPart) {
|
|
66
|
+
// C++ JHybridModelStoreSpec::CxxPart::initHybrid(...)
|
|
67
|
+
external override fun initHybrid(): HybridData
|
|
68
|
+
}
|
|
69
|
+
override fun createCxxPart(): CxxPart {
|
|
70
|
+
return CxxPart(this)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
companion object {
|
|
74
|
+
protected const val TAG = "HybridModelStoreSpec"
|
|
75
|
+
}
|
|
76
|
+
}
|