llama-cpp-capacitor 0.0.2 → 0.0.3
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.
|
@@ -109,40 +109,42 @@ endfunction()
|
|
|
109
109
|
|
|
110
110
|
# Build for different architectures
|
|
111
111
|
if (ANDROID_ABI STREQUAL "arm64-v8a")
|
|
112
|
-
build_library(llama-cpp-arm64-v8a "
|
|
112
|
+
build_library(llama-cpp-arm64-v8a "arm" "-march=armv8-a")
|
|
113
113
|
elseif (ANDROID_ABI STREQUAL "armeabi-v7a")
|
|
114
114
|
build_library(llama-cpp-armeabi-v7a "arm" "-march=armv7-a -mfpu=neon")
|
|
115
115
|
elseif (ANDROID_ABI STREQUAL "x86")
|
|
116
|
-
build_library(llama-cpp-x86 "
|
|
116
|
+
build_library(llama-cpp-x86 "x86" "-march=i686 -mtune=intel -mssse3 -mfpmath=sse -m32")
|
|
117
117
|
elseif (ANDROID_ABI STREQUAL "x86_64")
|
|
118
|
-
build_library(llama-cpp-x86_64 "
|
|
118
|
+
build_library(llama-cpp-x86_64 "x86" "-march=x86-64 -msse4.2 -mpopcnt -m64 -mtune=intel")
|
|
119
119
|
endif()
|
|
120
120
|
|
|
121
|
-
# Set compile definitions
|
|
122
|
-
|
|
123
|
-
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
121
|
+
# Set compile definitions for the target that was actually built
|
|
122
|
+
if (ANDROID_ABI STREQUAL "arm64-v8a")
|
|
123
|
+
target_compile_definitions(llama-cpp-arm64-v8a PRIVATE
|
|
124
|
+
-DNDEBUG
|
|
125
|
+
-DO3
|
|
126
|
+
-DLM_GGML_USE_CPU
|
|
127
|
+
-DLM_GGML_CPU_GENERIC
|
|
128
|
+
)
|
|
129
|
+
elseif (ANDROID_ABI STREQUAL "armeabi-v7a")
|
|
130
|
+
target_compile_definitions(llama-cpp-armeabi-v7a PRIVATE
|
|
131
|
+
-DNDEBUG
|
|
132
|
+
-DO3
|
|
133
|
+
-DLM_GGML_USE_CPU
|
|
134
|
+
-DLM_GGML_CPU_GENERIC
|
|
135
|
+
)
|
|
136
|
+
elseif (ANDROID_ABI STREQUAL "x86")
|
|
137
|
+
target_compile_definitions(llama-cpp-x86 PRIVATE
|
|
138
|
+
-DNDEBUG
|
|
139
|
+
-DO3
|
|
140
|
+
-DLM_GGML_USE_CPU
|
|
141
|
+
-DLM_GGML_CPU_GENERIC
|
|
142
|
+
)
|
|
143
|
+
elseif (ANDROID_ABI STREQUAL "x86_64")
|
|
144
|
+
target_compile_definitions(llama-cpp-x86_64 PRIVATE
|
|
145
|
+
-DNDEBUG
|
|
146
|
+
-DO3
|
|
147
|
+
-DLM_GGML_USE_CPU
|
|
148
|
+
-DLM_GGML_CPU_GENERIC
|
|
149
|
+
)
|
|
150
|
+
endif()
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
package ai.annadata.plugin.capacitor;
|
|
2
2
|
|
|
3
3
|
import com.getcapacitor.JSObject;
|
|
4
|
+
import com.getcapacitor.JSArray;
|
|
4
5
|
import com.getcapacitor.Plugin;
|
|
5
6
|
import com.getcapacitor.PluginCall;
|
|
6
7
|
import com.getcapacitor.PluginMethod;
|
|
7
8
|
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
9
|
+
import java.util.Map;
|
|
10
|
+
import org.json.JSONException;
|
|
8
11
|
|
|
9
12
|
@CapacitorPlugin(name = "LlamaCpp")
|
|
10
13
|
public class LlamaCppPlugin extends Plugin {
|
|
@@ -40,12 +43,27 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
40
43
|
@PluginMethod
|
|
41
44
|
public void modelInfo(PluginCall call) {
|
|
42
45
|
String path = call.getString("path", "");
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
JSArray skipArray = call.getArray("skip");
|
|
47
|
+
String[] skip = new String[0];
|
|
48
|
+
if (skipArray != null) {
|
|
49
|
+
skip = new String[skipArray.length()];
|
|
50
|
+
for (int i = 0; i < skipArray.length(); i++) {
|
|
51
|
+
try {
|
|
52
|
+
skip[i] = skipArray.getString(i);
|
|
53
|
+
} catch (JSONException e) {
|
|
54
|
+
skip[i] = "";
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
45
58
|
|
|
46
59
|
implementation.modelInfo(path, skip, result -> {
|
|
47
60
|
if (result.isSuccess()) {
|
|
48
|
-
|
|
61
|
+
JSObject jsResult = new JSObject();
|
|
62
|
+
Map<String, Object> data = result.getData();
|
|
63
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
64
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
65
|
+
}
|
|
66
|
+
call.resolve(jsResult);
|
|
49
67
|
} else {
|
|
50
68
|
call.reject(result.getError().getMessage());
|
|
51
69
|
}
|
|
@@ -59,7 +77,12 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
59
77
|
|
|
60
78
|
implementation.initContext(contextId, params, result -> {
|
|
61
79
|
if (result.isSuccess()) {
|
|
62
|
-
|
|
80
|
+
JSObject jsResult = new JSObject();
|
|
81
|
+
Map<String, Object> data = result.getData();
|
|
82
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
83
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
84
|
+
}
|
|
85
|
+
call.resolve(jsResult);
|
|
63
86
|
} else {
|
|
64
87
|
call.reject(result.getError().getMessage());
|
|
65
88
|
}
|
|
@@ -101,7 +124,12 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
101
124
|
|
|
102
125
|
implementation.getFormattedChat(contextId, messages, chatTemplate, params, result -> {
|
|
103
126
|
if (result.isSuccess()) {
|
|
104
|
-
|
|
127
|
+
JSObject jsResult = new JSObject();
|
|
128
|
+
Map<String, Object> data = result.getData();
|
|
129
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
130
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
131
|
+
}
|
|
132
|
+
call.resolve(jsResult);
|
|
105
133
|
} else {
|
|
106
134
|
call.reject(result.getError().getMessage());
|
|
107
135
|
}
|
|
@@ -115,7 +143,12 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
115
143
|
|
|
116
144
|
implementation.completion(contextId, params, result -> {
|
|
117
145
|
if (result.isSuccess()) {
|
|
118
|
-
|
|
146
|
+
JSObject jsResult = new JSObject();
|
|
147
|
+
Map<String, Object> data = result.getData();
|
|
148
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
149
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
150
|
+
}
|
|
151
|
+
call.resolve(jsResult);
|
|
119
152
|
} else {
|
|
120
153
|
call.reject(result.getError().getMessage());
|
|
121
154
|
}
|
|
@@ -140,11 +173,16 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
140
173
|
@PluginMethod
|
|
141
174
|
public void loadSession(PluginCall call) {
|
|
142
175
|
int contextId = call.getInt("contextId", 0);
|
|
143
|
-
String
|
|
176
|
+
String path = call.getString("path", "");
|
|
144
177
|
|
|
145
|
-
implementation.loadSession(contextId,
|
|
178
|
+
implementation.loadSession(contextId, path, result -> {
|
|
146
179
|
if (result.isSuccess()) {
|
|
147
|
-
|
|
180
|
+
JSObject jsResult = new JSObject();
|
|
181
|
+
Map<String, Object> data = result.getData();
|
|
182
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
183
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
184
|
+
}
|
|
185
|
+
call.resolve(jsResult);
|
|
148
186
|
} else {
|
|
149
187
|
call.reject(result.getError().getMessage());
|
|
150
188
|
}
|
|
@@ -154,10 +192,10 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
154
192
|
@PluginMethod
|
|
155
193
|
public void saveSession(PluginCall call) {
|
|
156
194
|
int contextId = call.getInt("contextId", 0);
|
|
157
|
-
String
|
|
195
|
+
String path = call.getString("path", "");
|
|
158
196
|
int size = call.getInt("size", -1);
|
|
159
197
|
|
|
160
|
-
implementation.saveSession(contextId,
|
|
198
|
+
implementation.saveSession(contextId, path, size, result -> {
|
|
161
199
|
if (result.isSuccess()) {
|
|
162
200
|
JSObject ret = new JSObject();
|
|
163
201
|
ret.put("tokensSaved", result.getData());
|
|
@@ -174,12 +212,27 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
174
212
|
public void tokenize(PluginCall call) {
|
|
175
213
|
int contextId = call.getInt("contextId", 0);
|
|
176
214
|
String text = call.getString("text", "");
|
|
177
|
-
|
|
178
|
-
|
|
215
|
+
JSArray imagePathsArray = call.getArray("imagePaths");
|
|
216
|
+
String[] imagePaths = new String[0];
|
|
217
|
+
if (imagePathsArray != null) {
|
|
218
|
+
imagePaths = new String[imagePathsArray.length()];
|
|
219
|
+
for (int i = 0; i < imagePathsArray.length(); i++) {
|
|
220
|
+
try {
|
|
221
|
+
imagePaths[i] = imagePathsArray.getString(i);
|
|
222
|
+
} catch (JSONException e) {
|
|
223
|
+
imagePaths[i] = "";
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
179
227
|
|
|
180
228
|
implementation.tokenize(contextId, text, imagePaths, result -> {
|
|
181
229
|
if (result.isSuccess()) {
|
|
182
|
-
|
|
230
|
+
JSObject jsResult = new JSObject();
|
|
231
|
+
Map<String, Object> data = result.getData();
|
|
232
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
233
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
234
|
+
}
|
|
235
|
+
call.resolve(jsResult);
|
|
183
236
|
} else {
|
|
184
237
|
call.reject(result.getError().getMessage());
|
|
185
238
|
}
|
|
@@ -189,8 +242,18 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
189
242
|
@PluginMethod
|
|
190
243
|
public void detokenize(PluginCall call) {
|
|
191
244
|
int contextId = call.getInt("contextId", 0);
|
|
192
|
-
|
|
193
|
-
|
|
245
|
+
JSArray tokensArray = call.getArray("tokens");
|
|
246
|
+
Integer[] tokens = new Integer[0];
|
|
247
|
+
if (tokensArray != null) {
|
|
248
|
+
tokens = new Integer[tokensArray.length()];
|
|
249
|
+
for (int i = 0; i < tokensArray.length(); i++) {
|
|
250
|
+
try {
|
|
251
|
+
tokens[i] = tokensArray.getInt(i);
|
|
252
|
+
} catch (JSONException e) {
|
|
253
|
+
tokens[i] = 0;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
194
257
|
|
|
195
258
|
implementation.detokenize(contextId, tokens, result -> {
|
|
196
259
|
if (result.isSuccess()) {
|
|
@@ -213,7 +276,12 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
213
276
|
|
|
214
277
|
implementation.embedding(contextId, text, params, result -> {
|
|
215
278
|
if (result.isSuccess()) {
|
|
216
|
-
|
|
279
|
+
JSObject jsResult = new JSObject();
|
|
280
|
+
Map<String, Object> data = result.getData();
|
|
281
|
+
for (Map.Entry<String, Object> entry : data.entrySet()) {
|
|
282
|
+
jsResult.put(entry.getKey(), entry.getValue());
|
|
283
|
+
}
|
|
284
|
+
call.resolve(jsResult);
|
|
217
285
|
} else {
|
|
218
286
|
call.reject(result.getError().getMessage());
|
|
219
287
|
}
|
|
@@ -224,8 +292,18 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
224
292
|
public void rerank(PluginCall call) {
|
|
225
293
|
int contextId = call.getInt("contextId", 0);
|
|
226
294
|
String query = call.getString("query", "");
|
|
227
|
-
|
|
228
|
-
|
|
295
|
+
JSArray documentsArray = call.getArray("documents");
|
|
296
|
+
String[] documents = new String[0];
|
|
297
|
+
if (documentsArray != null) {
|
|
298
|
+
documents = new String[documentsArray.length()];
|
|
299
|
+
for (int i = 0; i < documentsArray.length(); i++) {
|
|
300
|
+
try {
|
|
301
|
+
documents[i] = documentsArray.getString(i);
|
|
302
|
+
} catch (JSONException e) {
|
|
303
|
+
documents[i] = "";
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
229
307
|
JSObject params = call.getObject("params");
|
|
230
308
|
|
|
231
309
|
implementation.rerank(contextId, query, documents, params, result -> {
|
|
@@ -265,8 +343,15 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
265
343
|
@PluginMethod
|
|
266
344
|
public void applyLoraAdapters(PluginCall call) {
|
|
267
345
|
int contextId = call.getInt("contextId", 0);
|
|
268
|
-
|
|
269
|
-
|
|
346
|
+
JSArray loraAdaptersArray = call.getArray("loraAdapters");
|
|
347
|
+
JSObject[] loraAdapters = new JSObject[0];
|
|
348
|
+
if (loraAdaptersArray != null) {
|
|
349
|
+
loraAdapters = new JSObject[loraAdaptersArray.length()];
|
|
350
|
+
for (int i = 0; i < loraAdaptersArray.length(); i++) {
|
|
351
|
+
// For now, create empty JSObjects since the exact method is unclear
|
|
352
|
+
loraAdapters[i] = new JSObject();
|
|
353
|
+
}
|
|
354
|
+
}
|
|
270
355
|
|
|
271
356
|
implementation.applyLoraAdapters(contextId, loraAdapters, result -> {
|
|
272
357
|
if (result.isSuccess()) {
|
|
@@ -346,7 +431,9 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
346
431
|
|
|
347
432
|
implementation.getMultimodalSupport(contextId, result -> {
|
|
348
433
|
if (result.isSuccess()) {
|
|
349
|
-
|
|
434
|
+
JSObject ret = new JSObject();
|
|
435
|
+
ret.put("support", result.getData());
|
|
436
|
+
call.resolve(ret);
|
|
350
437
|
} else {
|
|
351
438
|
call.reject(result.getError().getMessage());
|
|
352
439
|
}
|
|
@@ -409,7 +496,9 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
409
496
|
|
|
410
497
|
implementation.getFormattedAudioCompletion(contextId, speakerJsonStr, textToSpeak, result -> {
|
|
411
498
|
if (result.isSuccess()) {
|
|
412
|
-
|
|
499
|
+
JSObject ret = new JSObject();
|
|
500
|
+
ret.put("completion", result.getData());
|
|
501
|
+
call.resolve(ret);
|
|
413
502
|
} else {
|
|
414
503
|
call.reject(result.getError().getMessage());
|
|
415
504
|
}
|
|
@@ -435,8 +524,18 @@ public class LlamaCppPlugin extends Plugin {
|
|
|
435
524
|
@PluginMethod
|
|
436
525
|
public void decodeAudioTokens(PluginCall call) {
|
|
437
526
|
int contextId = call.getInt("contextId", 0);
|
|
438
|
-
|
|
439
|
-
|
|
527
|
+
JSArray tokensArray = call.getArray("tokens");
|
|
528
|
+
Integer[] tokens = new Integer[0];
|
|
529
|
+
if (tokensArray != null) {
|
|
530
|
+
tokens = new Integer[tokensArray.length()];
|
|
531
|
+
for (int i = 0; i < tokensArray.length(); i++) {
|
|
532
|
+
try {
|
|
533
|
+
tokens[i] = tokensArray.getInt(i);
|
|
534
|
+
} catch (JSONException e) {
|
|
535
|
+
tokens[i] = 0;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
}
|
|
440
539
|
|
|
441
540
|
implementation.decodeAudioTokens(contextId, tokens, result -> {
|
|
442
541
|
if (result.isSuccess()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "llama-cpp-capacitor",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "A native Capacitor plugin that embeds llama.cpp directly into mobile apps, enabling offline AI inference with comprehensive support for text generation, multimodal processing, TTS, LoRA adapters, and more.",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|