cui-llama.rn 0.2.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 (76) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +330 -0
  3. package/android/build.gradle +107 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +4 -0
  6. package/android/src/main/CMakeLists.txt +69 -0
  7. package/android/src/main/java/com/rnllama/LlamaContext.java +353 -0
  8. package/android/src/main/java/com/rnllama/RNLlama.java +446 -0
  9. package/android/src/main/java/com/rnllama/RNLlamaPackage.java +48 -0
  10. package/android/src/main/jni.cpp +635 -0
  11. package/android/src/newarch/java/com/rnllama/RNLlamaModule.java +94 -0
  12. package/android/src/oldarch/java/com/rnllama/RNLlamaModule.java +95 -0
  13. package/cpp/README.md +4 -0
  14. package/cpp/common.cpp +3237 -0
  15. package/cpp/common.h +467 -0
  16. package/cpp/ggml-aarch64.c +2193 -0
  17. package/cpp/ggml-aarch64.h +39 -0
  18. package/cpp/ggml-alloc.c +1041 -0
  19. package/cpp/ggml-alloc.h +76 -0
  20. package/cpp/ggml-backend-impl.h +153 -0
  21. package/cpp/ggml-backend.c +2225 -0
  22. package/cpp/ggml-backend.h +236 -0
  23. package/cpp/ggml-common.h +1829 -0
  24. package/cpp/ggml-impl.h +655 -0
  25. package/cpp/ggml-metal.h +65 -0
  26. package/cpp/ggml-metal.m +3273 -0
  27. package/cpp/ggml-quants.c +15022 -0
  28. package/cpp/ggml-quants.h +132 -0
  29. package/cpp/ggml.c +22034 -0
  30. package/cpp/ggml.h +2444 -0
  31. package/cpp/grammar-parser.cpp +536 -0
  32. package/cpp/grammar-parser.h +29 -0
  33. package/cpp/json-schema-to-grammar.cpp +1045 -0
  34. package/cpp/json-schema-to-grammar.h +8 -0
  35. package/cpp/json.hpp +24766 -0
  36. package/cpp/llama.cpp +21789 -0
  37. package/cpp/llama.h +1201 -0
  38. package/cpp/log.h +737 -0
  39. package/cpp/rn-llama.hpp +630 -0
  40. package/cpp/sampling.cpp +460 -0
  41. package/cpp/sampling.h +160 -0
  42. package/cpp/sgemm.cpp +1027 -0
  43. package/cpp/sgemm.h +14 -0
  44. package/cpp/unicode-data.cpp +7032 -0
  45. package/cpp/unicode-data.h +20 -0
  46. package/cpp/unicode.cpp +812 -0
  47. package/cpp/unicode.h +64 -0
  48. package/ios/RNLlama.h +11 -0
  49. package/ios/RNLlama.mm +302 -0
  50. package/ios/RNLlama.xcodeproj/project.pbxproj +278 -0
  51. package/ios/RNLlamaContext.h +39 -0
  52. package/ios/RNLlamaContext.mm +426 -0
  53. package/jest/mock.js +169 -0
  54. package/lib/commonjs/NativeRNLlama.js +10 -0
  55. package/lib/commonjs/NativeRNLlama.js.map +1 -0
  56. package/lib/commonjs/grammar.js +574 -0
  57. package/lib/commonjs/grammar.js.map +1 -0
  58. package/lib/commonjs/index.js +151 -0
  59. package/lib/commonjs/index.js.map +1 -0
  60. package/lib/module/NativeRNLlama.js +3 -0
  61. package/lib/module/NativeRNLlama.js.map +1 -0
  62. package/lib/module/grammar.js +566 -0
  63. package/lib/module/grammar.js.map +1 -0
  64. package/lib/module/index.js +129 -0
  65. package/lib/module/index.js.map +1 -0
  66. package/lib/typescript/NativeRNLlama.d.ts +107 -0
  67. package/lib/typescript/NativeRNLlama.d.ts.map +1 -0
  68. package/lib/typescript/grammar.d.ts +38 -0
  69. package/lib/typescript/grammar.d.ts.map +1 -0
  70. package/lib/typescript/index.d.ts +46 -0
  71. package/lib/typescript/index.d.ts.map +1 -0
  72. package/llama-rn.podspec +56 -0
  73. package/package.json +230 -0
  74. package/src/NativeRNLlama.ts +132 -0
  75. package/src/grammar.ts +849 -0
  76. package/src/index.ts +182 -0
