@agorapete/wllama 3.5.1-q2.0
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/.gitmodules +3 -0
- package/.prettierignore +38 -0
- package/AGENTS.md +1 -0
- package/CMakeLists.txt +131 -0
- package/LICENCE +21 -0
- package/README-dev.md +178 -0
- package/README.md +225 -0
- package/README_banner.png +0 -0
- package/assets/screenshot_0.png +0 -0
- package/cpp/generate_glue_prototype.js +115 -0
- package/cpp/glue.hpp +664 -0
- package/cpp/test_glue.cpp +80 -0
- package/cpp/wllama-context.h +1172 -0
- package/cpp/wllama-fs.h +148 -0
- package/cpp/wllama.cpp +187 -0
- package/cpp/wllama.h +6 -0
- package/esm/cache-manager.d.ts +130 -0
- package/esm/debug.d.ts +28 -0
- package/esm/glue/glue.d.ts +22 -0
- package/esm/glue/messages.d.ts +146 -0
- package/esm/huggingface.d.ts +31 -0
- package/esm/index.cjs +3406 -0
- package/esm/index.d.ts +8 -0
- package/esm/index.js +3387 -0
- package/esm/index.min.js +1 -0
- package/esm/index.min.js.map +1 -0
- package/esm/model-manager.d.ts +136 -0
- package/esm/storage/cos.d.ts +36 -0
- package/esm/storage/index.d.ts +33 -0
- package/esm/storage/opfs.d.ts +12 -0
- package/esm/types/oai-compat.d.ts +278 -0
- package/esm/types/types.d.ts +112 -0
- package/esm/utils.d.ts +119 -0
- package/esm/wasm/source-map.d.ts +1 -0
- package/esm/wasm/wllama.wasm +0 -0
- package/esm/wasm-from-cdn.d.ts +8 -0
- package/esm/wllama.d.ts +397 -0
- package/esm/worker.d.ts +92 -0
- package/esm/workers-code/generated.d.ts +4 -0
- package/guides/intro-v2.md +132 -0
- package/guides/intro-v3.1.md +40 -0
- package/guides/intro-v3.md +230 -0
- package/index.ts +1 -0
- package/package.json +71 -0
- package/scripts/bisect_test.sh +33 -0
- package/scripts/build_hf_space.sh +26 -0
- package/scripts/build_source_map.js +269 -0
- package/scripts/build_wasm.sh +19 -0
- package/scripts/build_worker.sh +38 -0
- package/scripts/check_debug_build.js +30 -0
- package/scripts/check_package_size.js +25 -0
- package/scripts/docker-compose.yml +76 -0
- package/scripts/generate_wasm_from_cdn.js +24 -0
- package/scripts/http_server.js +44 -0
- package/scripts/post_build.sh +32 -0
- package/src/cache-manager.ts +358 -0
- package/src/debug.ts +111 -0
- package/src/glue/glue.ts +291 -0
- package/src/glue/messages.ts +773 -0
- package/src/huggingface.ts +151 -0
- package/src/index.ts +8 -0
- package/src/mjs.test.ts +44 -0
- package/src/model-manager.test.ts +200 -0
- package/src/model-manager.ts +359 -0
- package/src/storage/cos.test.ts +83 -0
- package/src/storage/cos.ts +171 -0
- package/src/storage/index.ts +40 -0
- package/src/storage/opfs.ts +119 -0
- package/src/types/oai-compat.ts +342 -0
- package/src/types/types.ts +133 -0
- package/src/utils.test.ts +231 -0
- package/src/utils.ts +403 -0
- package/src/wasm/source-map.ts +7 -0
- package/src/wasm/wllama.js +1 -0
- package/src/wasm/wllama.wasm +0 -0
- package/src/wasm-from-cdn.ts +13 -0
- package/src/wllama.test.ts +392 -0
- package/src/wllama.ts +1138 -0
- package/src/wllama.wgpu.test.ts +62 -0
- package/src/worker.ts +443 -0
- package/src/workers-code/generated.ts +11 -0
- package/src/workers-code/llama-cpp.js +511 -0
- package/src/workers-code/opfs-utils.js +150 -0
- package/tsconfig.build.json +34 -0
- package/tsup.config.ts +23 -0
- package/vitest.config.ts +61 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
|
|
4
|
+
const inputPath = './cpp/glue.hpp';
|
|
5
|
+
const outputPath = './src/glue/messages.ts';
|
|
6
|
+
|
|
7
|
+
const snakeToCamel = (str) =>
|
|
8
|
+
str.replace(/([-_]\w)/g, (g) => g[1].toUpperCase());
|
|
9
|
+
const snakeToPascal = (str) => {
|
|
10
|
+
let camelCase = snakeToCamel(str);
|
|
11
|
+
let pascalCase = camelCase[0].toUpperCase() + camelCase.substr(1);
|
|
12
|
+
return pascalCase;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const cppContent = fs.readFileSync(inputPath, 'utf8');
|
|
16
|
+
const lines = cppContent.split('\n');
|
|
17
|
+
const protos = [];
|
|
18
|
+
|
|
19
|
+
let insideStruct = false;
|
|
20
|
+
let currentProto = { name: '', className: '', structName: '', fields: [] };
|
|
21
|
+
let version = 0;
|
|
22
|
+
for (const line of lines) {
|
|
23
|
+
if (line.startsWith('#define GLUE_VERSION')) {
|
|
24
|
+
version = parseInt(line.split(' ').at(-1));
|
|
25
|
+
}
|
|
26
|
+
if (line.startsWith('struct glue_msg_')) {
|
|
27
|
+
insideStruct = true;
|
|
28
|
+
const structName = line.split(' ')[1];
|
|
29
|
+
currentProto = {
|
|
30
|
+
name: '',
|
|
31
|
+
structName,
|
|
32
|
+
className: snakeToPascal(structName),
|
|
33
|
+
fields: [],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const lineTrimed = line.trim();
|
|
37
|
+
if (insideStruct) {
|
|
38
|
+
if (lineTrimed.startsWith('GLUE_HANDLER')) {
|
|
39
|
+
const name = lineTrimed.split('(')[1].split(')')[0];
|
|
40
|
+
currentProto.name = JSON.parse(name);
|
|
41
|
+
if (currentProto.name.length !== 8) {
|
|
42
|
+
console.error(
|
|
43
|
+
'Invalid name (must be 8 characters):',
|
|
44
|
+
currentProto.name
|
|
45
|
+
);
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (lineTrimed.startsWith('GLUE_FIELD')) {
|
|
50
|
+
const isNullable = lineTrimed.startsWith('GLUE_FIELD_NULLABLE');
|
|
51
|
+
const fieldParts = lineTrimed.split('(')[1].split(')')[0].split(',');
|
|
52
|
+
currentProto.fields.push({
|
|
53
|
+
type: fieldParts[0].trim(),
|
|
54
|
+
name: fieldParts[1].trim(),
|
|
55
|
+
isNullable,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
if (line.startsWith('};')) {
|
|
59
|
+
insideStruct = false;
|
|
60
|
+
protos.push(currentProto);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//console.log(JSON.stringify(protos, null, 2));
|
|
66
|
+
|
|
67
|
+
const typeMapping = {
|
|
68
|
+
bool: 'boolean',
|
|
69
|
+
int: 'number',
|
|
70
|
+
float: 'number',
|
|
71
|
+
str: 'string',
|
|
72
|
+
raw: 'Uint8Array',
|
|
73
|
+
arr_bool: 'bool[]',
|
|
74
|
+
arr_int: 'number[]',
|
|
75
|
+
arr_float: 'number[]',
|
|
76
|
+
arr_str: 'string[]',
|
|
77
|
+
arr_raw: 'Uint8Array[]',
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const protoMap = {};
|
|
81
|
+
for (const proto of protos) {
|
|
82
|
+
protoMap[proto.name] = proto;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const outputContent = `// This file is generated by cpp/generate_glue_prototype.js
|
|
86
|
+
// Do not edit this file directly
|
|
87
|
+
|
|
88
|
+
import type { GlueMessageProto } from './glue';
|
|
89
|
+
|
|
90
|
+
export const GLUE_VERSION = ${version};
|
|
91
|
+
|
|
92
|
+
export const GLUE_MESSAGE_PROTOTYPES: { [name: string]: GlueMessageProto } = ${JSON.stringify(protoMap, null, 2)};
|
|
93
|
+
|
|
94
|
+
${protos
|
|
95
|
+
.map((proto) => {
|
|
96
|
+
let interfaceCode = `// struct ${proto.structName}\n`;
|
|
97
|
+
interfaceCode += `export interface ${proto.className} {\n`;
|
|
98
|
+
interfaceCode += ` _name: "${proto.name}";\n`;
|
|
99
|
+
for (const field of proto.fields) {
|
|
100
|
+
const mappedType = typeMapping[field.type];
|
|
101
|
+
if (!mappedType) {
|
|
102
|
+
console.error('Unknown type:', field.type);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
interfaceCode += ` ${field.name}${field.isNullable ? '?' : ''}: ${mappedType}${field.isNullable ? ' | undefined' : ''};\n`;
|
|
106
|
+
}
|
|
107
|
+
interfaceCode += '}\n';
|
|
108
|
+
return interfaceCode;
|
|
109
|
+
})
|
|
110
|
+
.join('\n')}
|
|
111
|
+
|
|
112
|
+
export type GlueMsg = ${protos.map((proto) => proto.className).join(' | ')};
|
|
113
|
+
`;
|
|
114
|
+
|
|
115
|
+
fs.writeFileSync(outputPath, outputContent);
|