Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1 web (redux) #60

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions binding/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
node_modules
dist
src/lib/*
src/!lib/.gitkeep
lib/*
!lib/.gitkeep
test/*.bin
.idea/
test_data.json
Expand Down
15 changes: 1 addition & 14 deletions binding/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,13 @@ models. picoLLM Inference Engine is:
- Runs on CPU and GPU
- Free for open-weight models

## Requirements

PicoLLM Web Binding uses [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer) to generate
text. Modern browsers require the following response headers to allow the usage of `SharedArrayBuffers`:

```
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
```

Refer to our [Web demos](https://github.com/Picovoice/picollm/tree/master/demo/web) for example on creating a server
with the corresponding response headers.

## Compatibility

- Chrome / Edge
- Firefox
- Safari

**NOTE**: IndexedDB, SIMD and SharedArrayBuffers are required to use `picoLLM`.
**NOTE**: IndexedDB and SIMD are required to use `picoLLM`.

## Installation

Expand Down
9 changes: 0 additions & 9 deletions binding/web/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,5 @@ export default defineConfig({
specPattern: 'test/*.test.{js,jsx,ts,tsx}',
video: false,
screenshotOnRunFailure: false,
setupNodeEvents(on, config) {
on('before:browser:launch', (browser, launchOptions) => {
if (browser.name === 'chrome') {
launchOptions.args.push('--enable-features=SharedArrayBuffer');
}

return launchOptions;
});
},
},
});
5 changes: 0 additions & 5 deletions binding/web/module.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ declare module "*.wasm" {
export default content;
}

declare module "*.txt" {
const content: string;
export default content;
}

declare module 'web-worker:*' {
const WorkerFactory: new () => Worker;
export default WorkerFactory;
Expand Down
9 changes: 5 additions & 4 deletions binding/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@
"lint": "eslint . --ext .js,.ts",
"prepack": "npm-run-all build",
"start": "cross-env TARGET='debug' rollup --config --watch",
"serve": "node server.js",
"watch": "rollup --config --watch",
"format": "prettier --write \"**/*.{js,ts,json}\"",
"copywasm": "node scripts/copy_wasm.js",
"setup-test": "node scripts/setup_test.js",
"test": "cypress run --spec test/picollm.test.ts --browser chrome --headed"
},
"dependencies": {
"@picovoice/web-utils": "~1.4.1"
"@picovoice/web-utils": "~1.4.3"
},
"devDependencies": {
"@babel/core": "^7.21.3",
Expand All @@ -42,18 +41,20 @@
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-terser": "^0.4.0",
"@rollup/pluginutils": "^5.0.2",
"@types/emscripten": "^1.39.13",
"@types/node": "^18.11.9",
"@types/pv-xpu-web-worker": "../../lib/wasm/dist/types/xpu_web_worker",
"@types/pv-xpu-webgpu": "../../lib/wasm/dist/types/xpu_webgpu",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"async-mutex": "^0.4.0",
"cross-env": "^7.0.3",
"cypress": "^12.8.1",
"eslint": "^8.22.0",
"eslint-plugin-cypress": "^2.12.1",
"mime-types": "^2.1.35",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.3",
"pv-xpu-web-worker": "../../lib/wasm/dist/xpu_web_worker/esm",
"pv-xpu-webgpu": "../../lib/wasm/dist/xpu_webgpu/esm",
"rollup": "^2.79.1",
"rollup-plugin-typescript2": "^0.34.1",
"rollup-plugin-web-worker-loader": "^1.6.1",
Expand Down
2 changes: 1 addition & 1 deletion binding/web/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default {
exclude: '**/node_modules/**',
}),
base64({
include: ['./**/*.wasm', './**/*.txt'],
include: ['./lib/**/*.wasm'],
})
],
};
12 changes: 4 additions & 8 deletions binding/web/scripts/copy_wasm.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const fs = require("fs");
const { join, extname } = require("path");
const { join } = require("path");

const wasmFiles = [
"pv_picollm.wasm",
"pv_picollm_simd.wasm",
"pv_picollm.js",
"pv_picollm_simd.js",
"pv_picollm_web_worker_helper.wasm",
"pv_picollm_web_worker_helper_simd.wasm",
]

console.log("Copying the WASM model...");
Expand All @@ -19,16 +19,12 @@ const sourceDirectory = join(
"wasm"
);

const outputDirectory = join(__dirname, "..", "src", "lib");
const outputDirectory = join(__dirname, "..", "lib");

try {
fs.mkdirSync(outputDirectory, { recursive: true });
wasmFiles.forEach(file => {
fs.copyFileSync(join(sourceDirectory, file), join(outputDirectory, file))
const ext = extname(file);
if (ext === ".js") {
fs.copyFileSync(join(sourceDirectory, file), join(outputDirectory, file.replace(ext, ".txt")));
}
})
} catch (error) {
console.error(error);
Expand Down
5 changes: 1 addition & 4 deletions binding/web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,12 @@ import {
PicoLLMWorkerResponse,
} from './types';

import picoLLMWasmSimd from './lib/pv_picollm_simd.wasm';
import picoLLMWasmLib from './lib/pv_picollm_simd.txt';
import picoLLMWasmSimd from '../lib/pv_picollm_simd.wasm';

import * as PicoLLMErrors from './picollm_errors';

PicoLLM.setWasmSimd(picoLLMWasmSimd);
PicoLLMWorker.setWasmSimd(picoLLMWasmSimd);
PicoLLM.setWasmLib(picoLLMWasmLib);
PicoLLMWorker.setWasmLib(picoLLMWasmLib);

export {
Dialog,
Expand Down
Empty file removed binding/web/src/lib/.gitkeep
Empty file.
Loading
Loading