cui-llama.rn 1.3.0 → 1.3.4
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/android/src/main/CMakeLists.txt +9 -6
- package/android/src/main/java/com/rnllama/LlamaContext.java +4 -4
- package/android/src/main/jni.cpp +15 -15
- package/cpp/common.cpp +1962 -1682
- package/cpp/common.h +645 -600
- package/cpp/ggml-alloc.c +1038 -1040
- package/cpp/ggml-alloc.h +76 -76
- package/cpp/ggml-backend-impl.h +256 -216
- package/cpp/ggml-backend-reg.cpp +552 -195
- package/cpp/ggml-backend.cpp +1999 -1997
- package/cpp/ggml-backend.h +352 -328
- package/cpp/ggml-common.h +1853 -1853
- package/cpp/ggml-cpp.h +38 -38
- package/cpp/{ggml-cpu-aarch64.c → ggml-cpu-aarch64.cpp} +4262 -3560
- package/cpp/ggml-cpu-aarch64.h +8 -30
- package/cpp/ggml-cpu-impl.h +386 -371
- package/cpp/ggml-cpu-quants.c +10835 -10822
- package/cpp/ggml-cpu-quants.h +63 -63
- package/cpp/ggml-cpu-traits.cpp +36 -0
- package/cpp/ggml-cpu-traits.h +38 -0
- package/cpp/ggml-cpu.c +14122 -13975
- package/cpp/ggml-cpu.cpp +618 -663
- package/cpp/ggml-cpu.h +135 -177
- package/cpp/ggml-impl.h +556 -550
- package/cpp/ggml-metal.h +66 -66
- package/cpp/ggml-metal.m +4884 -4294
- package/cpp/ggml-quants.c +5238 -5247
- package/cpp/ggml-quants.h +100 -100
- package/cpp/ggml-threading.cpp +12 -12
- package/cpp/ggml-threading.h +14 -12
- package/cpp/ggml.c +7707 -8180
- package/cpp/ggml.h +2286 -2411
- package/cpp/json-schema-to-grammar.cpp +1045 -0
- package/cpp/json-schema-to-grammar.h +8 -0
- package/cpp/json.hpp +24766 -0
- package/cpp/llama-grammar.cpp +1138 -1138
- package/cpp/llama-grammar.h +144 -144
- package/cpp/llama-impl.h +181 -181
- package/cpp/llama-sampling.cpp +2293 -2348
- package/cpp/llama-sampling.h +48 -48
- package/cpp/llama-vocab.cpp +1985 -1984
- package/cpp/llama-vocab.h +170 -170
- package/cpp/llama.cpp +22836 -22132
- package/cpp/llama.h +1263 -1253
- package/cpp/log.cpp +401 -401
- package/cpp/log.h +121 -121
- package/cpp/rn-llama.hpp +6 -6
- package/cpp/sampling.cpp +500 -466
- package/cpp/sampling.h +22 -1
- package/cpp/sgemm.cpp +1884 -1884
- package/cpp/speculative.cpp +274 -0
- package/cpp/speculative.h +28 -0
- package/cpp/unicode.cpp +62 -51
- package/cpp/unicode.h +9 -10
- package/ios/RNLlamaContext.mm +13 -0
- package/lib/commonjs/NativeRNLlama.js.map +1 -1
- package/lib/commonjs/grammar.js +4 -2
- package/lib/commonjs/grammar.js.map +1 -1
- package/lib/commonjs/index.js +38 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRNLlama.js.map +1 -1
- package/lib/module/grammar.js +2 -1
- package/lib/module/grammar.js.map +1 -1
- package/lib/module/index.js +36 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRNLlama.d.ts +95 -6
- package/lib/typescript/NativeRNLlama.d.ts.map +1 -1
- package/lib/typescript/grammar.d.ts +5 -6
- package/lib/typescript/grammar.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +40 -4
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/NativeRNLlama.ts +99 -12
- package/src/grammar.ts +10 -8
- package/src/index.ts +68 -3
- package/cpp/ggml-aarch64.c +0 -129
- package/cpp/ggml-aarch64.h +0 -19
@@ -17,11 +17,11 @@ export type NativeContextParams = {
|
|
17
17
|
/**
|
18
18
|
* KV cache data type for the K (Experimental in llama.cpp)
|
19
19
|
*/
|
20
|
-
cache_type_k?:
|
20
|
+
cache_type_k?: number;
|
21
21
|
/**
|
22
22
|
* KV cache data type for the V (Experimental in llama.cpp)
|
23
23
|
*/
|
24
|
-
cache_type_v?:
|
24
|
+
cache_type_v?: number;
|
25
25
|
use_mlock?: boolean;
|
26
26
|
use_mmap?: boolean;
|
27
27
|
vocab_only?: boolean;
|
@@ -35,34 +35,123 @@ export type NativeContextParams = {
|
|
35
35
|
};
|
36
36
|
export type NativeCompletionParams = {
|
37
37
|
prompt: string;
|
38
|
+
n_threads?: number;
|
39
|
+
/**
|
40
|
+
* Set grammar for grammar-based sampling. Default: no grammar
|
41
|
+
*/
|
38
42
|
grammar?: string;
|
43
|
+
/**
|
44
|
+
* Specify a JSON array of stopping strings.
|
45
|
+
* These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`
|
46
|
+
*/
|
39
47
|
stop?: Array<string>;
|
40
|
-
|
48
|
+
/**
|
49
|
+
* Set the maximum number of tokens to predict when generating text.
|
50
|
+
* **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.
|
51
|
+
* When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.
|
52
|
+
*/
|
41
53
|
n_predict?: number;
|
54
|
+
/**
|
55
|
+
* If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.
|
56
|
+
* 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.
|
57
|
+
* Default: `0`
|
58
|
+
*/
|
42
59
|
n_probs?: number;
|
60
|
+
/**
|
61
|
+
* Limit the next token selection to the K most probable tokens. Default: `40`
|
62
|
+
*/
|
43
63
|
top_k?: number;
|
64
|
+
/**
|
65
|
+
* Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`
|
66
|
+
*/
|
44
67
|
top_p?: number;
|
68
|
+
/**
|
69
|
+
* The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`
|
70
|
+
*/
|
45
71
|
min_p?: number;
|
46
|
-
|
72
|
+
/**
|
73
|
+
* Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.
|
74
|
+
*/
|
47
75
|
xtc_probability?: number;
|
76
|
+
/**
|
77
|
+
* Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)
|
78
|
+
*/
|
79
|
+
xtc_threshold?: number;
|
80
|
+
/**
|
81
|
+
* Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.
|
82
|
+
*/
|
48
83
|
typical_p?: number;
|
84
|
+
/**
|
85
|
+
* Adjust the randomness of the generated text. Default: `0.8`
|
86
|
+
*/
|
49
87
|
temperature?: number;
|
88
|
+
/**
|
89
|
+
* Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.
|
90
|
+
*/
|
50
91
|
penalty_last_n?: number;
|
92
|
+
/**
|
93
|
+
* Control the repetition of token sequences in the generated text. Default: `1.0`
|
94
|
+
*/
|
51
95
|
penalty_repeat?: number;
|
96
|
+
/**
|
97
|
+
* Repeat alpha frequency penalty. Default: `0.0`, which is disabled.
|
98
|
+
*/
|
52
99
|
penalty_freq?: number;
|
100
|
+
/**
|
101
|
+
* Repeat alpha presence penalty. Default: `0.0`, which is disabled.
|
102
|
+
*/
|
53
103
|
penalty_present?: number;
|
104
|
+
/**
|
105
|
+
* Penalize newline tokens when applying the repeat penalty. Default: `false`
|
106
|
+
*/
|
107
|
+
/**
|
108
|
+
* Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.
|
109
|
+
*/
|
54
110
|
mirostat?: number;
|
111
|
+
/**
|
112
|
+
* Set the Mirostat target entropy, parameter tau. Default: `5.0`
|
113
|
+
*/
|
55
114
|
mirostat_tau?: number;
|
115
|
+
/**
|
116
|
+
* Set the Mirostat learning rate, parameter eta. Default: `0.1`
|
117
|
+
*/
|
56
118
|
mirostat_eta?: number;
|
57
|
-
|
58
|
-
|
119
|
+
/**
|
120
|
+
* Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.
|
121
|
+
*/
|
59
122
|
dry_multiplier?: number;
|
123
|
+
/**
|
124
|
+
* Set the DRY repetition penalty base value. Default: `1.75`
|
125
|
+
*/
|
60
126
|
dry_base?: number;
|
127
|
+
/**
|
128
|
+
* Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`
|
129
|
+
*/
|
61
130
|
dry_allowed_length?: number;
|
131
|
+
/**
|
132
|
+
* How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.
|
133
|
+
*/
|
62
134
|
dry_penalty_last_n?: number;
|
135
|
+
/**
|
136
|
+
* Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\n', ':', '"', '*']`
|
137
|
+
*/
|
63
138
|
dry_sequence_breakers?: Array<string>;
|
139
|
+
/**
|
140
|
+
* Ignore end of stream token and continue generating. Default: `false`
|
141
|
+
*/
|
64
142
|
ignore_eos?: boolean;
|
143
|
+
/**
|
144
|
+
* Modify the likelihood of a token appearing in the generated text completion.
|
145
|
+
* 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.
|
146
|
+
* 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,
|
147
|
+
* 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.
|
148
|
+
* Default: `[]`
|
149
|
+
*/
|
65
150
|
logit_bias?: Array<Array<number>>;
|
151
|
+
/**
|
152
|
+
* Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.
|
153
|
+
*/
|
154
|
+
seed?: number;
|
66
155
|
emit_partial_completion: boolean;
|
67
156
|
};
|
68
157
|
export type NativeCompletionTokenProbItem = {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"NativeRNLlama.d.ts","sourceRoot":"","sources":["../../src/NativeRNLlama.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAA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AE,MAAM,EACjB,QAAQ,EAAE,sBAAsB,EAAE,EAClC,YAAY,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,MAAM,CAAC,CAAA;IAClB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAA;IAChE,SAAS,CACP,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC,CAAA;IACjC,KAAK,CACH,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,MAAM,GACT,OAAO,CAAC,MAAM,CAAC,CAAA;IAElB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAEhD,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACpC;;AAED,wBAA+D"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
declare class
|
1
|
+
export declare class SchemaGrammarConverterBuiltinRule {
|
2
2
|
content: string;
|
3
3
|
deps: string[];
|
4
4
|
constructor(content: string, deps: string[]);
|
5
5
|
}
|
6
|
-
interface
|
6
|
+
export interface SchemaGrammarConverterPropOrder {
|
7
7
|
[key: string]: number;
|
8
8
|
}
|
9
9
|
export declare class SchemaGrammarConverter {
|
@@ -14,7 +14,7 @@ export declare class SchemaGrammarConverter {
|
|
14
14
|
private _refs;
|
15
15
|
private _refsBeingResolved;
|
16
16
|
constructor(options: {
|
17
|
-
prop_order?:
|
17
|
+
prop_order?: SchemaGrammarConverterPropOrder;
|
18
18
|
allow_fetch?: boolean;
|
19
19
|
dotall?: boolean;
|
20
20
|
});
|
@@ -24,15 +24,14 @@ export declare class SchemaGrammarConverter {
|
|
24
24
|
_visitPattern(pattern: string, name: string): string;
|
25
25
|
_resolveRef(ref: string): string;
|
26
26
|
visit(schema: any, name: string): string;
|
27
|
-
_addPrimitive(name: string, rule:
|
27
|
+
_addPrimitive(name: string, rule: SchemaGrammarConverterBuiltinRule | undefined): string;
|
28
28
|
_buildObjectRule(properties: any[], required: Set<string>, name: string, additionalProperties: any): string;
|
29
29
|
formatGrammar(): string;
|
30
30
|
}
|
31
31
|
export declare const convertJsonSchemaToGrammar: ({ schema, propOrder, dotall, allowFetch, }: {
|
32
32
|
schema: any;
|
33
|
-
propOrder?:
|
33
|
+
propOrder?: SchemaGrammarConverterPropOrder | undefined;
|
34
34
|
dotall?: boolean | undefined;
|
35
35
|
allowFetch?: boolean | undefined;
|
36
36
|
}) => string | Promise<string>;
|
37
|
-
export {};
|
38
37
|
//# sourceMappingURL=grammar.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/grammar.ts"],"names":[],"mappings":"AA4EA,
|
1
|
+
{"version":3,"file":"grammar.d.ts","sourceRoot":"","sources":["../../src/grammar.ts"],"names":[],"mappings":"AA4EA,qBAAa,iCAAiC;IAC5C,OAAO,EAAE,MAAM,CAAA;IAEf,IAAI,EAAE,MAAM,EAAE,CAAA;gBAEF,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE;CAI5C;AA4FD,MAAM,WAAW,+BAA+B;IAC9C,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB;AAoBD,qBAAa,sBAAsB;IACjC,OAAO,CAAC,UAAU,CAAiC;IAEnD,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO,CAAC,OAAO,CAAS;IAExB,OAAO,CAAC,MAAM,CAA2B;IAEzC,OAAO,CAAC,KAAK,CAAwB;IAErC,OAAO,CAAC,kBAAkB,CAAa;gBAE3B,OAAO,EAAE;QACnB,UAAU,CAAC,EAAE,+BAA+B,CAAA;QAC5C,WAAW,CAAC,EAAE,OAAO,CAAA;QACrB,MAAM,CAAC,EAAE,OAAO,CAAA;KACjB;IASD,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAuBtC,WAAW,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAiEzD,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,GAAG,MAAM;IAW3D,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAmMpD,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAWhC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAoKxC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,iCAAiC,GAAG,SAAS;IAiB/E,gBAAgB,CACd,UAAU,EAAE,GAAG,EAAE,EACjB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,EACrB,IAAI,EAAE,MAAM,EACZ,oBAAoB,EAAE,GAAG;IAmG3B,aAAa;CASd;AAED,eAAO,MAAM,0BAA0B;YAM7B,GAAG;;;;MAIT,MAAM,GAAG,QAAQ,MAAM,CAe1B,CAAA"}
|
@@ -1,14 +1,50 @@
|
|
1
|
-
import type { NativeContextParams, NativeLlamaContext, NativeCompletionParams, NativeCompletionTokenProb, NativeCompletionResult, NativeTokenizeResult, NativeEmbeddingResult, NativeSessionLoadResult, NativeCPUFeatures, NativeEmbeddingParams } from './NativeRNLlama';
|
1
|
+
import type { NativeContextParams, NativeLlamaContext, NativeCompletionParams, NativeCompletionTokenProb, NativeCompletionResult, NativeTokenizeResult, NativeEmbeddingResult, NativeSessionLoadResult, NativeCPUFeatures, NativeEmbeddingParams, NativeCompletionTokenProbItem, NativeCompletionResultTimings } from './NativeRNLlama';
|
2
|
+
import type { SchemaGrammarConverterPropOrder, SchemaGrammarConverterBuiltinRule } from './grammar';
|
2
3
|
import { SchemaGrammarConverter, convertJsonSchemaToGrammar } from './grammar';
|
3
|
-
import type { RNLlamaOAICompatibleMessage } from './chat';
|
4
|
+
import type { RNLlamaMessagePart, RNLlamaOAICompatibleMessage } from './chat';
|
5
|
+
export type { NativeContextParams, NativeLlamaContext, NativeCompletionParams, NativeCompletionTokenProb, NativeCompletionResult, NativeTokenizeResult, NativeEmbeddingResult, NativeSessionLoadResult, NativeEmbeddingParams, NativeCompletionTokenProbItem, NativeCompletionResultTimings, RNLlamaMessagePart, RNLlamaOAICompatibleMessage, SchemaGrammarConverterPropOrder, SchemaGrammarConverterBuiltinRule, };
|
4
6
|
export { SchemaGrammarConverter, convertJsonSchemaToGrammar };
|
5
7
|
export type TokenData = {
|
6
8
|
token: string;
|
7
9
|
completion_probabilities?: Array<NativeCompletionTokenProb>;
|
8
10
|
};
|
11
|
+
export declare enum GGML_TYPE {
|
12
|
+
LM_GGML_TYPE_F32 = 0,
|
13
|
+
LM_GGML_TYPE_F16 = 1,
|
14
|
+
LM_GGML_TYPE_Q4_0 = 2,
|
15
|
+
LM_GGML_TYPE_Q4_1 = 3,
|
16
|
+
LM_GGML_TYPE_Q5_0 = 6,
|
17
|
+
LM_GGML_TYPE_Q5_1 = 7,
|
18
|
+
LM_GGML_TYPE_Q8_0 = 8,
|
19
|
+
LM_GGML_TYPE_Q8_1 = 9,
|
20
|
+
LM_GGML_TYPE_Q2_K = 10,
|
21
|
+
LM_GGML_TYPE_Q3_K = 11,
|
22
|
+
LM_GGML_TYPE_Q4_K = 12,
|
23
|
+
LM_GGML_TYPE_Q5_K = 13,
|
24
|
+
LM_GGML_TYPE_Q6_K = 14,
|
25
|
+
LM_GGML_TYPE_Q8_K = 15,
|
26
|
+
LM_GGML_TYPE_IQ2_XXS = 16,
|
27
|
+
LM_GGML_TYPE_IQ2_XS = 17,
|
28
|
+
LM_GGML_TYPE_IQ3_XXS = 18,
|
29
|
+
LM_GGML_TYPE_IQ1_S = 19,
|
30
|
+
LM_GGML_TYPE_IQ4_NL = 20,
|
31
|
+
LM_GGML_TYPE_IQ3_S = 21,
|
32
|
+
LM_GGML_TYPE_IQ2_S = 22,
|
33
|
+
LM_GGML_TYPE_IQ4_XS = 23,
|
34
|
+
LM_GGML_TYPE_I8 = 24,
|
35
|
+
LM_GGML_TYPE_I16 = 25,
|
36
|
+
LM_GGML_TYPE_I32 = 26,
|
37
|
+
LM_GGML_TYPE_I64 = 27,
|
38
|
+
LM_GGML_TYPE_F64 = 28,
|
39
|
+
LM_GGML_TYPE_IQ1_M = 29,
|
40
|
+
LM_GGML_TYPE_BF16 = 30,
|
41
|
+
LM_GGML_TYPE_TQ1_0 = 34,
|
42
|
+
LM_GGML_TYPE_TQ2_0 = 35,
|
43
|
+
LM_GGML_TYPE_COUNT = 39
|
44
|
+
}
|
9
45
|
export type ContextParams = Omit<NativeContextParams, 'cache_type_k' | 'cache_type_v' | 'pooling_type'> & {
|
10
|
-
cache_type_k?:
|
11
|
-
cache_type_v?:
|
46
|
+
cache_type_k?: GGML_TYPE;
|
47
|
+
cache_type_v?: GGML_TYPE;
|
12
48
|
pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank';
|
13
49
|
};
|
14
50
|
export type EmbeddingParams = NativeEmbeddingParams;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,EACvB,iBAAiB,EACjB,qBAAqB,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,mBAAmB,EACnB,kBAAkB,EAClB,sBAAsB,EACtB,yBAAyB,EACzB,sBAAsB,EACtB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,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,EACL,cAAc,EAAE,YAAY,EAC5B,YAAY,EAAE,WAAW,EACzB,IAAI,EACJ,GAAG,IAAI,EACR,EAAE,aAAa,EAChB,UAAU,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,GACtC,OAAO,CAAC,YAAY,CAAC,CAuCvB;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAErD"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "cui-llama.rn",
|
3
|
-
"version": "1.3.
|
3
|
+
"version": "1.3.4",
|
4
4
|
"description": "Fork of llama.rn for ChatterUI",
|
5
5
|
"main": "lib/commonjs/index",
|
6
6
|
"module": "lib/module/index",
|
@@ -14,6 +14,7 @@
|
|
14
14
|
"ios",
|
15
15
|
"android",
|
16
16
|
"cpp/*.*",
|
17
|
+
"cpp/amx/*.*",
|
17
18
|
"*.podspec",
|
18
19
|
"!lib/typescript/example",
|
19
20
|
"!ios/build",
|
package/src/NativeRNLlama.ts
CHANGED
@@ -24,11 +24,11 @@ export type NativeContextParams = {
|
|
24
24
|
/**
|
25
25
|
* KV cache data type for the K (Experimental in llama.cpp)
|
26
26
|
*/
|
27
|
-
cache_type_k?:
|
27
|
+
cache_type_k?: number
|
28
28
|
/**
|
29
29
|
* KV cache data type for the V (Experimental in llama.cpp)
|
30
30
|
*/
|
31
|
-
cache_type_v?:
|
31
|
+
cache_type_v?: number
|
32
32
|
|
33
33
|
use_mlock?: boolean
|
34
34
|
use_mmap?: boolean
|
@@ -49,37 +49,124 @@ export type NativeContextParams = {
|
|
49
49
|
|
50
50
|
export type NativeCompletionParams = {
|
51
51
|
prompt: string
|
52
|
-
grammar?: string
|
53
|
-
stop?: Array<string> // -> antiprompt
|
54
|
-
|
55
52
|
n_threads?: number
|
53
|
+
/**
|
54
|
+
* Set grammar for grammar-based sampling. Default: no grammar
|
55
|
+
*/
|
56
|
+
grammar?: string
|
57
|
+
/**
|
58
|
+
* Specify a JSON array of stopping strings.
|
59
|
+
* These words will not be included in the completion, so make sure to add them to the prompt for the next iteration. Default: `[]`
|
60
|
+
*/
|
61
|
+
stop?: Array<string>
|
62
|
+
/**
|
63
|
+
* Set the maximum number of tokens to predict when generating text.
|
64
|
+
* **Note:** May exceed the set limit slightly if the last token is a partial multibyte character.
|
65
|
+
* When 0,no tokens will be generated but the prompt is evaluated into the cache. Default: `-1`, where `-1` is infinity.
|
66
|
+
*/
|
56
67
|
n_predict?: number
|
68
|
+
/**
|
69
|
+
* If greater than 0, the response also contains the probabilities of top N tokens for each generated token given the sampling settings.
|
70
|
+
* 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.
|
71
|
+
* Default: `0`
|
72
|
+
*/
|
57
73
|
n_probs?: number
|
74
|
+
/**
|
75
|
+
* Limit the next token selection to the K most probable tokens. Default: `40`
|
76
|
+
*/
|
58
77
|
top_k?: number
|
78
|
+
/**
|
79
|
+
* Limit the next token selection to a subset of tokens with a cumulative probability above a threshold P. Default: `0.95`
|
80
|
+
*/
|
59
81
|
top_p?: number
|
82
|
+
/**
|
83
|
+
* The minimum probability for a token to be considered, relative to the probability of the most likely token. Default: `0.05`
|
84
|
+
*/
|
60
85
|
min_p?: number
|
61
|
-
|
86
|
+
/**
|
87
|
+
* Set the chance for token removal via XTC sampler. Default: `0.0`, which is disabled.
|
88
|
+
*/
|
62
89
|
xtc_probability?: number
|
90
|
+
/**
|
91
|
+
* Set a minimum probability threshold for tokens to be removed via XTC sampler. Default: `0.1` (> `0.5` disables XTC)
|
92
|
+
*/
|
93
|
+
xtc_threshold?: number
|
94
|
+
/**
|
95
|
+
* Enable locally typical sampling with parameter p. Default: `1.0`, which is disabled.
|
96
|
+
*/
|
63
97
|
typical_p?: number
|
64
|
-
|
98
|
+
/**
|
99
|
+
* Adjust the randomness of the generated text. Default: `0.8`
|
100
|
+
*/
|
101
|
+
temperature?: number
|
102
|
+
/**
|
103
|
+
* Last n tokens to consider for penalizing repetition. Default: `64`, where `0` is disabled and `-1` is ctx-size.
|
104
|
+
*/
|
65
105
|
penalty_last_n?: number
|
106
|
+
/**
|
107
|
+
* Control the repetition of token sequences in the generated text. Default: `1.0`
|
108
|
+
*/
|
66
109
|
penalty_repeat?: number
|
110
|
+
/**
|
111
|
+
* Repeat alpha frequency penalty. Default: `0.0`, which is disabled.
|
112
|
+
*/
|
67
113
|
penalty_freq?: number
|
114
|
+
/**
|
115
|
+
* Repeat alpha presence penalty. Default: `0.0`, which is disabled.
|
116
|
+
*/
|
68
117
|
penalty_present?: number
|
118
|
+
/**
|
119
|
+
* Penalize newline tokens when applying the repeat penalty. Default: `false`
|
120
|
+
*/
|
121
|
+
// penalize_nl?: boolean
|
122
|
+
/**
|
123
|
+
* Enable Mirostat sampling, controlling perplexity during text generation. Default: `0`, where `0` is disabled, `1` is Mirostat, and `2` is Mirostat 2.0.
|
124
|
+
*/
|
69
125
|
mirostat?: number
|
126
|
+
/**
|
127
|
+
* Set the Mirostat target entropy, parameter tau. Default: `5.0`
|
128
|
+
*/
|
70
129
|
mirostat_tau?: number
|
130
|
+
/**
|
131
|
+
* Set the Mirostat learning rate, parameter eta. Default: `0.1`
|
132
|
+
*/
|
71
133
|
mirostat_eta?: number
|
72
|
-
|
73
|
-
|
74
|
-
|
134
|
+
/**
|
135
|
+
* Set the DRY (Don't Repeat Yourself) repetition penalty multiplier. Default: `0.0`, which is disabled.
|
136
|
+
*/
|
75
137
|
dry_multiplier?: number
|
138
|
+
/**
|
139
|
+
* Set the DRY repetition penalty base value. Default: `1.75`
|
140
|
+
*/
|
76
141
|
dry_base?: number
|
77
|
-
|
142
|
+
/**
|
143
|
+
* Tokens that extend repetition beyond this receive exponentially increasing penalty: multiplier * base ^ (length of repeating sequence before token - allowed length). Default: `2`
|
144
|
+
*/
|
145
|
+
dry_allowed_length?: number
|
146
|
+
/**
|
147
|
+
* How many tokens to scan for repetitions. Default: `-1`, where `0` is disabled and `-1` is context size.
|
148
|
+
*/
|
78
149
|
dry_penalty_last_n?: number
|
150
|
+
/**
|
151
|
+
* Specify an array of sequence breakers for DRY sampling. Only a JSON array of strings is accepted. Default: `['\n', ':', '"', '*']`
|
152
|
+
*/
|
79
153
|
dry_sequence_breakers?: Array<string>
|
80
|
-
|
154
|
+
/**
|
155
|
+
* Ignore end of stream token and continue generating. Default: `false`
|
156
|
+
*/
|
81
157
|
ignore_eos?: boolean
|
158
|
+
/**
|
159
|
+
* Modify the likelihood of a token appearing in the generated text completion.
|
160
|
+
* 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.
|
161
|
+
* 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,
|
162
|
+
* 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.
|
163
|
+
* Default: `[]`
|
164
|
+
*/
|
82
165
|
logit_bias?: Array<Array<number>>
|
166
|
+
/**
|
167
|
+
* Set the random number generator (RNG) seed. Default: `-1`, which is a random seed.
|
168
|
+
*/
|
169
|
+
seed?: number
|
83
170
|
|
84
171
|
emit_partial_completion: boolean
|
85
172
|
}
|
package/src/grammar.ts
CHANGED
@@ -74,7 +74,7 @@ function buildRepetition(
|
|
74
74
|
return result
|
75
75
|
}
|
76
76
|
|
77
|
-
class
|
77
|
+
export class SchemaGrammarConverterBuiltinRule {
|
78
78
|
content: string
|
79
79
|
|
80
80
|
deps: string[]
|
@@ -85,9 +85,11 @@ class BuiltinRule {
|
|
85
85
|
}
|
86
86
|
}
|
87
87
|
|
88
|
+
const BuiltinRule = SchemaGrammarConverterBuiltinRule
|
89
|
+
|
88
90
|
const UP_TO_15_DIGITS = buildRepetition('[0-9]', 0, 15)
|
89
91
|
|
90
|
-
const PRIMITIVE_RULES: { [key: string]:
|
92
|
+
const PRIMITIVE_RULES: { [key: string]: SchemaGrammarConverterBuiltinRule } = {
|
91
93
|
boolean: new BuiltinRule('("true" | "false") space', []),
|
92
94
|
'decimal-part': new BuiltinRule(`[0-9] ${UP_TO_15_DIGITS}`, []),
|
93
95
|
'integral-part': new BuiltinRule(`[0-9] | [1-9] ${UP_TO_15_DIGITS}`, []),
|
@@ -126,7 +128,7 @@ const PRIMITIVE_RULES: { [key: string]: BuiltinRule } = {
|
|
126
128
|
}
|
127
129
|
|
128
130
|
// TODO: support "uri", "email" string formats
|
129
|
-
const STRING_FORMAT_RULES: { [key: string]:
|
131
|
+
const STRING_FORMAT_RULES: { [key: string]: SchemaGrammarConverterBuiltinRule } = {
|
130
132
|
date: new BuiltinRule(
|
131
133
|
'[0-9] [0-9] [0-9] [0-9] "-" ( "0" [1-9] | "1" [0-2] ) "-" ( "0" [1-9] | [1-2] [0-9] | "3" [0-1] )',
|
132
134
|
[],
|
@@ -173,7 +175,7 @@ const formatLiteral = (literal: string): string => {
|
|
173
175
|
const generateConstantRule = (value: any): string =>
|
174
176
|
formatLiteral(JSON.stringify(value))
|
175
177
|
|
176
|
-
interface
|
178
|
+
export interface SchemaGrammarConverterPropOrder {
|
177
179
|
[key: string]: number
|
178
180
|
}
|
179
181
|
|
@@ -196,7 +198,7 @@ function* groupBy(iterable: Iterable<any>, keyFn: (x: any) => any) {
|
|
196
198
|
}
|
197
199
|
|
198
200
|
export class SchemaGrammarConverter {
|
199
|
-
private _propOrder:
|
201
|
+
private _propOrder: SchemaGrammarConverterPropOrder
|
200
202
|
|
201
203
|
private _allowFetch: boolean
|
202
204
|
|
@@ -209,7 +211,7 @@ export class SchemaGrammarConverter {
|
|
209
211
|
private _refsBeingResolved: Set<string>
|
210
212
|
|
211
213
|
constructor(options: {
|
212
|
-
prop_order?:
|
214
|
+
prop_order?: SchemaGrammarConverterPropOrder
|
213
215
|
allow_fetch?: boolean
|
214
216
|
dotall?: boolean
|
215
217
|
}) {
|
@@ -690,7 +692,7 @@ export class SchemaGrammarConverter {
|
|
690
692
|
}
|
691
693
|
}
|
692
694
|
|
693
|
-
_addPrimitive(name: string, rule:
|
695
|
+
_addPrimitive(name: string, rule: SchemaGrammarConverterBuiltinRule | undefined) {
|
694
696
|
if (!rule) {
|
695
697
|
throw new Error(`Rule ${name} not known`)
|
696
698
|
}
|
@@ -828,7 +830,7 @@ export const convertJsonSchemaToGrammar = ({
|
|
828
830
|
allowFetch,
|
829
831
|
}: {
|
830
832
|
schema: any
|
831
|
-
propOrder?:
|
833
|
+
propOrder?: SchemaGrammarConverterPropOrder
|
832
834
|
dotall?: boolean
|
833
835
|
allowFetch?: boolean
|
834
836
|
}): string | Promise<string> => {
|
package/src/index.ts
CHANGED
@@ -12,11 +12,32 @@ import type {
|
|
12
12
|
NativeSessionLoadResult,
|
13
13
|
NativeCPUFeatures,
|
14
14
|
NativeEmbeddingParams,
|
15
|
+
NativeCompletionTokenProbItem,
|
16
|
+
NativeCompletionResultTimings,
|
15
17
|
} from './NativeRNLlama'
|
18
|
+
import type { SchemaGrammarConverterPropOrder, SchemaGrammarConverterBuiltinRule } from './grammar'
|
16
19
|
import { SchemaGrammarConverter, convertJsonSchemaToGrammar } from './grammar'
|
17
|
-
import type { RNLlamaOAICompatibleMessage } from './chat'
|
20
|
+
import type { RNLlamaMessagePart, RNLlamaOAICompatibleMessage } from './chat'
|
18
21
|
import { formatChat } from './chat'
|
19
22
|
|
23
|
+
export type {
|
24
|
+
NativeContextParams,
|
25
|
+
NativeLlamaContext,
|
26
|
+
NativeCompletionParams,
|
27
|
+
NativeCompletionTokenProb,
|
28
|
+
NativeCompletionResult,
|
29
|
+
NativeTokenizeResult,
|
30
|
+
NativeEmbeddingResult,
|
31
|
+
NativeSessionLoadResult,
|
32
|
+
NativeEmbeddingParams,
|
33
|
+
NativeCompletionTokenProbItem,
|
34
|
+
NativeCompletionResultTimings,
|
35
|
+
RNLlamaMessagePart,
|
36
|
+
RNLlamaOAICompatibleMessage,
|
37
|
+
SchemaGrammarConverterPropOrder,
|
38
|
+
SchemaGrammarConverterBuiltinRule,
|
39
|
+
}
|
40
|
+
|
20
41
|
export { SchemaGrammarConverter, convertJsonSchemaToGrammar }
|
21
42
|
|
22
43
|
const EVENT_ON_INIT_CONTEXT_PROGRESS = '@RNLlama_onInitContextProgress'
|
@@ -41,12 +62,56 @@ type TokenNativeEvent = {
|
|
41
62
|
tokenResult: TokenData
|
42
63
|
}
|
43
64
|
|
65
|
+
export enum GGML_TYPE {
|
66
|
+
LM_GGML_TYPE_F32 = 0,
|
67
|
+
LM_GGML_TYPE_F16 = 1,
|
68
|
+
LM_GGML_TYPE_Q4_0 = 2,
|
69
|
+
LM_GGML_TYPE_Q4_1 = 3,
|
70
|
+
// LM_GGML_TYPE_Q4_2 = 4, support has been removed
|
71
|
+
// LM_GGML_TYPE_Q4_3 = 5, support has been removed
|
72
|
+
LM_GGML_TYPE_Q5_0 = 6,
|
73
|
+
LM_GGML_TYPE_Q5_1 = 7,
|
74
|
+
LM_GGML_TYPE_Q8_0 = 8,
|
75
|
+
LM_GGML_TYPE_Q8_1 = 9,
|
76
|
+
LM_GGML_TYPE_Q2_K = 10,
|
77
|
+
LM_GGML_TYPE_Q3_K = 11,
|
78
|
+
LM_GGML_TYPE_Q4_K = 12,
|
79
|
+
LM_GGML_TYPE_Q5_K = 13,
|
80
|
+
LM_GGML_TYPE_Q6_K = 14,
|
81
|
+
LM_GGML_TYPE_Q8_K = 15,
|
82
|
+
LM_GGML_TYPE_IQ2_XXS = 16,
|
83
|
+
LM_GGML_TYPE_IQ2_XS = 17,
|
84
|
+
LM_GGML_TYPE_IQ3_XXS = 18,
|
85
|
+
LM_GGML_TYPE_IQ1_S = 19,
|
86
|
+
LM_GGML_TYPE_IQ4_NL = 20,
|
87
|
+
LM_GGML_TYPE_IQ3_S = 21,
|
88
|
+
LM_GGML_TYPE_IQ2_S = 22,
|
89
|
+
LM_GGML_TYPE_IQ4_XS = 23,
|
90
|
+
LM_GGML_TYPE_I8 = 24,
|
91
|
+
LM_GGML_TYPE_I16 = 25,
|
92
|
+
LM_GGML_TYPE_I32 = 26,
|
93
|
+
LM_GGML_TYPE_I64 = 27,
|
94
|
+
LM_GGML_TYPE_F64 = 28,
|
95
|
+
LM_GGML_TYPE_IQ1_M = 29,
|
96
|
+
LM_GGML_TYPE_BF16 = 30,
|
97
|
+
// LM_GGML_TYPE_Q4_0_4_4 = 31, support has been removed from gguf files
|
98
|
+
// LM_GGML_TYPE_Q4_0_4_8 = 32,
|
99
|
+
// LM_GGML_TYPE_Q4_0_8_8 = 33,
|
100
|
+
LM_GGML_TYPE_TQ1_0 = 34,
|
101
|
+
LM_GGML_TYPE_TQ2_0 = 35,
|
102
|
+
// LM_GGML_TYPE_IQ4_NL_4_4 = 36,
|
103
|
+
// LM_GGML_TYPE_IQ4_NL_4_8 = 37,
|
104
|
+
// LM_GGML_TYPE_IQ4_NL_8_8 = 38,
|
105
|
+
LM_GGML_TYPE_COUNT = 39,
|
106
|
+
};
|
107
|
+
|
108
|
+
|
44
109
|
export type ContextParams = Omit<
|
45
110
|
NativeContextParams,
|
46
111
|
'cache_type_k' | 'cache_type_v' | 'pooling_type'
|
47
112
|
> & {
|
48
|
-
cache_type_k?:
|
49
|
-
cache_type_v?:
|
113
|
+
cache_type_k?: GGML_TYPE
|
114
|
+
cache_type_v?: GGML_TYPE
|
50
115
|
pooling_type?: 'none' | 'mean' | 'cls' | 'last' | 'rank'
|
51
116
|
}
|
52
117
|
|