package/cpp/unicode.h ADDED
@@ -0,0 +1,64 @@
1
+ #pragma once
2
+
3
+ #include <cstdint>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ struct codepoint_flags {
8
+ enum {
9
+ UNDEFINED = 0x0001,
10
+ NUMBER = 0x0002, // regex: \p{N}
11
+ LETTER = 0x0004, // regex: \p{L}
12
+ SEPARATOR = 0x0008, // regex: \p{Z}
13
+ ACCENT_MARK = 0x0010, // regex: \p{M}
14
+ PUNCTUATION = 0x0020, // regex: \p{P}
15
+ SYMBOL = 0x0040, // regex: \p{S}
16
+ CONTROL = 0x0080, // regex: \p{C}
17
+ MASK_CATEGORIES = 0x00FF,
18
+ };
19
+
20
+ // codepoint type
21
+ uint16_t is_undefined : 1;
22
+ uint16_t is_number : 1; // regex: \p{N}
23
+ uint16_t is_letter : 1; // regex: \p{L}
24
+ uint16_t is_separator : 1; // regex: \p{Z}
25
+ uint16_t is_accent_mark : 1; // regex: \p{M}
26
+ uint16_t is_punctuation : 1; // regex: \p{P}
27
+ uint16_t is_symbol : 1; // regex: \p{S}
28
+ uint16_t is_control : 1; // regex: \p{C}
29
+ // helper flags
30
+ uint16_t is_whitespace : 1; // regex: \s
31
+ uint16_t is_lowercase : 1;
32
+ uint16_t is_uppercase : 1;
33
+ uint16_t is_nfd : 1;
34
+
35
+ // decode from uint16
36
+ inline codepoint_flags(const uint16_t flags=0) {
37
+ *reinterpret_cast<uint16_t*>(this) = flags;
38
+ }
39
+
40
+ inline uint16_t as_uint() const {
41
+ return *reinterpret_cast<const uint16_t*>(this);
42
+ }
43
+
44
+ inline uint16_t category_flag() const {
45
+ return this->as_uint() & MASK_CATEGORIES;
46
+ }
47
+ };
48
+
49
+
50
+ std::string unicode_cpt_to_utf8(uint32_t cp);
51
+ uint32_t unicode_cpt_from_utf8(const std::string & utf8, size_t & offset);
52
+ std::vector<uint32_t> unicode_cpts_from_utf8(const std::string & utf8);
53
+
54
+ std::vector<uint32_t> unicode_cpts_normalize_nfd(const std::vector<uint32_t> & cpts);
55
+
56
+ codepoint_flags unicode_cpt_flags(const uint32_t cp);
57
+ codepoint_flags unicode_cpt_flags(const std::string & utf8);
58
+
59
+ std::string unicode_byte_to_utf8(uint8_t byte);
60
+ uint8_t unicode_utf8_to_byte(const std::string & utf8);
61
+
62
+ uint32_t unicode_tolower(uint32_t cp);
63
+
64
+ std::vector<std::string> unicode_regex_split(const std::string & text, const std::vector<std::string> & regex_exprs);
package/ios/RNLlama.h ADDED
@@ -0,0 +1,11 @@
1
+ #ifdef __cplusplus
2
+ #import "rn-llama.hpp"
3
+ #endif
4
+
5
+ #import <React/RCTEventEmitter.h>
6
+ #import <React/RCTBridgeModule.h>
7
+
8
+ // TODO: Use RNLlamaSpec (Need to refactor NSDictionary usage)
9
+ @interface RNLlama : RCTEventEmitter <RCTBridgeModule>
10
+
11
+ @end
package/ios/RNLlama.mm ADDED
@@ -0,0 +1,302 @@
1
+ #import "RNLlama.h"
2
+ #import "RNLlamaContext.h"
3
+
4
+ #ifdef RCT_NEW_ARCH_ENABLED
5
+ #import "RNLlamaSpec.h"
6
+ #endif
7
+
8
+ @implementation RNLlama
9
+
10
+ NSMutableDictionary *llamaContexts;
11
+ double llamaContextLimit = 1;
12
+ dispatch_queue_t llamaDQueue;
13
+
14
+ RCT_EXPORT_MODULE()
15
+
16
+ RCT_EXPORT_METHOD(setContextLimit:(double)limit
17
+ withResolver:(RCTPromiseResolveBlock)resolve
18
+ withRejecter:(RCTPromiseRejectBlock)reject)
19
+ {
20
+ llamaContextLimit = limit;
21
+ resolve(nil);
22
+ }
23
+
24
+ RCT_EXPORT_METHOD(initContext:(NSDictionary *)contextParams
25
+ withResolver:(RCTPromiseResolveBlock)resolve
26
+ withRejecter:(RCTPromiseRejectBlock)reject)
27
+ {
28
+ if (llamaDQueue == nil) {
29
+ llamaDQueue = dispatch_queue_create("com.rnllama", DISPATCH_QUEUE_SERIAL);
30
+ }
31
+
32
+ if (llamaContexts == nil) {
33
+ llamaContexts = [[NSMutableDictionary alloc] init];
34
+ }
35
+
36
+ if (llamaContextLimit > 0 && [llamaContexts count] >= llamaContextLimit) {
37
+ reject(@"llama_error", @"Context limit reached", nil);
38
+ return;
39
+ }
40
+
41
+ RNLlamaContext *context = [RNLlamaContext initWithParams:contextParams];
42
+ if (![context isModelLoaded]) {
43
+ reject(@"llama_cpp_error", @"Failed to load the model", nil);
44
+ return;
45
+ }
46
+
47
+ double contextId = (double) arc4random_uniform(1000000);
48
+
49
+ NSNumber *contextIdNumber = [NSNumber numberWithDouble:contextId];
50
+ [llamaContexts setObject:context forKey:contextIdNumber];
51
+
52
+ resolve(@{
53
+ @"contextId": contextIdNumber,
54
+ @"gpu": @([context isMetalEnabled]),
55
+ @"reasonNoGPU": [context reasonNoMetal],
56
+ @"model": @{
57
+ @"desc": [context modelDesc],
58
+ @"size": @([context modelSize]),
59
+ @"nParams": @([context modelNParams]),
60
+ @"metadata": [context metadata],
61
+ }
62
+ });
63
+ }
64
+
65
+ RCT_EXPORT_METHOD(loadSession:(double)contextId
66
+ withFilePath:(NSString *)filePath
67
+ withResolver:(RCTPromiseResolveBlock)resolve
68
+ withRejecter:(RCTPromiseRejectBlock)reject)
69
+ {
70
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
71
+ if (context == nil) {
72
+ reject(@"llama_error", @"Context not found", nil);
73
+ return;
74
+ }
75
+ if ([context isPredicting]) {
76
+ reject(@"llama_error", @"Context is busy", nil);
77
+ return;
78
+ }
79
+ dispatch_async(llamaDQueue, ^{
80
+ @try {
81
+ @autoreleasepool {
82
+ resolve([context loadSession:filePath]);
83
+ }
84
+ } @catch (NSException *exception) {
85
+ reject(@"llama_cpp_error", exception.reason, nil);
86
+ }
87
+ });
88
+ }
89
+
90
+ RCT_EXPORT_METHOD(saveSession:(double)contextId
91
+ withFilePath:(NSString *)filePath
92
+ withSize:(double)size
93
+ withResolver:(RCTPromiseResolveBlock)resolve
94
+ withRejecter:(RCTPromiseRejectBlock)reject)
95
+ {
96
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
97
+ if (context == nil) {
98
+ reject(@"llama_error", @"Context not found", nil);
99
+ return;
100
+ }
101
+ if ([context isPredicting]) {
102
+ reject(@"llama_error", @"Context is busy", nil);
103
+ return;
104
+ }
105
+ dispatch_async(llamaDQueue, ^{
106
+ @try {
107
+ @autoreleasepool {
108
+ int count = [context saveSession:filePath size:(int)size];
109
+ resolve(@(count));
110
+ }
111
+ } @catch (NSException *exception) {
112
+ reject(@"llama_cpp_error", exception.reason, nil);
113
+ }
114
+ });
115
+ }
116
+
117
+ - (NSArray *)supportedEvents {
118
+ return@[
119
+ @"@RNLlama_onToken",
120
+ ];
121
+ }
122
+
123
+ RCT_EXPORT_METHOD(completion:(double)contextId
124
+ withCompletionParams:(NSDictionary *)completionParams
125
+ withResolver:(RCTPromiseResolveBlock)resolve
126
+ withRejecter:(RCTPromiseRejectBlock)reject)
127
+ {
128
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
129
+ if (context == nil) {
130
+ reject(@"llama_error", @"Context not found", nil);
131
+ return;
132
+ }
133
+ if ([context isPredicting]) {
134
+ reject(@"llama_error", @"Context is busy", nil);
135
+ return;
136
+ }
137
+ dispatch_async(llamaDQueue, ^{
138
+ @try {
139
+ @autoreleasepool {
140
+ NSDictionary* completionResult = [context completion:completionParams
141
+ onToken:^(NSMutableDictionary *tokenResult) {
142
+ if (![completionParams[@"emit_partial_completion"] boolValue]) return;
143
+ dispatch_async(dispatch_get_main_queue(), ^{
144
+ [self sendEventWithName:@"@RNLlama_onToken"
145
+ body:@{
146
+ @"contextId": [NSNumber numberWithDouble:contextId],
147
+ @"tokenResult": tokenResult
148
+ }
149
+ ];
150
+ [tokenResult release];
151
+ });
152
+ }
153
+ ];
154
+ resolve(completionResult);
155
+ }
156
+ } @catch (NSException *exception) {
157
+ reject(@"llama_cpp_error", exception.reason, nil);
158
+ [context stopCompletion];
159
+ }
160
+ });
161
+
162
+ }
163
+
164
+ RCT_EXPORT_METHOD(stopCompletion:(double)contextId
165
+ withResolver:(RCTPromiseResolveBlock)resolve
166
+ withRejecter:(RCTPromiseRejectBlock)reject)
167
+ {
168
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
169
+ if (context == nil) {
170
+ reject(@"llama_error", @"Context not found", nil);
171
+ return;
172
+ }
173
+ [context stopCompletion];
174
+ resolve(nil);
175
+ }
176
+
177
+ RCT_EXPORT_METHOD(tokenize:(double)contextId
178
+ text:(NSString *)text
179
+ withResolver:(RCTPromiseResolveBlock)resolve
180
+ withRejecter:(RCTPromiseRejectBlock)reject)
181
+ {
182
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
183
+ if (context == nil) {
184
+ reject(@"llama_error", @"Context not found", nil);
185
+ return;
186
+ }
187
+ NSMutableArray *tokens = [context tokenize:text];
188
+ resolve(@{ @"tokens": tokens });
189
+ [tokens release];
190
+ }
191
+
192
+ RCT_EXPORT_METHOD(detokenize:(double)contextId
193
+ tokens:(NSArray *)tokens
194
+ withResolver:(RCTPromiseResolveBlock)resolve
195
+ withRejecter:(RCTPromiseRejectBlock)reject)
196
+ {
197
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
198
+ if (context == nil) {
199
+ reject(@"llama_error", @"Context not found", nil);
200
+ return;
201
+ }
202
+ resolve([context detokenize:tokens]);
203
+ }
204
+
205
+ RCT_EXPORT_METHOD(embedding:(double)contextId
206
+ text:(NSString *)text
207
+ withResolver:(RCTPromiseResolveBlock)resolve
208
+ withRejecter:(RCTPromiseRejectBlock)reject)
209
+ {
210
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
211
+ if (context == nil) {
212
+ reject(@"llama_error", @"Context not found", nil);
213
+ return;
214
+ }
215
+ @try {
216
+ NSMutableArray *embedding = [context embedding:text];
217
+ resolve(@{ @"embedding": embedding });
218
+ [embedding release];
219
+ } @catch (NSException *exception) {
220
+ reject(@"llama_cpp_error", exception.reason, nil);
221
+ }
222
+ }
223
+
224
+ RCT_EXPORT_METHOD(bench:(double)contextId
225
+ pp:(int)pp
226
+ tg:(int)tg
227
+ pl:(int)pl
228
+ nr:(int)nr
229
+ withResolver:(RCTPromiseResolveBlock)resolve
230
+ withRejecter:(RCTPromiseRejectBlock)reject)
231
+ {
232
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
233
+ if (context == nil) {
234
+ reject(@"llama_error", @"Context not found", nil);
235
+ return;
236
+ }
237
+ @try {
238
+ NSString *benchResults = [context bench:pp tg:tg pl:pl nr:nr];
239
+ resolve(benchResults);
240
+ } @catch (NSException *exception) {
241
+ reject(@"llama_cpp_error", exception.reason, nil);
242
+ }
243
+ }
244
+
245
+ RCT_EXPORT_METHOD(releaseContext:(double)contextId
246
+ withResolver:(RCTPromiseResolveBlock)resolve
247
+ withRejecter:(RCTPromiseRejectBlock)reject)
248
+ {
249
+ RNLlamaContext *context = llamaContexts[[NSNumber numberWithDouble:contextId]];
250
+ if (context == nil) {
251
+ reject(@"llama_error", @"Context not found", nil);
252
+ return;
253
+ }
254
+ [context stopCompletion];
255
+ dispatch_barrier_sync(llamaDQueue, ^{});
256
+ [context invalidate];
257
+ [llamaContexts removeObjectForKey:[NSNumber numberWithDouble:contextId]];
258
+ resolve(nil);
259
+ }
260
+
261
+ RCT_EXPORT_METHOD(releaseAllContexts:(RCTPromiseResolveBlock)resolve
262
+ withRejecter:(RCTPromiseRejectBlock)reject)
263
+ {
264
+ [self invalidate];
265
+ resolve(nil);
266
+ }
267
+
268
+
269
+ - (void)invalidate {
270
+ if (llamaContexts == nil) {
271
+ return;
272
+ }
273
+
274
+ for (NSNumber *contextId in llamaContexts) {
275
+ RNLlamaContext *context = llamaContexts[contextId];
276
+ [context stopCompletion];
277
+ dispatch_barrier_sync(llamaDQueue, ^{});
278
+ [context invalidate];
279
+ }
280
+
281
+ [llamaContexts removeAllObjects];
282
+ [llamaContexts release];
283
+ llamaContexts = nil;
284
+
285
+ if (llamaDQueue != nil) {
286
+ dispatch_release(llamaDQueue);
287
+ llamaDQueue = nil;
288
+ }
289
+
290
+ [super invalidate];
291
+ }
292
+
293
+ // Don't compile this code when we build for the old architecture.
294
+ #ifdef RCT_NEW_ARCH_ENABLED
295
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
296
+ (const facebook::react::ObjCTurboModule::InitParams &)params
297
+ {
298
+ return std::make_shared<facebook::react::NativeRNLlamaSpecJSI>(params);
299
+ }
300
+ #endif
301
+
302
+ @end
@@ -0,0 +1,278 @@
1
+ // !$*UTF8*$!
2
+ {
3
+ archiveVersion = 1;
4
+ classes = {
5
+ };
6
+ objectVersion = 46;
7
+ objects = {
8
+
9
+ /* Begin PBXBuildFile section */
10
+ 5E46D8CD2428F78900513E24 /* rn-llama.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5E46D8CB2428F78900513E24 /* rn-llama.cpp */; };
11
+ 5E555C0D2413F4C50049A1A2 /* RNLlama in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* RNLlama */; };
12
+ /* End PBXBuildFile section */
13
+
14
+ /* Begin PBXCopyFilesBuildPhase section */
15
+ 58B511D91A9E6C8500147676 /* CopyFiles */ = {
16
+ isa = PBXCopyFilesBuildPhase;
17
+ buildActionMask = 2147483647;
18
+ dstPath = "include/$(PRODUCT_NAME)";
19
+ dstSubfolderSpec = 16;
20
+ files = (
21
+ );
22
+ runOnlyForDeploymentPostprocessing = 0;
23
+ };
24
+ /* End PBXCopyFilesBuildPhase section */
25
+
26
+ /* Begin PBXFileReference section */
27
+ 134814201AA4EA6300B7C361 /* libLlama.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLlama.a; sourceTree = BUILT_PRODUCTS_DIR; };
28
+ 5E46D8CB2428F78900513E24 /* rn-llama.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = rn-llama.cpp; path = ../cpp/rn-llama.cpp; sourceTree = "<group>"; };
29
+ 5E46D8CC2428F78900513E24 /* rn-llama.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = rn-llama.h; path = ../cpp/rn-llama.h; sourceTree = "<group>"; };
30
+ B3E7B5891CC2AC0600A0062D /* RNLlama */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RNLlama; sourceTree = "<group>"; };
31
+ /* End PBXFileReference section */
32
+
33
+ /* Begin PBXFrameworksBuildPhase section */
34
+ 58B511D81A9E6C8500147676 /* Frameworks */ = {
35
+ isa = PBXFrameworksBuildPhase;
36
+ buildActionMask = 2147483647;
37
+ files = (
38
+ );
39
+ runOnlyForDeploymentPostprocessing = 0;
40
+ };
41
+ /* End PBXFrameworksBuildPhase section */
42
+
43
+ /* Begin PBXGroup section */
44
+ 134814211AA4EA7D00B7C361 /* Products */ = {
45
+ isa = PBXGroup;
46
+ children = (
47
+ 134814201AA4EA6300B7C361 /* libLlama.a */,
48
+ );
49
+ name = Products;
50
+ sourceTree = "<group>";
51
+ };
52
+ 58B511D21A9E6C8500147676 = {
53
+ isa = PBXGroup;
54
+ children = (
55
+ 5E46D8CB2428F78900513E24 /* rn-llama.cpp */,
56
+ 5E46D8CC2428F78900513E24 /* rn-llama.h */,
57
+ B3E7B5891CC2AC0600A0062D /* RNLlama */,
58
+ 134814211AA4EA7D00B7C361 /* Products */,
59
+ );
60
+ sourceTree = "<group>";
61
+ };
62
+ /* End PBXGroup section */
63
+
64
+ /* Begin PBXNativeTarget section */
65
+ 58B511DA1A9E6C8500147676 /* Llama */ = {
66
+ isa = PBXNativeTarget;
67
+ buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Llama" */;
68
+ buildPhases = (
69
+ 58B511D71A9E6C8500147676 /* Sources */,
70
+ 58B511D81A9E6C8500147676 /* Frameworks */,
71
+ 58B511D91A9E6C8500147676 /* CopyFiles */,
72
+ );
73
+ buildRules = (
74
+ );
75
+ dependencies = (
76
+ );
77
+ name = Llama;
78
+ productName = RCTDataManager;
79
+ productReference = 134814201AA4EA6300B7C361 /* libLlama.a */;
80
+ productType = "com.apple.product-type.library.static";
81
+ };
82
+ /* End PBXNativeTarget section */
83
+
84
+ /* Begin PBXProject section */
85
+ 58B511D31A9E6C8500147676 /* Project object */ = {
86
+ isa = PBXProject;
87
+ attributes = {
88
+ LastUpgradeCheck = 0920;
89
+ ORGANIZATIONNAME = Facebook;
90
+ TargetAttributes = {
91
+ 58B511DA1A9E6C8500147676 = {
92
+ CreatedOnToolsVersion = 6.1.1;
93
+ };
94
+ };
95
+ };
96
+ buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Llama" */;
97
+ compatibilityVersion = "Xcode 3.2";
98
+ developmentRegion = English;
99
+ hasScannedForEncodings = 0;
100
+ knownRegions = (
101
+ English,
102
+ en,
103
+ );
104
+ mainGroup = 58B511D21A9E6C8500147676;
105
+ productRefGroup = 58B511D21A9E6C8500147676;
106
+ projectDirPath = "";
107
+ projectRoot = "";
108
+ targets = (
109
+ 58B511DA1A9E6C8500147676 /* Llama */,
110
+ );
111
+ };
112
+ /* End PBXProject section */
113
+
114
+ /* Begin PBXSourcesBuildPhase section */
115
+ 58B511D71A9E6C8500147676 /* Sources */ = {
116
+ isa = PBXSourcesBuildPhase;
117
+ buildActionMask = 2147483647;
118
+ files = (
119
+ 5E46D8CD2428F78900513E24 /* rn-llama.cpp in Sources */,
120
+ 5E555C0D2413F4C50049A1A2 /* RNLlama in Sources */,
121
+ );
122
+ runOnlyForDeploymentPostprocessing = 0;
123
+ };
124
+ /* End PBXSourcesBuildPhase section */
125
+
126
+ /* Begin XCBuildConfiguration section */
127
+ 58B511ED1A9E6C8500147676 /* Debug */ = {
128
+ isa = XCBuildConfiguration;
129
+ buildSettings = {
130
+ ALWAYS_SEARCH_USER_PATHS = NO;
131
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
132
+ CLANG_CXX_LIBRARY = "libc++";
133
+ CLANG_ENABLE_MODULES = YES;
134
+ CLANG_ENABLE_OBJC_ARC = YES;
135
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
136
+ CLANG_WARN_BOOL_CONVERSION = YES;
137
+ CLANG_WARN_COMMA = YES;
138
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
139
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
140
+ CLANG_WARN_EMPTY_BODY = YES;
141
+ CLANG_WARN_ENUM_CONVERSION = YES;
142
+ CLANG_WARN_INFINITE_RECURSION = YES;
143
+ CLANG_WARN_INT_CONVERSION = YES;
144
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
145
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
146
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
147
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
148
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
149
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
150
+ CLANG_WARN_UNREACHABLE_CODE = YES;
151
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
152
+ COPY_PHASE_STRIP = NO;
153
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
154
+ ENABLE_TESTABILITY = YES;
155
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
156
+ GCC_C_LANGUAGE_STANDARD = gnu99;
157
+ GCC_DYNAMIC_NO_PIC = NO;
158
+ GCC_NO_COMMON_BLOCKS = YES;
159
+ GCC_OPTIMIZATION_LEVEL = 0;
160
+ GCC_PREPROCESSOR_DEFINITIONS = (
161
+ "DEBUG=1",
162
+ "$(inherited)",
163
+ );
164
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
165
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
166
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
167
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
168
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
169
+ GCC_WARN_UNUSED_FUNCTION = YES;
170
+ GCC_WARN_UNUSED_VARIABLE = YES;
171
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
172
+ MTL_ENABLE_DEBUG_INFO = YES;
173
+ ONLY_ACTIVE_ARCH = YES;
174
+ SDKROOT = iphoneos;
175
+ };
176
+ name = Debug;
177
+ };
178
+ 58B511EE1A9E6C8500147676 /* Release */ = {
179
+ isa = XCBuildConfiguration;
180
+ buildSettings = {
181
+ ALWAYS_SEARCH_USER_PATHS = NO;
182
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
183
+ CLANG_CXX_LIBRARY = "libc++";
184
+ CLANG_ENABLE_MODULES = YES;
185
+ CLANG_ENABLE_OBJC_ARC = YES;
186
+ CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
187
+ CLANG_WARN_BOOL_CONVERSION = YES;
188
+ CLANG_WARN_COMMA = YES;
189
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
190
+ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
191
+ CLANG_WARN_EMPTY_BODY = YES;
192
+ CLANG_WARN_ENUM_CONVERSION = YES;
193
+ CLANG_WARN_INFINITE_RECURSION = YES;
194
+ CLANG_WARN_INT_CONVERSION = YES;
195
+ CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
196
+ CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
197
+ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
198
+ CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
199
+ CLANG_WARN_STRICT_PROTOTYPES = YES;
200
+ CLANG_WARN_SUSPICIOUS_MOVE = YES;
201
+ CLANG_WARN_UNREACHABLE_CODE = YES;
202
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
203
+ COPY_PHASE_STRIP = YES;
204
+ ENABLE_NS_ASSERTIONS = NO;
205
+ ENABLE_STRICT_OBJC_MSGSEND = YES;
206
+ "EXCLUDED_ARCHS[sdk=*]" = arm64;
207
+ GCC_C_LANGUAGE_STANDARD = gnu99;
208
+ GCC_NO_COMMON_BLOCKS = YES;
209
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
210
+ GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
211
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
212
+ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
213
+ GCC_WARN_UNUSED_FUNCTION = YES;
214
+ GCC_WARN_UNUSED_VARIABLE = YES;
215
+ IPHONEOS_DEPLOYMENT_TARGET = 8.0;
216
+ MTL_ENABLE_DEBUG_INFO = NO;
217
+ SDKROOT = iphoneos;
218
+ VALIDATE_PRODUCT = YES;
219
+ };
220
+ name = Release;
221
+ };
222
+ 58B511F01A9E6C8500147676 /* Debug */ = {
223
+ isa = XCBuildConfiguration;
224
+ buildSettings = {
225
+ HEADER_SEARCH_PATHS = (
226
+ "$(inherited)",
227
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
228
+ "$(SRCROOT)/../../../React/**",
229
+ "$(SRCROOT)/../../react-native/React/**",
230
+ );
231
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
232
+ OTHER_LDFLAGS = "-ObjC";
233
+ PRODUCT_NAME = Llama;
234
+ SKIP_INSTALL = YES;
235
+ };
236
+ name = Debug;
237
+ };
238
+ 58B511F11A9E6C8500147676 /* Release */ = {
239
+ isa = XCBuildConfiguration;
240
+ buildSettings = {
241
+ HEADER_SEARCH_PATHS = (
242
+ "$(inherited)",
243
+ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
244
+ "$(SRCROOT)/../../../React/**",
245
+ "$(SRCROOT)/../../react-native/React/**",
246
+ );
247
+ LIBRARY_SEARCH_PATHS = "$(inherited)";
248
+ OTHER_LDFLAGS = "-ObjC";
249
+ PRODUCT_NAME = Llama;
250
+ SKIP_INSTALL = YES;
251
+ };
252
+ name = Release;
253
+ };
254
+ /* End XCBuildConfiguration section */
255
+
256
+ /* Begin XCConfigurationList section */
257
+ 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "Llama" */ = {
258
+ isa = XCConfigurationList;
259
+ buildConfigurations = (
260
+ 58B511ED1A9E6C8500147676 /* Debug */,
261
+ 58B511EE1A9E6C8500147676 /* Release */,
262
+ );
263
+ defaultConfigurationIsVisible = 0;
264
+ defaultConfigurationName = Release;
265
+ };
266
+ 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "Llama" */ = {
267
+ isa = XCConfigurationList;
268
+ buildConfigurations = (
269
+ 58B511F01A9E6C8500147676 /* Debug */,
270
+ 58B511F11A9E6C8500147676 /* Release */,
271
+ );
272
+ defaultConfigurationIsVisible = 0;
273
+ defaultConfigurationName = Release;
274
+ };
275
+ /* End XCConfigurationList section */
276
+ };
277
+ rootObject = 58B511D31A9E6C8500147676 /* Project object */;
278
+ }
@@ -0,0 +1,39 @@
1
+ #ifdef __cplusplus
2
+ #import "llama.h"
3
+ #import "rn-llama.hpp"
4
+ #endif
5
+
6
+
7
+ @interface RNLlamaContext : NSObject {
8
+ bool is_metal_enabled;
9
+ NSString * reason_no_metal;
10
+ bool is_model_loaded;
11
+ NSString * model_desc;
12
+ uint64_t model_size;
13
+ uint64_t model_n_params;
14
+ NSDictionary * metadata;
15
+
16
+ rnllama::llama_rn_context * llama;
17
+ }
18
+
19
+ + (instancetype)initWithParams:(NSDictionary *)params;
20
+ - (bool)isMetalEnabled;
21
+ - (NSString *)reasonNoMetal;
22
+ - (NSDictionary *)metadata;
23
+ - (NSString *)modelDesc;
24
+ - (uint64_t)modelSize;
25
+ - (uint64_t)modelNParams;
26
+ - (bool)isModelLoaded;
27
+ - (bool)isPredicting;
28
+ - (NSDictionary *)completion:(NSDictionary *)params onToken:(void (^)(NSMutableDictionary *tokenResult))onToken;
29
+ - (void)stopCompletion;
30
+ - (NSArray *)tokenize:(NSString *)text;
31
+ - (NSString *)detokenize:(NSArray *)tokens;
32
+ - (NSArray *)embedding:(NSString *)text;
33
+ - (NSDictionary *)loadSession:(NSString *)path;
34
+ - (int)saveSession:(NSString *)path size:(int)size;
35
+ - (NSString *)bench:(int)pp tg:(int)tg pl:(int)pl nr:(int)nr;
36
+
37
+ - (void)invalidate;
38
+
39
+ @end