react-native-litert-lm 0.3.6 → 0.4.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/README.md +207 -158
- package/android/build.gradle +12 -0
- package/android/src/main/AndroidManifest.xml +5 -0
- package/android/src/main/java/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLM.kt +316 -63
- package/android/src/main/java/dev/litert/litertlm/LiteRTLMPackage.kt +19 -2
- 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 +83 -0
- package/cpp/include/README.md +9 -11
- package/ios/HybridLiteRTLM.swift +1058 -0
- package/ios/Tests/HybridLiteRTLMTests.swift +67 -0
- package/lib/__mocks__/react-native-nitro-modules.d.ts +61 -0
- package/lib/__mocks__/react-native-nitro-modules.js +50 -0
- package/lib/__tests__/hooks.test.d.ts +1 -0
- package/lib/__tests__/hooks.test.js +124 -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 +52 -0
- package/lib/hooks.js +1 -1
- package/lib/index.d.ts +2 -4
- package/lib/index.js +12 -7
- package/lib/modelFactory.js +62 -63
- package/lib/specs/LiteRTLM.nitro.d.ts +71 -2
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.cpp +62 -7
- package/nitrogen/generated/android/c++/JHybridLiteRTLMSpec.hpp +3 -1
- package/nitrogen/generated/android/c++/JLLMConfig.hpp +40 -3
- package/nitrogen/generated/android/c++/JMultimodalPart.hpp +74 -0
- package/nitrogen/generated/android/c++/JPartType.hpp +61 -0
- package/nitrogen/generated/android/c++/JToolDefinition.hpp +65 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/GenerationStats.kt +23 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/HybridLiteRTLMSpec.kt +10 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/LLMConfig.kt +46 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MemoryUsage.kt +19 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/Message.kt +15 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/dev/litert/litertlm/MultimodalPart.kt +66 -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/ToolDefinition.kt +61 -0
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.cpp +57 -1
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Bridge.hpp +414 -3
- package/nitrogen/generated/ios/LiteRTLM-Swift-Cxx-Umbrella.hpp +41 -3
- package/nitrogen/generated/ios/LiteRTLMAutolinking.mm +4 -6
- package/nitrogen/generated/ios/LiteRTLMAutolinking.swift +10 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridLiteRTLMSpecSwift.hpp +224 -0
- package/nitrogen/generated/ios/swift/Backend.swift +44 -0
- package/nitrogen/generated/ios/swift/Func_void.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 +69 -0
- package/nitrogen/generated/ios/swift/HybridLiteRTLMSpec_cxx.swift +383 -0
- package/nitrogen/generated/ios/swift/LLMConfig.swift +203 -0
- package/nitrogen/generated/ios/swift/MemoryUsage.swift +44 -0
- package/nitrogen/generated/ios/swift/Message.swift +34 -0
- package/nitrogen/generated/ios/swift/MultimodalPart.swift +83 -0
- package/nitrogen/generated/ios/swift/PartType.swift +44 -0
- package/nitrogen/generated/ios/swift/Role.swift +44 -0
- package/nitrogen/generated/ios/swift/ToolDefinition.swift +39 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.cpp +2 -0
- package/nitrogen/generated/shared/c++/HybridLiteRTLMSpec.hpp +7 -2
- package/nitrogen/generated/shared/c++/LLMConfig.hpp +22 -2
- package/nitrogen/generated/shared/c++/MultimodalPart.hpp +99 -0
- package/nitrogen/generated/shared/c++/PartType.hpp +80 -0
- package/nitrogen/generated/shared/c++/ToolDefinition.hpp +91 -0
- package/package.json +16 -8
- package/react-native-litert-lm.podspec +15 -19
- package/scripts/download-ios-frameworks.sh +14 -48
- package/scripts/postinstall.js +1 -2
- package/src/__mocks__/react-native-nitro-modules.ts +48 -0
- package/src/__tests__/hooks.test.ts +153 -0
- package/src/__tests__/memoryTracker.test.ts +87 -0
- package/src/__tests__/modelFactory.test.ts +68 -0
- package/src/hooks.ts +1 -1
- package/src/index.ts +12 -9
- package/src/modelFactory.ts +82 -80
- package/src/specs/LiteRTLM.nitro.ts +80 -2
- package/cpp/HybridLiteRTLM.cpp +0 -838
- package/cpp/HybridLiteRTLM.hpp +0 -167
- package/cpp/IOSDownloadHelper.h +0 -24
- package/ios/IOSDownloadHelper.mm +0 -129
- package/scripts/build-ios-engine.sh +0 -302
- package/scripts/stubs/cxx_bridge_stubs.cc +0 -224
- package/scripts/stubs/gemma_model_constraint_provider.cc +0 -46
- package/scripts/stubs/llguidance_stubs.c +0 -101
- package/src/templates.ts +0 -105
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLiteRTLMSpecSwift.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 "HybridLiteRTLMSpec.hpp"
|
|
11
|
+
|
|
12
|
+
// Forward declaration of `HybridLiteRTLMSpec_cxx` to properly resolve imports.
|
|
13
|
+
namespace LiteRTLM { class HybridLiteRTLMSpec_cxx; }
|
|
14
|
+
|
|
15
|
+
// Forward declaration of `LLMConfig` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::litertlm { struct LLMConfig; }
|
|
17
|
+
// Forward declaration of `Backend` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::litertlm { enum class Backend; }
|
|
19
|
+
// Forward declaration of `ToolDefinition` to properly resolve imports.
|
|
20
|
+
namespace margelo::nitro::litertlm { struct ToolDefinition; }
|
|
21
|
+
// Forward declaration of `MultimodalPart` to properly resolve imports.
|
|
22
|
+
namespace margelo::nitro::litertlm { struct MultimodalPart; }
|
|
23
|
+
// Forward declaration of `PartType` to properly resolve imports.
|
|
24
|
+
namespace margelo::nitro::litertlm { enum class PartType; }
|
|
25
|
+
// Forward declaration of `ArrayBufferHolder` to properly resolve imports.
|
|
26
|
+
namespace NitroModules { class ArrayBufferHolder; }
|
|
27
|
+
// Forward declaration of `Message` to properly resolve imports.
|
|
28
|
+
namespace margelo::nitro::litertlm { struct Message; }
|
|
29
|
+
// Forward declaration of `Role` to properly resolve imports.
|
|
30
|
+
namespace margelo::nitro::litertlm { enum class Role; }
|
|
31
|
+
// Forward declaration of `GenerationStats` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::litertlm { struct GenerationStats; }
|
|
33
|
+
// Forward declaration of `MemoryUsage` to properly resolve imports.
|
|
34
|
+
namespace margelo::nitro::litertlm { struct MemoryUsage; }
|
|
35
|
+
|
|
36
|
+
#include <NitroModules/Promise.hpp>
|
|
37
|
+
#include <string>
|
|
38
|
+
#include "LLMConfig.hpp"
|
|
39
|
+
#include <optional>
|
|
40
|
+
#include "Backend.hpp"
|
|
41
|
+
#include "ToolDefinition.hpp"
|
|
42
|
+
#include <vector>
|
|
43
|
+
#include <functional>
|
|
44
|
+
#include "MultimodalPart.hpp"
|
|
45
|
+
#include "PartType.hpp"
|
|
46
|
+
#include <NitroModules/ArrayBuffer.hpp>
|
|
47
|
+
#include <NitroModules/ArrayBufferHolder.hpp>
|
|
48
|
+
#include "Message.hpp"
|
|
49
|
+
#include "Role.hpp"
|
|
50
|
+
#include "GenerationStats.hpp"
|
|
51
|
+
#include "MemoryUsage.hpp"
|
|
52
|
+
|
|
53
|
+
#include "LiteRTLM-Swift-Cxx-Umbrella.hpp"
|
|
54
|
+
|
|
55
|
+
namespace margelo::nitro::litertlm {
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The C++ part of HybridLiteRTLMSpec_cxx.swift.
|
|
59
|
+
*
|
|
60
|
+
* HybridLiteRTLMSpecSwift (C++) accesses HybridLiteRTLMSpec_cxx (Swift), and might
|
|
61
|
+
* contain some additional bridging code for C++ <> Swift interop.
|
|
62
|
+
*
|
|
63
|
+
* Since this obviously introduces an overhead, I hope at some point in
|
|
64
|
+
* the future, HybridLiteRTLMSpec_cxx can directly inherit from the C++ class HybridLiteRTLMSpec
|
|
65
|
+
* to simplify the whole structure and memory management.
|
|
66
|
+
*/
|
|
67
|
+
class HybridLiteRTLMSpecSwift: public virtual HybridLiteRTLMSpec {
|
|
68
|
+
public:
|
|
69
|
+
// Constructor from a Swift instance
|
|
70
|
+
explicit HybridLiteRTLMSpecSwift(const LiteRTLM::HybridLiteRTLMSpec_cxx& swiftPart):
|
|
71
|
+
HybridObject(HybridLiteRTLMSpec::TAG),
|
|
72
|
+
_swiftPart(swiftPart) { }
|
|
73
|
+
|
|
74
|
+
public:
|
|
75
|
+
// Get the Swift part
|
|
76
|
+
inline LiteRTLM::HybridLiteRTLMSpec_cxx& getSwiftPart() noexcept {
|
|
77
|
+
return _swiftPart;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public:
|
|
81
|
+
inline size_t getExternalMemorySize() noexcept override {
|
|
82
|
+
return _swiftPart.getMemorySize();
|
|
83
|
+
}
|
|
84
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override {
|
|
85
|
+
if (auto otherCast = std::dynamic_pointer_cast<HybridLiteRTLMSpecSwift>(other)) {
|
|
86
|
+
return _swiftPart.equals(otherCast->_swiftPart);
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
void dispose() noexcept override {
|
|
91
|
+
_swiftPart.dispose();
|
|
92
|
+
}
|
|
93
|
+
std::string toString() override {
|
|
94
|
+
return _swiftPart.toString();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public:
|
|
98
|
+
// Properties
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
public:
|
|
102
|
+
// Methods
|
|
103
|
+
inline std::shared_ptr<Promise<void>> loadModel(const std::string& modelPath, const std::optional<LLMConfig>& config) override {
|
|
104
|
+
auto __result = _swiftPart.loadModel(modelPath, config);
|
|
105
|
+
if (__result.hasError()) [[unlikely]] {
|
|
106
|
+
std::rethrow_exception(__result.error());
|
|
107
|
+
}
|
|
108
|
+
auto __value = std::move(__result.value());
|
|
109
|
+
return __value;
|
|
110
|
+
}
|
|
111
|
+
inline std::shared_ptr<Promise<std::string>> sendMessage(const std::string& message) override {
|
|
112
|
+
auto __result = _swiftPart.sendMessage(message);
|
|
113
|
+
if (__result.hasError()) [[unlikely]] {
|
|
114
|
+
std::rethrow_exception(__result.error());
|
|
115
|
+
}
|
|
116
|
+
auto __value = std::move(__result.value());
|
|
117
|
+
return __value;
|
|
118
|
+
}
|
|
119
|
+
inline std::shared_ptr<Promise<std::string>> sendMessageWithImage(const std::string& message, const std::string& imagePath) override {
|
|
120
|
+
auto __result = _swiftPart.sendMessageWithImage(message, imagePath);
|
|
121
|
+
if (__result.hasError()) [[unlikely]] {
|
|
122
|
+
std::rethrow_exception(__result.error());
|
|
123
|
+
}
|
|
124
|
+
auto __value = std::move(__result.value());
|
|
125
|
+
return __value;
|
|
126
|
+
}
|
|
127
|
+
inline std::shared_ptr<Promise<std::string>> downloadModel(const std::string& url, const std::string& fileName, const std::optional<std::function<void(double /* progress */)>>& onProgress) override {
|
|
128
|
+
auto __result = _swiftPart.downloadModel(url, fileName, onProgress);
|
|
129
|
+
if (__result.hasError()) [[unlikely]] {
|
|
130
|
+
std::rethrow_exception(__result.error());
|
|
131
|
+
}
|
|
132
|
+
auto __value = std::move(__result.value());
|
|
133
|
+
return __value;
|
|
134
|
+
}
|
|
135
|
+
inline std::shared_ptr<Promise<void>> deleteModel(const std::string& fileName) override {
|
|
136
|
+
auto __result = _swiftPart.deleteModel(fileName);
|
|
137
|
+
if (__result.hasError()) [[unlikely]] {
|
|
138
|
+
std::rethrow_exception(__result.error());
|
|
139
|
+
}
|
|
140
|
+
auto __value = std::move(__result.value());
|
|
141
|
+
return __value;
|
|
142
|
+
}
|
|
143
|
+
inline std::shared_ptr<Promise<std::string>> sendMessageWithAudio(const std::string& message, const std::string& audioPath) override {
|
|
144
|
+
auto __result = _swiftPart.sendMessageWithAudio(message, audioPath);
|
|
145
|
+
if (__result.hasError()) [[unlikely]] {
|
|
146
|
+
std::rethrow_exception(__result.error());
|
|
147
|
+
}
|
|
148
|
+
auto __value = std::move(__result.value());
|
|
149
|
+
return __value;
|
|
150
|
+
}
|
|
151
|
+
inline std::shared_ptr<Promise<std::string>> sendMultimodalMessage(const std::vector<MultimodalPart>& parts) override {
|
|
152
|
+
auto __result = _swiftPart.sendMultimodalMessage(parts);
|
|
153
|
+
if (__result.hasError()) [[unlikely]] {
|
|
154
|
+
std::rethrow_exception(__result.error());
|
|
155
|
+
}
|
|
156
|
+
auto __value = std::move(__result.value());
|
|
157
|
+
return __value;
|
|
158
|
+
}
|
|
159
|
+
inline std::shared_ptr<Promise<void>> sendMessageAsync(const std::string& message, const std::function<void(const std::string& /* token */, bool /* done */)>& onToken) override {
|
|
160
|
+
auto __result = _swiftPart.sendMessageAsync(message, onToken);
|
|
161
|
+
if (__result.hasError()) [[unlikely]] {
|
|
162
|
+
std::rethrow_exception(__result.error());
|
|
163
|
+
}
|
|
164
|
+
auto __value = std::move(__result.value());
|
|
165
|
+
return __value;
|
|
166
|
+
}
|
|
167
|
+
inline std::vector<Message> getHistory() override {
|
|
168
|
+
auto __result = _swiftPart.getHistory();
|
|
169
|
+
if (__result.hasError()) [[unlikely]] {
|
|
170
|
+
std::rethrow_exception(__result.error());
|
|
171
|
+
}
|
|
172
|
+
auto __value = std::move(__result.value());
|
|
173
|
+
return __value;
|
|
174
|
+
}
|
|
175
|
+
inline void resetConversation() override {
|
|
176
|
+
auto __result = _swiftPart.resetConversation();
|
|
177
|
+
if (__result.hasError()) [[unlikely]] {
|
|
178
|
+
std::rethrow_exception(__result.error());
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
inline bool isReady() override {
|
|
182
|
+
auto __result = _swiftPart.isReady();
|
|
183
|
+
if (__result.hasError()) [[unlikely]] {
|
|
184
|
+
std::rethrow_exception(__result.error());
|
|
185
|
+
}
|
|
186
|
+
auto __value = std::move(__result.value());
|
|
187
|
+
return __value;
|
|
188
|
+
}
|
|
189
|
+
inline GenerationStats getStats() override {
|
|
190
|
+
auto __result = _swiftPart.getStats();
|
|
191
|
+
if (__result.hasError()) [[unlikely]] {
|
|
192
|
+
std::rethrow_exception(__result.error());
|
|
193
|
+
}
|
|
194
|
+
auto __value = std::move(__result.value());
|
|
195
|
+
return __value;
|
|
196
|
+
}
|
|
197
|
+
inline double countTokens(const std::string& text) override {
|
|
198
|
+
auto __result = _swiftPart.countTokens(text);
|
|
199
|
+
if (__result.hasError()) [[unlikely]] {
|
|
200
|
+
std::rethrow_exception(__result.error());
|
|
201
|
+
}
|
|
202
|
+
auto __value = std::move(__result.value());
|
|
203
|
+
return __value;
|
|
204
|
+
}
|
|
205
|
+
inline MemoryUsage getMemoryUsage() override {
|
|
206
|
+
auto __result = _swiftPart.getMemoryUsage();
|
|
207
|
+
if (__result.hasError()) [[unlikely]] {
|
|
208
|
+
std::rethrow_exception(__result.error());
|
|
209
|
+
}
|
|
210
|
+
auto __value = std::move(__result.value());
|
|
211
|
+
return __value;
|
|
212
|
+
}
|
|
213
|
+
inline void close() override {
|
|
214
|
+
auto __result = _swiftPart.close();
|
|
215
|
+
if (__result.hasError()) [[unlikely]] {
|
|
216
|
+
std::rethrow_exception(__result.error());
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private:
|
|
221
|
+
LiteRTLM::HybridLiteRTLMSpec_cxx _swiftPart;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
} // namespace margelo::nitro::litertlm
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Backend.swift
|
|
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
|
+
/**
|
|
9
|
+
* Represents the JS union `Backend`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias Backend = margelo.nitro.litertlm.Backend
|
|
12
|
+
|
|
13
|
+
public extension Backend {
|
|
14
|
+
/**
|
|
15
|
+
* Get a Backend for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "cpu":
|
|
21
|
+
self = .cpu
|
|
22
|
+
case "gpu":
|
|
23
|
+
self = .gpu
|
|
24
|
+
case "npu":
|
|
25
|
+
self = .npu
|
|
26
|
+
default:
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the String value this Backend represents.
|
|
33
|
+
*/
|
|
34
|
+
var stringValue: String {
|
|
35
|
+
switch self {
|
|
36
|
+
case .cpu:
|
|
37
|
+
return "cpu"
|
|
38
|
+
case .gpu:
|
|
39
|
+
return "gpu"
|
|
40
|
+
case .npu:
|
|
41
|
+
return "npu"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `() -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void {
|
|
15
|
+
public typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: () -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping () -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call() -> Void {
|
|
25
|
+
self.closure()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void {
|
|
44
|
+
return Unmanaged<Func_void>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_double.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ progress: Double) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_double {
|
|
15
|
+
public typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ progress: Double) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ progress: Double) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(progress: Double) -> Void {
|
|
25
|
+
self.closure(progress)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_double`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_double>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_double {
|
|
44
|
+
return Unmanaged<Func_void_double>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__exception_ptr.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ error: Error) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__exception_ptr {
|
|
15
|
+
public typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ error: Error) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ error: Error) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(error: std.exception_ptr) -> Void {
|
|
25
|
+
self.closure(RuntimeError.from(cppError: error))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__exception_ptr`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__exception_ptr>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__exception_ptr {
|
|
44
|
+
return Unmanaged<Func_void_std__exception_ptr>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: String) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__string {
|
|
15
|
+
public typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: String) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: String) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: std.string) -> Void {
|
|
25
|
+
self.closure(String(value))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__string`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__string>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string {
|
|
44
|
+
return Unmanaged<Func_void_std__string>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__string_bool.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ token: String, _ done: Bool) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__string_bool {
|
|
15
|
+
public typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ token: String, _ done: Bool) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ token: String, _ done: Bool) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(token: std.string, done: Bool) -> Void {
|
|
25
|
+
self.closure(String(token), done)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
30
|
+
* This acquires one additional strong reference on the object!
|
|
31
|
+
*/
|
|
32
|
+
@inline(__always)
|
|
33
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
34
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Casts an unsafe pointer to a `Func_void_std__string_bool`.
|
|
39
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__string_bool>`.
|
|
40
|
+
* This removes one strong reference from the object!
|
|
41
|
+
*/
|
|
42
|
+
@inline(__always)
|
|
43
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__string_bool {
|
|
44
|
+
return Unmanaged<Func_void_std__string_bool>.fromOpaque(pointer).takeRetainedValue()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// GenerationStats.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents an instance of `GenerationStats`, backed by a C++ struct.
|
|
12
|
+
*/
|
|
13
|
+
public typealias GenerationStats = margelo.nitro.litertlm.GenerationStats
|
|
14
|
+
|
|
15
|
+
public extension GenerationStats {
|
|
16
|
+
private typealias bridge = margelo.nitro.litertlm.bridge.swift
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `GenerationStats`.
|
|
20
|
+
*/
|
|
21
|
+
init(promptTokens: Double, completionTokens: Double, totalTokens: Double, timeToFirstToken: Double, totalTime: Double, tokensPerSecond: Double) {
|
|
22
|
+
self.init(promptTokens, completionTokens, totalTokens, timeToFirstToken, totalTime, tokensPerSecond)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@inline(__always)
|
|
26
|
+
var promptTokens: Double {
|
|
27
|
+
return self.__promptTokens
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@inline(__always)
|
|
31
|
+
var completionTokens: Double {
|
|
32
|
+
return self.__completionTokens
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@inline(__always)
|
|
36
|
+
var totalTokens: Double {
|
|
37
|
+
return self.__totalTokens
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@inline(__always)
|
|
41
|
+
var timeToFirstToken: Double {
|
|
42
|
+
return self.__timeToFirstToken
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@inline(__always)
|
|
46
|
+
var totalTime: Double {
|
|
47
|
+
return self.__totalTime
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@inline(__always)
|
|
51
|
+
var tokensPerSecond: Double {
|
|
52
|
+
return self.__tokensPerSecond
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridLiteRTLMSpec.swift
|
|
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
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/// See ``HybridLiteRTLMSpec``
|
|
11
|
+
public protocol HybridLiteRTLMSpec_protocol: HybridObject {
|
|
12
|
+
// Properties
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
// Methods
|
|
16
|
+
func loadModel(modelPath: String, config: LLMConfig?) throws -> Promise<Void>
|
|
17
|
+
func sendMessage(message: String) throws -> Promise<String>
|
|
18
|
+
func sendMessageWithImage(message: String, imagePath: String) throws -> Promise<String>
|
|
19
|
+
func downloadModel(url: String, fileName: String, onProgress: ((_ progress: Double) -> Void)?) throws -> Promise<String>
|
|
20
|
+
func deleteModel(fileName: String) throws -> Promise<Void>
|
|
21
|
+
func sendMessageWithAudio(message: String, audioPath: String) throws -> Promise<String>
|
|
22
|
+
func sendMultimodalMessage(parts: [MultimodalPart]) throws -> Promise<String>
|
|
23
|
+
func sendMessageAsync(message: String, onToken: @escaping (_ token: String, _ done: Bool) -> Void) throws -> Promise<Void>
|
|
24
|
+
func getHistory() throws -> [Message]
|
|
25
|
+
func resetConversation() throws -> Void
|
|
26
|
+
func isReady() throws -> Bool
|
|
27
|
+
func getStats() throws -> GenerationStats
|
|
28
|
+
func countTokens(text: String) throws -> Double
|
|
29
|
+
func getMemoryUsage() throws -> MemoryUsage
|
|
30
|
+
func close() throws -> Void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public extension HybridLiteRTLMSpec_protocol {
|
|
34
|
+
/// Default implementation of ``HybridObject.toString``
|
|
35
|
+
func toString() -> String {
|
|
36
|
+
return "[HybridObject LiteRTLM]"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// See ``HybridLiteRTLMSpec``
|
|
41
|
+
open class HybridLiteRTLMSpec_base {
|
|
42
|
+
private weak var cxxWrapper: HybridLiteRTLMSpec_cxx? = nil
|
|
43
|
+
public init() { }
|
|
44
|
+
public func getCxxWrapper() -> HybridLiteRTLMSpec_cxx {
|
|
45
|
+
#if DEBUG
|
|
46
|
+
guard self is any HybridLiteRTLMSpec else {
|
|
47
|
+
fatalError("`self` is not a `HybridLiteRTLMSpec`! Did you accidentally inherit from `HybridLiteRTLMSpec_base` instead of `HybridLiteRTLMSpec`?")
|
|
48
|
+
}
|
|
49
|
+
#endif
|
|
50
|
+
if let cxxWrapper = self.cxxWrapper {
|
|
51
|
+
return cxxWrapper
|
|
52
|
+
} else {
|
|
53
|
+
let cxxWrapper = HybridLiteRTLMSpec_cxx(self as! any HybridLiteRTLMSpec)
|
|
54
|
+
self.cxxWrapper = cxxWrapper
|
|
55
|
+
return cxxWrapper
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A Swift base-protocol representing the LiteRTLM HybridObject.
|
|
62
|
+
* Implement this protocol to create Swift-based instances of LiteRTLM.
|
|
63
|
+
* ```swift
|
|
64
|
+
* class HybridLiteRTLM : HybridLiteRTLMSpec {
|
|
65
|
+
* // ...
|
|
66
|
+
* }
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
public typealias HybridLiteRTLMSpec = HybridLiteRTLMSpec_protocol & HybridLiteRTLMSpec_base
|