openvino-tokenizers-node 2024.6.0-preview

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 ADDED
@@ -0,0 +1,30 @@
1
+ # OpenVINO Tokenizers
2
+
3
+ This package contains binaries extension for
4
+ [openvino-node](https://www.npmjs.com/package/openvino-node) package
5
+
6
+ ## Installation
7
+
8
+ ```bash
9
+ npm install openvino-tokenizers-node
10
+ ```
11
+ After package installation script that downloads and extracts binaries will be executed. Binaries will be placed in the `node_modules/openvino-tokenizers-node/bin` directory.
12
+
13
+ This package is a part of [openvino-node](https://www.npmjs.com/package/openvino-node) package and should be used with it. Version of this package should be the same as version of openvino-node package.
14
+
15
+ ## Usage
16
+
17
+ ```javascript
18
+ const { addon: ov } = require('openvino-node');
19
+ const openvinoTokenizers = require('openvino-tokenizers-node');
20
+
21
+ const core = new ov.Core();
22
+ core.addExtension(openvinoTokenizers.path); // Add tokenizers extension
23
+
24
+ // Load tokenizers model
25
+ // ...
26
+ ```
27
+
28
+ [License](https://github.com/openvinotoolkit/openvino/blob/master/LICENSE)
29
+
30
+ Copyright © 2018-2024 Intel Corporation
@@ -0,0 +1,60 @@
1
+ const os = require('node:os');
2
+ const path = require('node:path');
3
+
4
+ module.exports = {
5
+ path: getPathToBinary({
6
+ platform: os.platform(),
7
+ arch: os.arch(),
8
+ }),
9
+ getPathToBinary,
10
+ };
11
+
12
+ function getPathToBinary(osProps) {
13
+ const { arch, platform } = osProps;
14
+
15
+ if (platform === 'win32' && arch !== 'x64')
16
+ throw new Error(`Version for windows and '${arch}' is not supported.`);
17
+
18
+ return path.join(
19
+ __dirname,
20
+ 'bin/runtime',
21
+ libOrBin(platform),
22
+ getDirnameByArch(arch),
23
+ platform === 'linux' ? '' : 'Release',
24
+ getBinaryFilename(platform),
25
+ );
26
+ }
27
+
28
+ function getDirnameByArch(arch) {
29
+ switch (arch) {
30
+ case 'x64':
31
+ return 'intel64';
32
+ case 'arm64':
33
+ case 'armhf':
34
+ return 'arm64';
35
+ default:
36
+ throw new Error(`Unsupported architecture: ${arch}`);
37
+ }
38
+ }
39
+
40
+ function libOrBin(platform) {
41
+ switch (platform) {
42
+ case 'win32':
43
+ return 'bin';
44
+ default:
45
+ return 'lib';
46
+ }
47
+ }
48
+
49
+ function getBinaryFilename(platform) {
50
+ switch (platform) {
51
+ case 'win32':
52
+ return 'openvino_tokenizers.dll';
53
+ case 'linux':
54
+ return 'libopenvino_tokenizers.so';
55
+ case 'darwin':
56
+ return 'libopenvino_tokenizers.dylib';
57
+ default:
58
+ throw new Error(`Unsupported platform: ${platform}`);
59
+ }
60
+ }
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "openvino-tokenizers-node",
3
+ "version": "2024.6.0-preview",
4
+ "description": "OpenVINO™ Tokenizers adds text processing operations to openvino-node package",
5
+ "repository": {
6
+ "url": "https://github.com/openvinotoolkit/openvino.git",
7
+ "type": "git"
8
+ },
9
+ "license": "Apache-2.0",
10
+ "main": "openvino-tokenizers.js",
11
+ "os": [
12
+ "win32",
13
+ "darwin",
14
+ "linux"
15
+ ],
16
+ "scripts": {
17
+ "postinstall": "npm run install_runtime",
18
+ "download_runtime": "node ./scripts/download-runtime.js",
19
+ "install_runtime": "npm run download_runtime -- --ignore-if-exists",
20
+ "test": "node --test ./tests/*.test.js"
21
+ },
22
+ "binary": {
23
+ "version": "2024.6.0.0",
24
+ "module_path": "./bin/",
25
+ "remote_path": "./repositories/openvino_tokenizers/packages/{version}/",
26
+ "package_name": "openvino_tokenizers_{platform}_{version}_{arch}.{extension}",
27
+ "host": "https://storage.openvinotoolkit.org"
28
+ },
29
+ "keywords": [
30
+ "OpenVINO",
31
+ "openvino",
32
+ "tokenizers",
33
+ "OpenVINO tokenizers",
34
+ "openvino tokenizers",
35
+ "openvino-tokenizers",
36
+ "openvino-tokenizers-node",
37
+ "tokenization",
38
+ "text processing",
39
+ "string tensors",
40
+ "text tensors"
41
+ ],
42
+ "dependencies": {
43
+ "adm-zip": "^0.5.16",
44
+ "openvino-node": "2024.6.0"
45
+ }
46
+ }
@@ -0,0 +1,91 @@
1
+
2
+ const os = require('node:os');
3
+ const AdmZip = require('adm-zip');
4
+ const { join } = require('node:path');
5
+ const BinaryManager = require('openvino-node/scripts/lib/binary-manager');
6
+
7
+ const packageJson = require('../package.json');
8
+
9
+ class TokenizersBinaryManager extends BinaryManager {
10
+ getVersion() {
11
+ return `${ this.binaryConfig.version || this.version }.0`;
12
+ }
13
+
14
+ getPlatformLabel() {
15
+ return this.convertPlatformLabel(os.platform());
16
+ }
17
+
18
+ getArchLabel() {
19
+ return this.convertArchLabel(os.arch());
20
+ }
21
+
22
+ getExtension() {
23
+ return os.platform() === 'win32' ? 'zip' : 'tar.gz';
24
+ }
25
+
26
+ convertPlatformLabel(platform) {
27
+ switch(platform) {
28
+ case 'win32':
29
+ return 'windows';
30
+ case 'linux':
31
+ return 'centos7';
32
+ case 'darwin':
33
+ return 'macos_12_6';
34
+ }
35
+ }
36
+
37
+ convertArchLabel(arch) {
38
+ switch(arch) {
39
+ case 'x64':
40
+ return 'x86_64';
41
+ case 'arm64':
42
+ case 'armhf':
43
+ return 'arm64';
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Unarchive tar, tar.gz or zip archives.
49
+ *
50
+ * @function unarchive
51
+ * @param {string} archivePath - Path to archive.
52
+ * @param {string} dest - Path where to unpack.
53
+ * @returns {Promise<void>}
54
+ */
55
+ static unarchive(archivePath, dest) {
56
+ if (archivePath.endsWith('.zip')) {
57
+ const zip = new AdmZip(archivePath);
58
+
59
+ return new Promise((resolve, reject) => {
60
+ zip.extractAllToAsync(dest, true, (err) => {
61
+ if (err) {
62
+ reject(err);
63
+ } else {
64
+ resolve();
65
+ }
66
+ });
67
+ });
68
+ }
69
+
70
+ return BinaryManager.unarchive(archivePath, dest);
71
+ }
72
+ }
73
+
74
+ if (require.main === module) main();
75
+
76
+ async function main() {
77
+ if (!TokenizersBinaryManager.isCompatible()) process.exit(1);
78
+
79
+ const force = process.argv.includes('-f');
80
+ const ignoreIfExists = process.argv.includes('--ignore-if-exists');
81
+
82
+ const { env } = process;
83
+ const proxy = env.http_proxy || env.HTTP_PROXY || env.npm_config_proxy;
84
+
85
+ await TokenizersBinaryManager.prepareBinary(
86
+ join(__dirname, '..'),
87
+ packageJson.binary.version || packageJson.version,
88
+ packageJson.binary,
89
+ { force, ignoreIfExists, proxy },
90
+ );
91
+ }