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,653 @@
|
|
|
1
|
+
export interface NativeEmbeddingParams {
|
|
2
|
+
embd_normalize?: number;
|
|
3
|
+
}
|
|
4
|
+
export interface NativeContextParams {
|
|
5
|
+
model: string;
|
|
6
|
+
/**
|
|
7
|
+
* Chat template to override the default one from the model.
|
|
8
|
+
*/
|
|
9
|
+
chat_template?: string;
|
|
10
|
+
is_model_asset?: boolean;
|
|
11
|
+
use_progress_callback?: boolean;
|
|
12
|
+
n_ctx?: number;
|
|
13
|
+
n_batch?: number;
|
|
14
|
+
n_ubatch?: number;
|
|
15
|
+
n_threads?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Number of layers to store in VRAM (Currently only for iOS)
|
|
18
|
+
*/
|
|
19
|
+
n_gpu_layers?: number;
|
|
20
|
+
/**
|
|
21
|
+
* Skip GPU devices (iOS only)
|
|
22
|
+
*/
|
|
23
|
+
no_gpu_devices?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Enable flash attention, only recommended in GPU device (Experimental in llama.cpp)
|
|
26
|
+
*/
|
|
27
|
+
flash_attn?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* KV cache data type for the K (Experimental in llama.cpp)
|
|
30
|
+
*/
|
|
31
|
+
cache_type_k?: string;
|
|
32
|
+
/**
|
|
33
|
+
* KV cache data type for the V (Experimental in llama.cpp)
|
|
34
|
+
*/
|
|
35
|
+
cache_type_v?: string;
|
|
36
|
+
use_mlock?: boolean;
|
|
37
|
+
use_mmap?: boolean;
|
|
38
|
+
vocab_only?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Single LoRA adapter path
|
|
41
|
+
*/
|
|
42
|
+
lora?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Single LoRA adapter scale
|
|
45
|
+
*/
|
|
46
|
+
lora_scaled?: number;
|
|
47
|
+
/**
|
|
48
|
+
* LoRA adapter list
|
|
49
|
+
*/
|
|
50
|
+
lora_list?: Array<{
|
|
51
|
+
path: string;
|
|
52
|
+
scaled?: number;
|
|
53
|
+
}>;
|
|
54
|
+
rope_freq_base?: number;
|
|
55
|
+
rope_freq_scale?: number;
|
|
56
|
+
pooling_type?: number;
|
|
57
|
+
/**
|
|
58
|
+
* Enable context shifting to handle prompts larger than context size
|
|
59
|
+
*/
|
|
60
|
+
ctx_shift?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Use a unified buffer across the input sequences when computing the attention.
|
|
63
|
+
* Try to disable when n_seq_max > 1 for improved performance when the sequences do not share a large prefix.
|
|
64
|
+
*/
|
|
65
|
+
kv_unified?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* Use full-size SWA cache (https://github.com/ggml-org/llama.cpp/pull/13194#issuecomment-2868343055)
|
|
68
|
+
*/
|
|
69
|
+
swa_full?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Number of layers to keep MoE weights on CPU
|
|
72
|
+
*/
|
|
73
|
+
n_cpu_moe?: number;
|
|
74
|
+
embedding?: boolean;
|
|
75
|
+
embd_normalize?: number;
|
|
76
|
+
}
|
|
77
|
+
export interface NativeCompletionParams {
|
|
78
|
+
prompt: string;
|
|
79
|
+
n_threads?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Enable Jinja. Default: true if supported by the model
|
|
82
|
+
*/
|
|
83
|
+
jinja?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* JSON schema for convert to grammar for structured JSON output.
|
|
86
|
+
* It will be override by grammar if both are set.
|
|
87
|
+
*/
|
|
88
|
+
json_schema?: string;
|
|
89
|
+
/**
|
|
90
|
+
* Set grammar for grammar-based sampling. Default: no grammar
|
|
91
|
+
*/
|
|
92
|
+
grammar?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Lazy grammar sampling, trigger by grammar_triggers. Default: false
|
|
95
|
+
*/
|
|
96
|
+
grammar_lazy?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Enable thinking if jinja is enabled. Default: true
|
|
99
|
+
*/
|
|
100
|
+
enable_thinking?: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Force thinking to be open. Default: false
|
|
103
|
+
*/
|
|
104
|
+
thinking_forced_open?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Lazy grammar triggers. Default: []
|
|
107
|
+
*/
|
|
108
|
+
grammar_triggers?: Array<{
|
|
109
|
+
type: number;
|
|
110
|
+
value: string;
|
|
111
|
+
token: number;
|
|
112
|
+
}>;
|
|
113
|
+
preserved_tokens?: Array<string>;
|
|
114
|
+
chat_format?: number;
|
|
115
|
+
reasoning_format?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Path to an image file to process before generating text.
|
|
118
|
+
* When provided, the image will be processed and added to the context.
|
|
119
|
+
* Requires multimodal support to be enabled via initMultimodal.
|
|
120
|
+
*/
|
|
121
|
+
media_paths?: Array<string>;
|
|
122
|
+
/**
|
|
123
|
+
* Specify a JSON array of stopping strings.
|
|
124
|
+
* These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`
|
|
125
|
+
*/
|
|
126
|
+
stop?: Array<string>;
|
|
127
|
+
/**
|
|
128
|
+
* Set the maximum number of tokens to predict when generating text.
|
|
129
|
+
* **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.
|
|
130
|
+
* When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.
|
|
131
|
+
*/
|
|
132
|
+
n_predict?: number;
|
|
133
|
+
/**
|
|
134
|
+
* If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.
|
|
135
|
+
* Note that for temperature < 0 the tokens are sampled greedily but token probabilities are still being calculated via a simple softmax of the logits without considering any other sampler settings.
|
|
136
|
+
* Default: `0`
|
|
137
|
+
*/
|
|
138
|
+
n_probs?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Limit the next token selection to the K most probable tokens. Default: `40`
|
|
141
|
+
*/
|
|
142
|
+
top_k?: number;
|
|
143
|
+
/**
|
|
144
|
+
* Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`
|
|
145
|
+
*/
|
|
146
|
+
top_p?: number;
|
|
147
|
+
/**
|
|
148
|
+
* The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`
|
|
149
|
+
*/
|
|
150
|
+
min_p?: number;
|
|
151
|
+
/**
|
|
152
|
+
* Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.
|
|
153
|
+
*/
|
|
154
|
+
xtc_probability?: number;
|
|
155
|
+
/**
|
|
156
|
+
* Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)
|
|
157
|
+
*/
|
|
158
|
+
xtc_threshold?: number;
|
|
159
|
+
/**
|
|
160
|
+
* Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.
|
|
161
|
+
*/
|
|
162
|
+
typical_p?: number;
|
|
163
|
+
/**
|
|
164
|
+
* Adjust the randomness of the generated text. Default: `0.8`
|
|
165
|
+
*/
|
|
166
|
+
temperature?: number;
|
|
167
|
+
/**
|
|
168
|
+
* Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.
|
|
169
|
+
*/
|
|
170
|
+
penalty_last_n?: number;
|
|
171
|
+
/**
|
|
172
|
+
* Control the repetition of token sequences in the generated text. Default: `1.0`
|
|
173
|
+
*/
|
|
174
|
+
penalty_repeat?: number;
|
|
175
|
+
/**
|
|
176
|
+
* Repeat alpha frequency penalty. Default: `0.0`, which is disabled.
|
|
177
|
+
*/
|
|
178
|
+
penalty_freq?: number;
|
|
179
|
+
/**
|
|
180
|
+
* Repeat alpha presence penalty. Default: `0.0`, which is disabled.
|
|
181
|
+
*/
|
|
182
|
+
penalty_present?: number;
|
|
183
|
+
/**
|
|
184
|
+
* Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.
|
|
185
|
+
*/
|
|
186
|
+
mirostat?: number;
|
|
187
|
+
/**
|
|
188
|
+
* Set the Mirostat target entropy, parameter tau. Default: `5.0`
|
|
189
|
+
*/
|
|
190
|
+
mirostat_tau?: number;
|
|
191
|
+
/**
|
|
192
|
+
* Set the Mirostat learning rate, parameter eta. Default: `0.1`
|
|
193
|
+
*/
|
|
194
|
+
mirostat_eta?: number;
|
|
195
|
+
/**
|
|
196
|
+
* Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.
|
|
197
|
+
*/
|
|
198
|
+
dry_multiplier?: number;
|
|
199
|
+
/**
|
|
200
|
+
* Set the DRY repetition penalty base value. Default: `1.75`
|
|
201
|
+
*/
|
|
202
|
+
dry_base?: number;
|
|
203
|
+
/**
|
|
204
|
+
* Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`
|
|
205
|
+
*/
|
|
206
|
+
dry_allowed_length?: number;
|
|
207
|
+
/**
|
|
208
|
+
* How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.
|
|
209
|
+
*/
|
|
210
|
+
dry_penalty_last_n?: number;
|
|
211
|
+
/**
|
|
212
|
+
* Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\n', ':', '"', '*']`
|
|
213
|
+
*/
|
|
214
|
+
dry_sequence_breakers?: Array<string>;
|
|
215
|
+
/**
|
|
216
|
+
* Top n sigma sampling as described in academic paper "Top-nσ: Not All Logits Are You Need" https://arxiv.org/pdf/2411.07641. Default: `-1.0` (Disabled)
|
|
217
|
+
*/
|
|
218
|
+
top_n_sigma?: number;
|
|
219
|
+
/**
|
|
220
|
+
* Ignore end of stream token and continue generating. Default: `false`
|
|
221
|
+
*/
|
|
222
|
+
ignore_eos?: boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Modify the likelihood of a token appearing in the generated text completion.
|
|
225
|
+
* For example, use `"logit_bias": [[15043,1.0]]` to increase the likelihood of the token 'Hello', or `"logit_bias": [[15043,-1.0]]` to decrease its likelihood.
|
|
226
|
+
* Setting the value to false, `"logit_bias": [[15043,false]]` ensures that the token `Hello` is never produced. The tokens can also be represented as strings,
|
|
227
|
+
* e.g.`[["Hello, World!",-0.5]]` will reduce the likelihood of all the individual tokens that represent the string `Hello, World!`, just like the `presence_penalty` does.
|
|
228
|
+
* Default: `[]`
|
|
229
|
+
*/
|
|
230
|
+
logit_bias?: Array<Array<number>>;
|
|
231
|
+
/**
|
|
232
|
+
* Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.
|
|
233
|
+
*/
|
|
234
|
+
seed?: number;
|
|
235
|
+
/**
|
|
236
|
+
* Guide tokens for the completion.
|
|
237
|
+
* Help prevent hallucinations by forcing the TTS to use the correct words.
|
|
238
|
+
* Default: `[]`
|
|
239
|
+
*/
|
|
240
|
+
guide_tokens?: Array<number>;
|
|
241
|
+
emit_partial_completion: boolean;
|
|
242
|
+
}
|
|
243
|
+
export interface NativeCompletionTokenProbItem {
|
|
244
|
+
tok_str: string;
|
|
245
|
+
prob: number;
|
|
246
|
+
}
|
|
247
|
+
export interface NativeCompletionTokenProb {
|
|
248
|
+
content: string;
|
|
249
|
+
probs: Array<NativeCompletionTokenProbItem>;
|
|
250
|
+
}
|
|
251
|
+
export interface NativeCompletionResultTimings {
|
|
252
|
+
prompt_n: number;
|
|
253
|
+
prompt_ms: number;
|
|
254
|
+
prompt_per_token_ms: number;
|
|
255
|
+
prompt_per_second: number;
|
|
256
|
+
predicted_n: number;
|
|
257
|
+
predicted_ms: number;
|
|
258
|
+
predicted_per_token_ms: number;
|
|
259
|
+
predicted_per_second: number;
|
|
260
|
+
}
|
|
261
|
+
export interface NativeCompletionResult {
|
|
262
|
+
/**
|
|
263
|
+
* Original text (Ignored reasoning_content / tool_calls)
|
|
264
|
+
*/
|
|
265
|
+
text: string;
|
|
266
|
+
/**
|
|
267
|
+
* Reasoning content (parsed for reasoning model)
|
|
268
|
+
*/
|
|
269
|
+
reasoning_content: string;
|
|
270
|
+
/**
|
|
271
|
+
* Tool calls
|
|
272
|
+
*/
|
|
273
|
+
tool_calls: Array<{
|
|
274
|
+
type: 'function';
|
|
275
|
+
function: {
|
|
276
|
+
name: string;
|
|
277
|
+
arguments: string;
|
|
278
|
+
};
|
|
279
|
+
id?: string;
|
|
280
|
+
}>;
|
|
281
|
+
/**
|
|
282
|
+
* Content text (Filtered text by reasoning_content / tool_calls)
|
|
283
|
+
*/
|
|
284
|
+
content: string;
|
|
285
|
+
chat_format: number;
|
|
286
|
+
tokens_predicted: number;
|
|
287
|
+
tokens_evaluated: number;
|
|
288
|
+
truncated: boolean;
|
|
289
|
+
stopped_eos: boolean;
|
|
290
|
+
stopped_word: string;
|
|
291
|
+
stopped_limit: number;
|
|
292
|
+
stopping_word: string;
|
|
293
|
+
context_full: boolean;
|
|
294
|
+
interrupted: boolean;
|
|
295
|
+
tokens_cached: number;
|
|
296
|
+
timings: NativeCompletionResultTimings;
|
|
297
|
+
completion_probabilities?: Array<NativeCompletionTokenProb>;
|
|
298
|
+
audio_tokens?: Array<number>;
|
|
299
|
+
}
|
|
300
|
+
export interface NativeTokenizeResult {
|
|
301
|
+
tokens: Array<number>;
|
|
302
|
+
/**
|
|
303
|
+
* Whether the tokenization contains images
|
|
304
|
+
*/
|
|
305
|
+
has_images: boolean;
|
|
306
|
+
/**
|
|
307
|
+
* Bitmap hashes of the images
|
|
308
|
+
*/
|
|
309
|
+
bitmap_hashes: Array<number>;
|
|
310
|
+
/**
|
|
311
|
+
* Chunk positions of the text and images
|
|
312
|
+
*/
|
|
313
|
+
chunk_pos: Array<number>;
|
|
314
|
+
/**
|
|
315
|
+
* Chunk positions of the images
|
|
316
|
+
*/
|
|
317
|
+
chunk_pos_images: Array<number>;
|
|
318
|
+
}
|
|
319
|
+
export interface NativeEmbeddingResult {
|
|
320
|
+
embedding: Array<number>;
|
|
321
|
+
}
|
|
322
|
+
export interface NativeLlamaContext {
|
|
323
|
+
contextId: number;
|
|
324
|
+
model: {
|
|
325
|
+
desc: string;
|
|
326
|
+
size: number;
|
|
327
|
+
nEmbd: number;
|
|
328
|
+
nParams: number;
|
|
329
|
+
chatTemplates: {
|
|
330
|
+
llamaChat: boolean;
|
|
331
|
+
minja: {
|
|
332
|
+
default: boolean;
|
|
333
|
+
defaultCaps: {
|
|
334
|
+
tools: boolean;
|
|
335
|
+
toolCalls: boolean;
|
|
336
|
+
toolResponses: boolean;
|
|
337
|
+
systemRole: boolean;
|
|
338
|
+
parallelToolCalls: boolean;
|
|
339
|
+
toolCallId: boolean;
|
|
340
|
+
};
|
|
341
|
+
toolUse: boolean;
|
|
342
|
+
toolUseCaps: {
|
|
343
|
+
tools: boolean;
|
|
344
|
+
toolCalls: boolean;
|
|
345
|
+
toolResponses: boolean;
|
|
346
|
+
systemRole: boolean;
|
|
347
|
+
parallelToolCalls: boolean;
|
|
348
|
+
toolCallId: boolean;
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
};
|
|
352
|
+
metadata: Object;
|
|
353
|
+
isChatTemplateSupported: boolean;
|
|
354
|
+
};
|
|
355
|
+
/**
|
|
356
|
+
* Loaded library name for Android
|
|
357
|
+
*/
|
|
358
|
+
androidLib?: string;
|
|
359
|
+
gpu: boolean;
|
|
360
|
+
reasonNoGPU: string;
|
|
361
|
+
}
|
|
362
|
+
export interface NativeSessionLoadResult {
|
|
363
|
+
tokens_loaded: number;
|
|
364
|
+
prompt: string;
|
|
365
|
+
}
|
|
366
|
+
export interface NativeLlamaMessagePart {
|
|
367
|
+
type: 'text';
|
|
368
|
+
text: string;
|
|
369
|
+
}
|
|
370
|
+
export interface NativeLlamaChatMessage {
|
|
371
|
+
role: string;
|
|
372
|
+
content: string | Array<NativeLlamaMessagePart>;
|
|
373
|
+
}
|
|
374
|
+
export interface FormattedChatResult {
|
|
375
|
+
type: 'jinja' | 'llama-chat';
|
|
376
|
+
prompt: string;
|
|
377
|
+
has_media: boolean;
|
|
378
|
+
media_paths?: Array<string>;
|
|
379
|
+
}
|
|
380
|
+
export interface JinjaFormattedChatResult extends FormattedChatResult {
|
|
381
|
+
chat_format?: number;
|
|
382
|
+
grammar?: string;
|
|
383
|
+
grammar_lazy?: boolean;
|
|
384
|
+
grammar_triggers?: Array<{
|
|
385
|
+
type: number;
|
|
386
|
+
value: string;
|
|
387
|
+
token: number;
|
|
388
|
+
}>;
|
|
389
|
+
thinking_forced_open?: boolean;
|
|
390
|
+
preserved_tokens?: Array<string>;
|
|
391
|
+
additional_stops?: Array<string>;
|
|
392
|
+
}
|
|
393
|
+
export interface NativeImageProcessingResult {
|
|
394
|
+
success: boolean;
|
|
395
|
+
prompt: string;
|
|
396
|
+
error?: string;
|
|
397
|
+
}
|
|
398
|
+
export interface NativeRerankParams {
|
|
399
|
+
normalize?: number;
|
|
400
|
+
}
|
|
401
|
+
export interface NativeRerankResult {
|
|
402
|
+
score: number;
|
|
403
|
+
index: number;
|
|
404
|
+
}
|
|
405
|
+
export interface LlamaCppMessagePart {
|
|
406
|
+
type: string;
|
|
407
|
+
text?: string;
|
|
408
|
+
image_url?: {
|
|
409
|
+
url?: string;
|
|
410
|
+
};
|
|
411
|
+
input_audio?: {
|
|
412
|
+
format: string;
|
|
413
|
+
data?: string;
|
|
414
|
+
url?: string;
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
export interface LlamaCppOAICompatibleMessage {
|
|
418
|
+
role: string;
|
|
419
|
+
content?: string | LlamaCppMessagePart[];
|
|
420
|
+
}
|
|
421
|
+
export interface ToolCall {
|
|
422
|
+
type: 'function';
|
|
423
|
+
id?: string;
|
|
424
|
+
function: {
|
|
425
|
+
name: string;
|
|
426
|
+
arguments: string;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
export interface TokenData {
|
|
430
|
+
token: string;
|
|
431
|
+
completion_probabilities?: Array<NativeCompletionTokenProb>;
|
|
432
|
+
content?: string;
|
|
433
|
+
reasoning_content?: string;
|
|
434
|
+
tool_calls?: Array<ToolCall>;
|
|
435
|
+
accumulated_text?: string;
|
|
436
|
+
}
|
|
437
|
+
export interface ContextParams extends Omit<NativeContextParams, 'cache_type_k' | 'cache_type_v' | 'pooling_type'> {
|
|
438
|
+
cache_type_k?: 'f16' | 'f32' | 'q8_0' | 'q4_0' | 'q4_1' | 'iq4_nl' | 'q5_0' | 'q5_1';
|
|
439
|
+
cache_type_v?: 'f16' | 'f32' | 'q8_0' | 'q4_0' | 'q4_1' | 'iq4_nl' | 'q5_0' | 'q5_1';
|
|
440
|
+
pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank';
|
|
441
|
+
}
|
|
442
|
+
export interface EmbeddingParams extends NativeEmbeddingParams {
|
|
443
|
+
}
|
|
444
|
+
export interface RerankParams {
|
|
445
|
+
normalize?: number;
|
|
446
|
+
}
|
|
447
|
+
export interface RerankResult {
|
|
448
|
+
score: number;
|
|
449
|
+
index: number;
|
|
450
|
+
document?: string;
|
|
451
|
+
}
|
|
452
|
+
export interface CompletionResponseFormat {
|
|
453
|
+
type: 'text' | 'json_object' | 'json_schema';
|
|
454
|
+
json_schema?: {
|
|
455
|
+
strict?: boolean;
|
|
456
|
+
schema: object;
|
|
457
|
+
};
|
|
458
|
+
schema?: object;
|
|
459
|
+
}
|
|
460
|
+
export interface CompletionBaseParams {
|
|
461
|
+
prompt?: string;
|
|
462
|
+
messages?: LlamaCppOAICompatibleMessage[];
|
|
463
|
+
chatTemplate?: string;
|
|
464
|
+
chat_template?: string;
|
|
465
|
+
jinja?: boolean;
|
|
466
|
+
tools?: object;
|
|
467
|
+
parallel_tool_calls?: object;
|
|
468
|
+
tool_choice?: string;
|
|
469
|
+
response_format?: CompletionResponseFormat;
|
|
470
|
+
media_paths?: string[];
|
|
471
|
+
add_generation_prompt?: boolean;
|
|
472
|
+
now?: string | number;
|
|
473
|
+
chat_template_kwargs?: Record<string, string>;
|
|
474
|
+
/**
|
|
475
|
+
* Prefill text to be used for chat parsing (Generation Prompt + Content)
|
|
476
|
+
* Used for if last assistant message is for prefill purpose
|
|
477
|
+
*/
|
|
478
|
+
prefill_text?: string;
|
|
479
|
+
}
|
|
480
|
+
export interface CompletionParams extends Omit<NativeCompletionParams, 'emit_partial_completion' | 'prompt'> {
|
|
481
|
+
prompt?: string;
|
|
482
|
+
messages?: LlamaCppOAICompatibleMessage[];
|
|
483
|
+
chatTemplate?: string;
|
|
484
|
+
chat_template?: string;
|
|
485
|
+
jinja?: boolean;
|
|
486
|
+
tools?: object;
|
|
487
|
+
parallel_tool_calls?: object;
|
|
488
|
+
tool_choice?: string;
|
|
489
|
+
response_format?: CompletionResponseFormat;
|
|
490
|
+
media_paths?: string[];
|
|
491
|
+
add_generation_prompt?: boolean;
|
|
492
|
+
now?: string | number;
|
|
493
|
+
chat_template_kwargs?: Record<string, string>;
|
|
494
|
+
/**
|
|
495
|
+
* Prefill text to be used for chat parsing (Generation Prompt + Content)
|
|
496
|
+
* Used for if last assistant message is for prefill purpose
|
|
497
|
+
*/
|
|
498
|
+
prefill_text?: string;
|
|
499
|
+
}
|
|
500
|
+
export interface BenchResult {
|
|
501
|
+
modelDesc: string;
|
|
502
|
+
modelSize: number;
|
|
503
|
+
modelNParams: number;
|
|
504
|
+
ppAvg: number;
|
|
505
|
+
ppStd: number;
|
|
506
|
+
tgAvg: number;
|
|
507
|
+
tgStd: number;
|
|
508
|
+
}
|
|
509
|
+
export interface LlamaCppPlugin {
|
|
510
|
+
toggleNativeLog(options: {
|
|
511
|
+
enabled: boolean;
|
|
512
|
+
}): Promise<void>;
|
|
513
|
+
setContextLimit(options: {
|
|
514
|
+
limit: number;
|
|
515
|
+
}): Promise<void>;
|
|
516
|
+
modelInfo(options: {
|
|
517
|
+
path: string;
|
|
518
|
+
skip?: string[];
|
|
519
|
+
}): Promise<Object>;
|
|
520
|
+
initContext(options: {
|
|
521
|
+
contextId: number;
|
|
522
|
+
params: NativeContextParams;
|
|
523
|
+
}): Promise<NativeLlamaContext>;
|
|
524
|
+
releaseContext(options: {
|
|
525
|
+
contextId: number;
|
|
526
|
+
}): Promise<void>;
|
|
527
|
+
releaseAllContexts(): Promise<void>;
|
|
528
|
+
getFormattedChat(options: {
|
|
529
|
+
contextId: number;
|
|
530
|
+
messages: string;
|
|
531
|
+
chatTemplate?: string;
|
|
532
|
+
params?: {
|
|
533
|
+
jinja?: boolean;
|
|
534
|
+
json_schema?: string;
|
|
535
|
+
tools?: string;
|
|
536
|
+
parallel_tool_calls?: string;
|
|
537
|
+
tool_choice?: string;
|
|
538
|
+
enable_thinking?: boolean;
|
|
539
|
+
add_generation_prompt?: boolean;
|
|
540
|
+
now?: string;
|
|
541
|
+
chat_template_kwargs?: string;
|
|
542
|
+
};
|
|
543
|
+
}): Promise<JinjaFormattedChatResult | string>;
|
|
544
|
+
completion(options: {
|
|
545
|
+
contextId: number;
|
|
546
|
+
params: NativeCompletionParams;
|
|
547
|
+
}): Promise<NativeCompletionResult>;
|
|
548
|
+
stopCompletion(options: {
|
|
549
|
+
contextId: number;
|
|
550
|
+
}): Promise<void>;
|
|
551
|
+
loadSession(options: {
|
|
552
|
+
contextId: number;
|
|
553
|
+
filepath: string;
|
|
554
|
+
}): Promise<NativeSessionLoadResult>;
|
|
555
|
+
saveSession(options: {
|
|
556
|
+
contextId: number;
|
|
557
|
+
filepath: string;
|
|
558
|
+
size: number;
|
|
559
|
+
}): Promise<number>;
|
|
560
|
+
tokenize(options: {
|
|
561
|
+
contextId: number;
|
|
562
|
+
text: string;
|
|
563
|
+
imagePaths?: Array<string>;
|
|
564
|
+
}): Promise<NativeTokenizeResult>;
|
|
565
|
+
detokenize(options: {
|
|
566
|
+
contextId: number;
|
|
567
|
+
tokens: number[];
|
|
568
|
+
}): Promise<string>;
|
|
569
|
+
embedding(options: {
|
|
570
|
+
contextId: number;
|
|
571
|
+
text: string;
|
|
572
|
+
params: NativeEmbeddingParams;
|
|
573
|
+
}): Promise<NativeEmbeddingResult>;
|
|
574
|
+
rerank(options: {
|
|
575
|
+
contextId: number;
|
|
576
|
+
query: string;
|
|
577
|
+
documents: Array<string>;
|
|
578
|
+
params?: NativeRerankParams;
|
|
579
|
+
}): Promise<Array<NativeRerankResult>>;
|
|
580
|
+
bench(options: {
|
|
581
|
+
contextId: number;
|
|
582
|
+
pp: number;
|
|
583
|
+
tg: number;
|
|
584
|
+
pl: number;
|
|
585
|
+
nr: number;
|
|
586
|
+
}): Promise<string>;
|
|
587
|
+
applyLoraAdapters(options: {
|
|
588
|
+
contextId: number;
|
|
589
|
+
loraAdapters: Array<{
|
|
590
|
+
path: string;
|
|
591
|
+
scaled?: number;
|
|
592
|
+
}>;
|
|
593
|
+
}): Promise<void>;
|
|
594
|
+
removeLoraAdapters(options: {
|
|
595
|
+
contextId: number;
|
|
596
|
+
}): Promise<void>;
|
|
597
|
+
getLoadedLoraAdapters(options: {
|
|
598
|
+
contextId: number;
|
|
599
|
+
}): Promise<Array<{
|
|
600
|
+
path: string;
|
|
601
|
+
scaled?: number;
|
|
602
|
+
}>>;
|
|
603
|
+
initMultimodal(options: {
|
|
604
|
+
contextId: number;
|
|
605
|
+
params: {
|
|
606
|
+
path: string;
|
|
607
|
+
use_gpu: boolean;
|
|
608
|
+
};
|
|
609
|
+
}): Promise<boolean>;
|
|
610
|
+
isMultimodalEnabled(options: {
|
|
611
|
+
contextId: number;
|
|
612
|
+
}): Promise<boolean>;
|
|
613
|
+
getMultimodalSupport(options: {
|
|
614
|
+
contextId: number;
|
|
615
|
+
}): Promise<{
|
|
616
|
+
vision: boolean;
|
|
617
|
+
audio: boolean;
|
|
618
|
+
}>;
|
|
619
|
+
releaseMultimodal(options: {
|
|
620
|
+
contextId: number;
|
|
621
|
+
}): Promise<void>;
|
|
622
|
+
initVocoder(options: {
|
|
623
|
+
contextId: number;
|
|
624
|
+
params: {
|
|
625
|
+
path: string;
|
|
626
|
+
n_batch?: number;
|
|
627
|
+
};
|
|
628
|
+
}): Promise<boolean>;
|
|
629
|
+
isVocoderEnabled(options: {
|
|
630
|
+
contextId: number;
|
|
631
|
+
}): Promise<boolean>;
|
|
632
|
+
getFormattedAudioCompletion(options: {
|
|
633
|
+
contextId: number;
|
|
634
|
+
speakerJsonStr: string;
|
|
635
|
+
textToSpeak: string;
|
|
636
|
+
}): Promise<{
|
|
637
|
+
prompt: string;
|
|
638
|
+
grammar?: string;
|
|
639
|
+
}>;
|
|
640
|
+
getAudioCompletionGuideTokens(options: {
|
|
641
|
+
contextId: number;
|
|
642
|
+
textToSpeak: string;
|
|
643
|
+
}): Promise<Array<number>>;
|
|
644
|
+
decodeAudioTokens(options: {
|
|
645
|
+
contextId: number;
|
|
646
|
+
tokens: number[];
|
|
647
|
+
}): Promise<Array<number>>;
|
|
648
|
+
releaseVocoder(options: {
|
|
649
|
+
contextId: number;
|
|
650
|
+
}): Promise<void>;
|
|
651
|
+
addListener(eventName: string, listenerFunc: (data: any) => void): Promise<void>;
|
|
652
|
+
removeAllListeners(eventName: string): Promise<void>;
|
|
653
|
+
}
|