@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.
Files changed (86) hide show
  1. package/.gitmodules +3 -0
  2. package/.prettierignore +38 -0
  3. package/AGENTS.md +1 -0
  4. package/CMakeLists.txt +131 -0
  5. package/LICENCE +21 -0
  6. package/README-dev.md +178 -0
  7. package/README.md +225 -0
  8. package/README_banner.png +0 -0
  9. package/assets/screenshot_0.png +0 -0
  10. package/cpp/generate_glue_prototype.js +115 -0
  11. package/cpp/glue.hpp +664 -0
  12. package/cpp/test_glue.cpp +80 -0
  13. package/cpp/wllama-context.h +1172 -0
  14. package/cpp/wllama-fs.h +148 -0
  15. package/cpp/wllama.cpp +187 -0
  16. package/cpp/wllama.h +6 -0
  17. package/esm/cache-manager.d.ts +130 -0
  18. package/esm/debug.d.ts +28 -0
  19. package/esm/glue/glue.d.ts +22 -0
  20. package/esm/glue/messages.d.ts +146 -0
  21. package/esm/huggingface.d.ts +31 -0
  22. package/esm/index.cjs +3406 -0
  23. package/esm/index.d.ts +8 -0
  24. package/esm/index.js +3387 -0
  25. package/esm/index.min.js +1 -0
  26. package/esm/index.min.js.map +1 -0
  27. package/esm/model-manager.d.ts +136 -0
  28. package/esm/storage/cos.d.ts +36 -0
  29. package/esm/storage/index.d.ts +33 -0
  30. package/esm/storage/opfs.d.ts +12 -0
  31. package/esm/types/oai-compat.d.ts +278 -0
  32. package/esm/types/types.d.ts +112 -0
  33. package/esm/utils.d.ts +119 -0
  34. package/esm/wasm/source-map.d.ts +1 -0
  35. package/esm/wasm/wllama.wasm +0 -0
  36. package/esm/wasm-from-cdn.d.ts +8 -0
  37. package/esm/wllama.d.ts +397 -0
  38. package/esm/worker.d.ts +92 -0
  39. package/esm/workers-code/generated.d.ts +4 -0
  40. package/guides/intro-v2.md +132 -0
  41. package/guides/intro-v3.1.md +40 -0
  42. package/guides/intro-v3.md +230 -0
  43. package/index.ts +1 -0
  44. package/package.json +71 -0
  45. package/scripts/bisect_test.sh +33 -0
  46. package/scripts/build_hf_space.sh +26 -0
  47. package/scripts/build_source_map.js +269 -0
  48. package/scripts/build_wasm.sh +19 -0
  49. package/scripts/build_worker.sh +38 -0
  50. package/scripts/check_debug_build.js +30 -0
  51. package/scripts/check_package_size.js +25 -0
  52. package/scripts/docker-compose.yml +76 -0
  53. package/scripts/generate_wasm_from_cdn.js +24 -0
  54. package/scripts/http_server.js +44 -0
  55. package/scripts/post_build.sh +32 -0
  56. package/src/cache-manager.ts +358 -0
  57. package/src/debug.ts +111 -0
  58. package/src/glue/glue.ts +291 -0
  59. package/src/glue/messages.ts +773 -0
  60. package/src/huggingface.ts +151 -0
  61. package/src/index.ts +8 -0
  62. package/src/mjs.test.ts +44 -0
  63. package/src/model-manager.test.ts +200 -0
  64. package/src/model-manager.ts +359 -0
  65. package/src/storage/cos.test.ts +83 -0
  66. package/src/storage/cos.ts +171 -0
  67. package/src/storage/index.ts +40 -0
  68. package/src/storage/opfs.ts +119 -0
  69. package/src/types/oai-compat.ts +342 -0
  70. package/src/types/types.ts +133 -0
  71. package/src/utils.test.ts +231 -0
  72. package/src/utils.ts +403 -0
  73. package/src/wasm/source-map.ts +7 -0
  74. package/src/wasm/wllama.js +1 -0
  75. package/src/wasm/wllama.wasm +0 -0
  76. package/src/wasm-from-cdn.ts +13 -0
  77. package/src/wllama.test.ts +392 -0
  78. package/src/wllama.ts +1138 -0
  79. package/src/wllama.wgpu.test.ts +62 -0
  80. package/src/worker.ts +443 -0
  81. package/src/workers-code/generated.ts +11 -0
  82. package/src/workers-code/llama-cpp.js +511 -0
  83. package/src/workers-code/opfs-utils.js +150 -0
  84. package/tsconfig.build.json +34 -0
  85. package/tsup.config.ts +23 -0
  86. package/vitest.config.ts +61 -0
