cui-llama.rn 1.0.1 → 1.0.2
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/README.md
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
# cui-llama.rn
|
2
2
|
|
3
|
-
This is a fork of llama.rn meant for ChatterUI
|
3
|
+
This is a fork of [llama.rn](https://github.com/mybigday/llama.rn) meant for [ChatterUI](https://github.com/Vali-98/ChatterUI)
|
4
|
+
|
5
|
+
This fork exists to update llama.cpp on a more frequent basis, plus adding useful features to ChatterUI.
|
6
|
+
|
7
|
+
The following features have been added for Android:
|
8
|
+
|
9
|
+
- Updated sync for llama.cpp
|
10
|
+
- Added stopping prompt processing between batches, vital for mobile devices with very slow prompt processing
|
11
|
+
- `vocab_only` mode: utilize the llama.cpp tokenizer
|
12
|
+
- tokenizeSync: non-blocking, synchronous tokenizer function
|
4
13
|
|
5
14
|
Original repo README.md below.
|
6
15
|
|
@@ -17,6 +17,7 @@ import java.io.BufferedReader;
|
|
17
17
|
import java.io.FileReader;
|
18
18
|
import java.io.File;
|
19
19
|
import java.io.IOException;
|
20
|
+
import java.io.FileInputStream;
|
20
21
|
|
21
22
|
public class LlamaContext {
|
22
23
|
public static final String NAME = "RNLlamaContext";
|
@@ -28,6 +29,35 @@ public class LlamaContext {
|
|
28
29
|
private int jobId = -1;
|
29
30
|
private DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;
|
30
31
|
|
32
|
+
private byte[] ggufHeader = {0x47, 0x47, 0x55, 0x46};
|
33
|
+
|
34
|
+
private boolean isGGUF(final String filepath) {
|
35
|
+
byte[] fileHeader = new byte[4];
|
36
|
+
FileInputStream fis = null;
|
37
|
+
try {
|
38
|
+
fis = new FileInputStream(filepath);
|
39
|
+
int bytesRead = fis.read(fileHeader);
|
40
|
+
if(bytesRead < 4) {
|
41
|
+
return false;
|
42
|
+
}
|
43
|
+
for(int i = 0; i < 4; i++){
|
44
|
+
if(fileHeader[i] != ggufHeader[i])
|
45
|
+
return false;
|
46
|
+
}
|
47
|
+
return true;
|
48
|
+
} catch (Exception e) {
|
49
|
+
return false;
|
50
|
+
}finally {
|
51
|
+
if (fis != null) {
|
52
|
+
try {
|
53
|
+
fis.close();
|
54
|
+
} catch (Exception e) {
|
55
|
+
Log.d(NAME, "Closing FileInputStream failed.");
|
56
|
+
}
|
57
|
+
}
|
58
|
+
}
|
59
|
+
}
|
60
|
+
|
31
61
|
public LlamaContext(int id, ReactApplicationContext reactContext, ReadableMap params) {
|
32
62
|
if (LlamaContext.isArm64V8a() == false && LlamaContext.isX86_64() == false) {
|
33
63
|
throw new IllegalStateException("Only 64-bit architectures are supported");
|
@@ -35,6 +65,11 @@ public class LlamaContext {
|
|
35
65
|
if (!params.hasKey("model")) {
|
36
66
|
throw new IllegalArgumentException("Missing required parameter: model");
|
37
67
|
}
|
68
|
+
// Check if file has GGUF magic numbers
|
69
|
+
if(!isGGUF(params.getString("model"))) {
|
70
|
+
throw new IllegalArgumentException("File is not in GGUF format");
|
71
|
+
}
|
72
|
+
|
38
73
|
this.id = id;
|
39
74
|
this.context = initContext(
|
40
75
|
// String model,
|