llama-cpp-capacitor 0.0.1
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/LlamaCpp.podspec +17 -0
- package/Package.swift +28 -0
- package/README.md +574 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/CMakeLists.txt +148 -0
- package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCpp.java +677 -0
- package/android/src/main/java/ai/annadata/plugin/capacitor/LlamaCppPlugin.java +482 -0
- package/android/src/main/jni-utils.h +139 -0
- package/android/src/main/jni.cpp +271 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +5513 -0
- package/dist/esm/definitions.d.ts +653 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +180 -0
- package/dist/esm/index.js +518 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/plugin.cjs.js +531 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +534 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/LlamaCppPlugin/LlamaCpp.swift +596 -0
- package/ios/Sources/LlamaCppPlugin/LlamaCppPlugin.swift +514 -0
- package/ios/Tests/LlamaCppPluginTests/LlamaCppPluginTests.swift +15 -0
- package/package.json +108 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(LlamaCppPlugin)
|
|
9
|
+
public class LlamaCppPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
10
|
+
public let identifier = "LlamaCppPlugin"
|
|
11
|
+
public let jsName = "LlamaCpp"
|
|
12
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
13
|
+
// Core initialization and management
|
|
14
|
+
CAPPluginMethod(name: "toggleNativeLog", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "setContextLimit", returnType: CAPPluginReturnPromise),
|
|
16
|
+
CAPPluginMethod(name: "modelInfo", returnType: CAPPluginReturnPromise),
|
|
17
|
+
CAPPluginMethod(name: "initContext", returnType: CAPPluginReturnPromise),
|
|
18
|
+
CAPPluginMethod(name: "releaseContext", returnType: CAPPluginReturnPromise),
|
|
19
|
+
CAPPluginMethod(name: "releaseAllContexts", returnType: CAPPluginReturnPromise),
|
|
20
|
+
|
|
21
|
+
// Chat and completion
|
|
22
|
+
CAPPluginMethod(name: "getFormattedChat", returnType: CAPPluginReturnPromise),
|
|
23
|
+
CAPPluginMethod(name: "completion", returnType: CAPPluginReturnPromise),
|
|
24
|
+
CAPPluginMethod(name: "stopCompletion", returnType: CAPPluginReturnPromise),
|
|
25
|
+
|
|
26
|
+
// Session management
|
|
27
|
+
CAPPluginMethod(name: "loadSession", returnType: CAPPluginReturnPromise),
|
|
28
|
+
CAPPluginMethod(name: "saveSession", returnType: CAPPluginReturnPromise),
|
|
29
|
+
|
|
30
|
+
// Tokenization
|
|
31
|
+
CAPPluginMethod(name: "tokenize", returnType: CAPPluginReturnPromise),
|
|
32
|
+
CAPPluginMethod(name: "detokenize", returnType: CAPPluginReturnPromise),
|
|
33
|
+
|
|
34
|
+
// Embeddings and reranking
|
|
35
|
+
CAPPluginMethod(name: "embedding", returnType: CAPPluginReturnPromise),
|
|
36
|
+
CAPPluginMethod(name: "rerank", returnType: CAPPluginReturnPromise),
|
|
37
|
+
|
|
38
|
+
// Benchmarking
|
|
39
|
+
CAPPluginMethod(name: "bench", returnType: CAPPluginReturnPromise),
|
|
40
|
+
|
|
41
|
+
// LoRA adapters
|
|
42
|
+
CAPPluginMethod(name: "applyLoraAdapters", returnType: CAPPluginReturnPromise),
|
|
43
|
+
CAPPluginMethod(name: "removeLoraAdapters", returnType: CAPPluginReturnPromise),
|
|
44
|
+
CAPPluginMethod(name: "getLoadedLoraAdapters", returnType: CAPPluginReturnPromise),
|
|
45
|
+
|
|
46
|
+
// Multimodal methods
|
|
47
|
+
CAPPluginMethod(name: "initMultimodal", returnType: CAPPluginReturnPromise),
|
|
48
|
+
CAPPluginMethod(name: "isMultimodalEnabled", returnType: CAPPluginReturnPromise),
|
|
49
|
+
CAPPluginMethod(name: "getMultimodalSupport", returnType: CAPPluginReturnPromise),
|
|
50
|
+
CAPPluginMethod(name: "releaseMultimodal", returnType: CAPPluginReturnPromise),
|
|
51
|
+
|
|
52
|
+
// TTS methods
|
|
53
|
+
CAPPluginMethod(name: "initVocoder", returnType: CAPPluginReturnPromise),
|
|
54
|
+
CAPPluginMethod(name: "isVocoderEnabled", returnType: CAPPluginReturnPromise),
|
|
55
|
+
CAPPluginMethod(name: "getFormattedAudioCompletion", returnType: CAPPluginReturnPromise),
|
|
56
|
+
CAPPluginMethod(name: "getAudioCompletionGuideTokens", returnType: CAPPluginReturnPromise),
|
|
57
|
+
CAPPluginMethod(name: "decodeAudioTokens", returnType: CAPPluginReturnPromise),
|
|
58
|
+
CAPPluginMethod(name: "releaseVocoder", returnType: CAPPluginReturnPromise),
|
|
59
|
+
|
|
60
|
+
// Events
|
|
61
|
+
CAPPluginMethod(name: "addListener", returnType: CAPPluginReturnPromise),
|
|
62
|
+
CAPPluginMethod(name: "removeAllListeners", returnType: CAPPluginReturnPromise)
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
private let implementation = LlamaCpp()
|
|
66
|
+
|
|
67
|
+
// MARK: - Core initialization and management
|
|
68
|
+
|
|
69
|
+
@objc func toggleNativeLog(_ call: CAPPluginCall) {
|
|
70
|
+
let enabled = call.getBool("enabled") ?? false
|
|
71
|
+
implementation.toggleNativeLog(enabled: enabled) { result in
|
|
72
|
+
switch result {
|
|
73
|
+
case .success:
|
|
74
|
+
call.resolve()
|
|
75
|
+
case .failure(let error):
|
|
76
|
+
call.reject(error.localizedDescription)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc func setContextLimit(_ call: CAPPluginCall) {
|
|
82
|
+
let limit = call.getInt("limit") ?? 0
|
|
83
|
+
implementation.setContextLimit(limit: limit) { result in
|
|
84
|
+
switch result {
|
|
85
|
+
case .success:
|
|
86
|
+
call.resolve()
|
|
87
|
+
case .failure(let error):
|
|
88
|
+
call.reject(error.localizedDescription)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@objc func modelInfo(_ call: CAPPluginCall) {
|
|
94
|
+
let path = call.getString("path") ?? ""
|
|
95
|
+
let skip = call.getArray("skip", String.self) ?? []
|
|
96
|
+
|
|
97
|
+
implementation.modelInfo(path: path, skip: skip) { result in
|
|
98
|
+
switch result {
|
|
99
|
+
case .success(let modelInfo):
|
|
100
|
+
call.resolve(modelInfo)
|
|
101
|
+
case .failure(let error):
|
|
102
|
+
call.reject(error.localizedDescription)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@objc func initContext(_ call: CAPPluginCall) {
|
|
108
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
109
|
+
let params = call.getObject("params") ?? [:]
|
|
110
|
+
|
|
111
|
+
implementation.initContext(contextId: contextId, params: params) { result in
|
|
112
|
+
switch result {
|
|
113
|
+
case .success(let context):
|
|
114
|
+
call.resolve(context)
|
|
115
|
+
case .failure(let error):
|
|
116
|
+
call.reject(error.localizedDescription)
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
@objc func releaseContext(_ call: CAPPluginCall) {
|
|
122
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
123
|
+
|
|
124
|
+
implementation.releaseContext(contextId: contextId) { result in
|
|
125
|
+
switch result {
|
|
126
|
+
case .success:
|
|
127
|
+
call.resolve()
|
|
128
|
+
case .failure(let error):
|
|
129
|
+
call.reject(error.localizedDescription)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@objc func releaseAllContexts(_ call: CAPPluginCall) {
|
|
135
|
+
implementation.releaseAllContexts { result in
|
|
136
|
+
switch result {
|
|
137
|
+
case .success:
|
|
138
|
+
call.resolve()
|
|
139
|
+
case .failure(let error):
|
|
140
|
+
call.reject(error.localizedDescription)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// MARK: - Chat and completion
|
|
146
|
+
|
|
147
|
+
@objc func getFormattedChat(_ call: CAPPluginCall) {
|
|
148
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
149
|
+
let messages = call.getString("messages") ?? ""
|
|
150
|
+
let chatTemplate = call.getString("chatTemplate")
|
|
151
|
+
let params = call.getObject("params")
|
|
152
|
+
|
|
153
|
+
implementation.getFormattedChat(
|
|
154
|
+
contextId: contextId,
|
|
155
|
+
messages: messages,
|
|
156
|
+
chatTemplate: chatTemplate,
|
|
157
|
+
params: params
|
|
158
|
+
) { result in
|
|
159
|
+
switch result {
|
|
160
|
+
case .success(let formattedChat):
|
|
161
|
+
call.resolve(formattedChat)
|
|
162
|
+
case .failure(let error):
|
|
163
|
+
call.reject(error.localizedDescription)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@objc func completion(_ call: CAPPluginCall) {
|
|
169
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
170
|
+
let params = call.getObject("params") ?? [:]
|
|
171
|
+
|
|
172
|
+
implementation.completion(contextId: contextId, params: params) { result in
|
|
173
|
+
switch result {
|
|
174
|
+
case .success(let completionResult):
|
|
175
|
+
call.resolve(completionResult)
|
|
176
|
+
case .failure(let error):
|
|
177
|
+
call.reject(error.localizedDescription)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
@objc func stopCompletion(_ call: CAPPluginCall) {
|
|
183
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
184
|
+
|
|
185
|
+
implementation.stopCompletion(contextId: contextId) { result in
|
|
186
|
+
switch result {
|
|
187
|
+
case .success:
|
|
188
|
+
call.resolve()
|
|
189
|
+
case .failure(let error):
|
|
190
|
+
call.reject(error.localizedDescription)
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// MARK: - Session management
|
|
196
|
+
|
|
197
|
+
@objc func loadSession(_ call: CAPPluginCall) {
|
|
198
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
199
|
+
let filepath = call.getString("filepath") ?? ""
|
|
200
|
+
|
|
201
|
+
implementation.loadSession(contextId: contextId, filepath: filepath) { result in
|
|
202
|
+
switch result {
|
|
203
|
+
case .success(let sessionResult):
|
|
204
|
+
call.resolve(sessionResult)
|
|
205
|
+
case .failure(let error):
|
|
206
|
+
call.reject(error.localizedDescription)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
@objc func saveSession(_ call: CAPPluginCall) {
|
|
212
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
213
|
+
let filepath = call.getString("filepath") ?? ""
|
|
214
|
+
let size = call.getInt("size") ?? -1
|
|
215
|
+
|
|
216
|
+
implementation.saveSession(contextId: contextId, filepath: filepath, size: size) { result in
|
|
217
|
+
switch result {
|
|
218
|
+
case .success(let tokensSaved):
|
|
219
|
+
call.resolve(["tokensSaved": tokensSaved])
|
|
220
|
+
case .failure(let error):
|
|
221
|
+
call.reject(error.localizedDescription)
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// MARK: - Tokenization
|
|
227
|
+
|
|
228
|
+
@objc func tokenize(_ call: CAPPluginCall) {
|
|
229
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
230
|
+
let text = call.getString("text") ?? ""
|
|
231
|
+
let imagePaths = call.getArray("imagePaths", String.self) ?? []
|
|
232
|
+
|
|
233
|
+
implementation.tokenize(contextId: contextId, text: text, imagePaths: imagePaths) { result in
|
|
234
|
+
switch result {
|
|
235
|
+
case .success(let tokenizeResult):
|
|
236
|
+
call.resolve(tokenizeResult)
|
|
237
|
+
case .failure(let error):
|
|
238
|
+
call.reject(error.localizedDescription)
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
@objc func detokenize(_ call: CAPPluginCall) {
|
|
244
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
245
|
+
let tokens = call.getArray("tokens", Int.self) ?? []
|
|
246
|
+
|
|
247
|
+
implementation.detokenize(contextId: contextId, tokens: tokens) { result in
|
|
248
|
+
switch result {
|
|
249
|
+
case .success(let text):
|
|
250
|
+
call.resolve(["text": text])
|
|
251
|
+
case .failure(let error):
|
|
252
|
+
call.reject(error.localizedDescription)
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// MARK: - Embeddings and reranking
|
|
258
|
+
|
|
259
|
+
@objc func embedding(_ call: CAPPluginCall) {
|
|
260
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
261
|
+
let text = call.getString("text") ?? ""
|
|
262
|
+
let params = call.getObject("params") ?? [:]
|
|
263
|
+
|
|
264
|
+
implementation.embedding(contextId: contextId, text: text, params: params) { result in
|
|
265
|
+
switch result {
|
|
266
|
+
case .success(let embeddingResult):
|
|
267
|
+
call.resolve(embeddingResult)
|
|
268
|
+
case .failure(let error):
|
|
269
|
+
call.reject(error.localizedDescription)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@objc func rerank(_ call: CAPPluginCall) {
|
|
275
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
276
|
+
let query = call.getString("query") ?? ""
|
|
277
|
+
let documents = call.getArray("documents", String.self) ?? []
|
|
278
|
+
let params = call.getObject("params")
|
|
279
|
+
|
|
280
|
+
implementation.rerank(contextId: contextId, query: query, documents: documents, params: params) { result in
|
|
281
|
+
switch result {
|
|
282
|
+
case .success(let rerankResults):
|
|
283
|
+
call.resolve(["results": rerankResults])
|
|
284
|
+
case .failure(let error):
|
|
285
|
+
call.reject(error.localizedDescription)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// MARK: - Benchmarking
|
|
291
|
+
|
|
292
|
+
@objc func bench(_ call: CAPPluginCall) {
|
|
293
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
294
|
+
let pp = call.getInt("pp") ?? 0
|
|
295
|
+
let tg = call.getInt("tg") ?? 0
|
|
296
|
+
let pl = call.getInt("pl") ?? 0
|
|
297
|
+
let nr = call.getInt("nr") ?? 0
|
|
298
|
+
|
|
299
|
+
implementation.bench(contextId: contextId, pp: pp, tg: tg, pl: pl, nr: nr) { result in
|
|
300
|
+
switch result {
|
|
301
|
+
case .success(let benchResult):
|
|
302
|
+
call.resolve(["result": benchResult])
|
|
303
|
+
case .failure(let error):
|
|
304
|
+
call.reject(error.localizedDescription)
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// MARK: - LoRA adapters
|
|
310
|
+
|
|
311
|
+
@objc func applyLoraAdapters(_ call: CAPPluginCall) {
|
|
312
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
313
|
+
let loraAdapters = call.getArray("loraAdapters", [String: Any].self) ?? []
|
|
314
|
+
|
|
315
|
+
implementation.applyLoraAdapters(contextId: contextId, loraAdapters: loraAdapters) { result in
|
|
316
|
+
switch result {
|
|
317
|
+
case .success:
|
|
318
|
+
call.resolve()
|
|
319
|
+
case .failure(let error):
|
|
320
|
+
call.reject(error.localizedDescription)
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
@objc func removeLoraAdapters(_ call: CAPPluginCall) {
|
|
326
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
327
|
+
|
|
328
|
+
implementation.removeLoraAdapters(contextId: contextId) { result in
|
|
329
|
+
switch result {
|
|
330
|
+
case .success:
|
|
331
|
+
call.resolve()
|
|
332
|
+
case .failure(let error):
|
|
333
|
+
call.reject(error.localizedDescription)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
@objc func getLoadedLoraAdapters(_ call: CAPPluginCall) {
|
|
339
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
340
|
+
|
|
341
|
+
implementation.getLoadedLoraAdapters(contextId: contextId) { result in
|
|
342
|
+
switch result {
|
|
343
|
+
case .success(let adapters):
|
|
344
|
+
call.resolve(["adapters": adapters])
|
|
345
|
+
case .failure(let error):
|
|
346
|
+
call.reject(error.localizedDescription)
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// MARK: - Multimodal methods
|
|
352
|
+
|
|
353
|
+
@objc func initMultimodal(_ call: CAPPluginCall) {
|
|
354
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
355
|
+
let params = call.getObject("params") ?? [:]
|
|
356
|
+
let path = params["path"] as? String ?? ""
|
|
357
|
+
let useGpu = params["use_gpu"] as? Bool ?? true
|
|
358
|
+
|
|
359
|
+
implementation.initMultimodal(contextId: contextId, path: path, useGpu: useGpu) { result in
|
|
360
|
+
switch result {
|
|
361
|
+
case .success(let success):
|
|
362
|
+
call.resolve(["success": success])
|
|
363
|
+
case .failure(let error):
|
|
364
|
+
call.reject(error.localizedDescription)
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
@objc func isMultimodalEnabled(_ call: CAPPluginCall) {
|
|
370
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
371
|
+
|
|
372
|
+
implementation.isMultimodalEnabled(contextId: contextId) { result in
|
|
373
|
+
switch result {
|
|
374
|
+
case .success(let enabled):
|
|
375
|
+
call.resolve(["enabled": enabled])
|
|
376
|
+
case .failure(let error):
|
|
377
|
+
call.reject(error.localizedDescription)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
@objc func getMultimodalSupport(_ call: CAPPluginCall) {
|
|
383
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
384
|
+
|
|
385
|
+
implementation.getMultimodalSupport(contextId: contextId) { result in
|
|
386
|
+
switch result {
|
|
387
|
+
case .success(let support):
|
|
388
|
+
call.resolve(support)
|
|
389
|
+
case .failure(let error):
|
|
390
|
+
call.reject(error.localizedDescription)
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
@objc func releaseMultimodal(_ call: CAPPluginCall) {
|
|
396
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
397
|
+
|
|
398
|
+
implementation.releaseMultimodal(contextId: contextId) { result in
|
|
399
|
+
switch result {
|
|
400
|
+
case .success:
|
|
401
|
+
call.resolve()
|
|
402
|
+
case .failure(let error):
|
|
403
|
+
call.reject(error.localizedDescription)
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// MARK: - TTS methods
|
|
409
|
+
|
|
410
|
+
@objc func initVocoder(_ call: CAPPluginCall) {
|
|
411
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
412
|
+
let params = call.getObject("params") ?? [:]
|
|
413
|
+
let path = params["path"] as? String ?? ""
|
|
414
|
+
let nBatch = params["n_batch"] as? Int
|
|
415
|
+
|
|
416
|
+
implementation.initVocoder(contextId: contextId, path: path, nBatch: nBatch) { result in
|
|
417
|
+
switch result {
|
|
418
|
+
case .success(let success):
|
|
419
|
+
call.resolve(["success": success])
|
|
420
|
+
case .failure(let error):
|
|
421
|
+
call.reject(error.localizedDescription)
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
@objc func isVocoderEnabled(_ call: CAPPluginCall) {
|
|
427
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
428
|
+
|
|
429
|
+
implementation.isVocoderEnabled(contextId: contextId) { result in
|
|
430
|
+
switch result {
|
|
431
|
+
case .success(let enabled):
|
|
432
|
+
call.resolve(["enabled": enabled])
|
|
433
|
+
case .failure(let error):
|
|
434
|
+
call.reject(error.localizedDescription)
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
@objc func getFormattedAudioCompletion(_ call: CAPPluginCall) {
|
|
440
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
441
|
+
let speakerJsonStr = call.getString("speakerJsonStr") ?? ""
|
|
442
|
+
let textToSpeak = call.getString("textToSpeak") ?? ""
|
|
443
|
+
|
|
444
|
+
implementation.getFormattedAudioCompletion(
|
|
445
|
+
contextId: contextId,
|
|
446
|
+
speakerJsonStr: speakerJsonStr,
|
|
447
|
+
textToSpeak: textToSpeak
|
|
448
|
+
) { result in
|
|
449
|
+
switch result {
|
|
450
|
+
case .success(let audioCompletion):
|
|
451
|
+
call.resolve(audioCompletion)
|
|
452
|
+
case .failure(let error):
|
|
453
|
+
call.reject(error.localizedDescription)
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
@objc func getAudioCompletionGuideTokens(_ call: CAPPluginCall) {
|
|
459
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
460
|
+
let textToSpeak = call.getString("textToSpeak") ?? ""
|
|
461
|
+
|
|
462
|
+
implementation.getAudioCompletionGuideTokens(contextId: contextId, textToSpeak: textToSpeak) { result in
|
|
463
|
+
switch result {
|
|
464
|
+
case .success(let tokens):
|
|
465
|
+
call.resolve(["tokens": tokens])
|
|
466
|
+
case .failure(let error):
|
|
467
|
+
call.reject(error.localizedDescription)
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
@objc func decodeAudioTokens(_ call: CAPPluginCall) {
|
|
473
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
474
|
+
let tokens = call.getArray("tokens", Int.self) ?? []
|
|
475
|
+
|
|
476
|
+
implementation.decodeAudioTokens(contextId: contextId, tokens: tokens) { result in
|
|
477
|
+
switch result {
|
|
478
|
+
case .success(let decodedTokens):
|
|
479
|
+
call.resolve(["decodedTokens": decodedTokens])
|
|
480
|
+
case .failure(let error):
|
|
481
|
+
call.reject(error.localizedDescription)
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
@objc func releaseVocoder(_ call: CAPPluginCall) {
|
|
487
|
+
let contextId = call.getInt("contextId") ?? 0
|
|
488
|
+
|
|
489
|
+
implementation.releaseVocoder(contextId: contextId) { result in
|
|
490
|
+
switch result {
|
|
491
|
+
case .success:
|
|
492
|
+
call.resolve()
|
|
493
|
+
case .failure(let error):
|
|
494
|
+
call.reject(error.localizedDescription)
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// MARK: - Events
|
|
500
|
+
|
|
501
|
+
@objc func addListener(_ call: CAPPluginCall) {
|
|
502
|
+
let eventName = call.getString("eventName") ?? ""
|
|
503
|
+
// Note: In Capacitor, event listeners are typically handled differently
|
|
504
|
+
// This is a placeholder for the event system
|
|
505
|
+
call.resolve()
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
@objc func removeAllListeners(_ call: CAPPluginCall) {
|
|
509
|
+
let eventName = call.getString("eventName") ?? ""
|
|
510
|
+
// Note: In Capacitor, event listeners are typically handled differently
|
|
511
|
+
// This is a placeholder for the event system
|
|
512
|
+
call.resolve()
|
|
513
|
+
}
|
|
514
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import LlamaCppPlugin
|
|
3
|
+
|
|
4
|
+
class LlamaCppTests: XCTestCase {
|
|
5
|
+
func testEcho() {
|
|
6
|
+
// This is an example of a functional test case for a plugin.
|
|
7
|
+
// Use XCTAssert and related functions to verify your tests produce the correct results.
|
|
8
|
+
|
|
9
|
+
let implementation = LlamaCpp()
|
|
10
|
+
let value = "Hello, World!"
|
|
11
|
+
let result = implementation.echo(value)
|
|
12
|
+
|
|
13
|
+
XCTAssertEqual(value, result)
|
|
14
|
+
}
|
|
15
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "llama-cpp-capacitor",
|
|
3
|
+
"version": "0.0.1",
|
|
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
|
+
"main": "dist/plugin.cjs.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"unpkg": "dist/plugin.js",
|
|
9
|
+
"files": [
|
|
10
|
+
"android/src/main/",
|
|
11
|
+
"android/build.gradle",
|
|
12
|
+
"dist/",
|
|
13
|
+
"ios/Sources",
|
|
14
|
+
"ios/Tests",
|
|
15
|
+
"Package.swift",
|
|
16
|
+
"LlamaCpp.podspec"
|
|
17
|
+
],
|
|
18
|
+
"author": "Yakub Mohammad",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/arusatech/llama-cpp.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/arusatech/llama-cpp/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/arusatech/llama-cpp#readme",
|
|
28
|
+
"keywords": [
|
|
29
|
+
"capacitor",
|
|
30
|
+
"plugin",
|
|
31
|
+
"native",
|
|
32
|
+
"llama",
|
|
33
|
+
"llama.cpp",
|
|
34
|
+
"ai",
|
|
35
|
+
"machine-learning",
|
|
36
|
+
"offline-ai",
|
|
37
|
+
"text-generation",
|
|
38
|
+
"multimodal",
|
|
39
|
+
"tts",
|
|
40
|
+
"text-to-speech",
|
|
41
|
+
"lora",
|
|
42
|
+
"embeddings",
|
|
43
|
+
"reranking",
|
|
44
|
+
"chat-completion",
|
|
45
|
+
"gguf",
|
|
46
|
+
"large-language-model",
|
|
47
|
+
"llm"
|
|
48
|
+
],
|
|
49
|
+
"scripts": {
|
|
50
|
+
"verify": "npm run verify:ios && npm run verify:android && npm run verify:web",
|
|
51
|
+
"verify:ios": "xcodebuild -scheme LlamaCpp -destination generic/platform=iOS",
|
|
52
|
+
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
53
|
+
"verify:web": "npm run build",
|
|
54
|
+
"lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
|
|
55
|
+
"fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --fix --format",
|
|
56
|
+
"eslint": "eslint . --ext ts",
|
|
57
|
+
"prettier": "prettier \"**/*.{css,html,ts,js,java}\" --plugin=prettier-plugin-java",
|
|
58
|
+
"swiftlint": "node-swiftlint",
|
|
59
|
+
"docgen": "docgen --api LlamaCppPlugin --output-readme README.md --output-json dist/docs.json",
|
|
60
|
+
"build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
|
|
61
|
+
"build:native": "./build-native.sh",
|
|
62
|
+
"build:ios": "cd ios && cmake -B build -S . && cmake --build build --config Release",
|
|
63
|
+
"build:android": "cd android && ./gradlew assembleRelease",
|
|
64
|
+
"test": "jest",
|
|
65
|
+
"test:integration": "./scripts/test-integration.sh",
|
|
66
|
+
"test:integration:jest": "jest --config test/jest.integration.config.js",
|
|
67
|
+
"test:integration:custom": "ts-node test/integration/test-runner.ts",
|
|
68
|
+
"test:unit": "jest --testPathIgnorePatterns=test/integration",
|
|
69
|
+
"test:coverage": "jest --coverage",
|
|
70
|
+
"clean": "rimraf ./dist",
|
|
71
|
+
"clean:native": "rimraf ios/build android/build android/src/main/jniLibs",
|
|
72
|
+
"clean:test": "rimraf test/output test/coverage",
|
|
73
|
+
"watch": "tsc --watch",
|
|
74
|
+
"prepublishOnly": "npm run build"
|
|
75
|
+
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"@capacitor/android": "^7.0.0",
|
|
78
|
+
"@capacitor/core": "^7.4.3",
|
|
79
|
+
"@capacitor/docgen": "^0.3.0",
|
|
80
|
+
"@capacitor/ios": "^7.0.0",
|
|
81
|
+
"@ionic/eslint-config": "^0.4.0",
|
|
82
|
+
"@ionic/prettier-config": "^4.0.0",
|
|
83
|
+
"@ionic/swiftlint-config": "^2.0.0",
|
|
84
|
+
"eslint": "^8.57.0",
|
|
85
|
+
"prettier": "^3.4.2",
|
|
86
|
+
"prettier-plugin-java": "^2.6.6",
|
|
87
|
+
"rimraf": "^6.0.1",
|
|
88
|
+
"rollup": "^4.30.1",
|
|
89
|
+
"swiftlint": "^2.0.0",
|
|
90
|
+
"typescript": "~4.1.5"
|
|
91
|
+
},
|
|
92
|
+
"peerDependencies": {
|
|
93
|
+
"@capacitor/core": ">=7.0.0"
|
|
94
|
+
},
|
|
95
|
+
"prettier": "@ionic/prettier-config",
|
|
96
|
+
"swiftlint": "@ionic/swiftlint-config",
|
|
97
|
+
"eslintConfig": {
|
|
98
|
+
"extends": "@ionic/eslint-config/recommended"
|
|
99
|
+
},
|
|
100
|
+
"capacitor": {
|
|
101
|
+
"ios": {
|
|
102
|
+
"src": "ios"
|
|
103
|
+
},
|
|
104
|
+
"android": {
|
|
105
|
+
"src": "android"
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|