package/tsup.config.ts ADDED
@@ -0,0 +1,23 @@
1
+ import type { Options } from 'tsup';
2
+
3
+ const baseConfig: Options = {
4
+ entry: ['./index.ts'],
5
+ format: ['cjs', 'esm'],
6
+ outDir: 'esm',
7
+ clean: true,
8
+ };
9
+
10
+ // const nodeConfig: Options = {
11
+ // ...baseConfig,
12
+ // platform: "node",
13
+ // };
14
+
15
+ const browserConfig: Options = {
16
+ ...baseConfig,
17
+ platform: 'browser',
18
+ target: 'es2015',
19
+ splitting: false,
20
+ outDir: 'esm',
21
+ };
22
+
23
+ export default [browserConfig];
@@ -0,0 +1,61 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ const SAFARI = process.env.BROWSER === 'safari';
4
+ const WEBGPU = process.env.WEBGPU === '1';
5
+ const AUTO = process.env.AUTO === '1';
6
+
7
+ const chromeArgsCI = ['disable-gpu', 'no-sandbox', 'disable-setuid-sandbox'];
8
+ const chromeArgsWebGPU = [
9
+ 'no-sandbox',
10
+ 'disable-setuid-sandbox',
11
+ 'enable-unsafe-webgpu',
12
+ 'enable-features=WebGPU',
13
+ ];
14
+
15
+ export default defineConfig({
16
+ define: {
17
+ __GITHUB_CI__: JSON.stringify(!!process.env.GITHUB_ACTIONS),
18
+ },
19
+ test: {
20
+ ...(AUTO ? { watch: false } : {}),
21
+ exclude: [
22
+ '**/node_modules/**',
23
+ '**/esm/**',
24
+ '**/docs/**',
25
+ '**/examples/**',
26
+ ...(!WEBGPU ? ['**/src/*.wgpu.test.*'] : []),
27
+ ],
28
+ include: WEBGPU ? ['**/src/*.wgpu.test.*'] : ['**/src/**/*.test.*'],
29
+ browser: {
30
+ enabled: true,
31
+ name: process.env.BROWSER ?? 'chromium',
32
+ provider: SAFARI ? 'webdriverio' : 'playwright',
33
+ // https://playwright.dev
34
+ providerOptions: WEBGPU
35
+ ? { launch: { args: chromeArgsWebGPU.map((a) => `--${a}`) } }
36
+ : process.env.GITHUB_ACTIONS
37
+ ? {
38
+ capabilities: {
39
+ 'goog:chromeOptions': {
40
+ args: chromeArgsCI,
41
+ },
42
+ },
43
+ }
44
+ : SAFARI
45
+ ? {
46
+ capabilities: {
47
+ alwaysMatch: { browserName: 'safari' },
48
+ firstMatch: [{}],
49
+ browserName: 'safari',
50
+ },
51
+ }
52
+ : {},
53
+ },
54
+ },
55
+ server: {
56
+ headers: {
57
+ 'Cross-Origin-Embedder-Policy': 'require-corp',
58
+ 'Cross-Origin-Opener-Policy': 'same-origin',
59
+ },
60
+ },
61
+ });