spec-cat 0.1.0 → 0.1.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/.output/nitro.json +1 -1
- package/.output/public/_nuxt/{Bqlz6CoK.js → BE_75kPa.js} +1 -1
- package/.output/public/_nuxt/{B2wdmh_w.js → BJ7m4fRW.js} +53 -53
- package/.output/public/_nuxt/{KNuzSjk0.js → CCNYUZ9m.js} +1 -1
- package/.output/public/_nuxt/{BvosqTnx.js → DGtcdWVl.js} +1 -1
- package/.output/public/_nuxt/DxEx-kFx.js +1 -0
- package/.output/public/_nuxt/{BwcbSlWF.js → DyMq_cQC.js} +2 -2
- package/.output/public/_nuxt/{COTT6rNZ.js → _cj5lOdZ.js} +1 -1
- package/.output/public/_nuxt/builds/latest.json +1 -1
- package/.output/public/_nuxt/builds/meta/3a0aacc1-0bd1-4d15-8b8a-3cee48cbfc69.json +1 -0
- package/.output/public/_nuxt/{BUOk7wkI.js → gDut6QrP.js} +1 -1
- package/.output/public/_nuxt/{C5wk2twv.js → nJpWpjzg.js} +1 -1
- package/.output/public/_nuxt/{DBab5Zcv.js → waQ9fPC1.js} +1 -1
- package/.output/server/chunks/_/codexProvider.mjs +64 -18
- package/.output/server/chunks/_/codexProvider.mjs.map +1 -1
- package/.output/server/chunks/build/client.precomputed.mjs +1 -1
- package/.output/server/chunks/build/client.precomputed.mjs.map +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +702 -703
- package/.output/server/chunks/routes/_ws.mjs +37 -7
- package/.output/server/chunks/routes/_ws.mjs.map +1 -1
- package/.output/server/node_modules/@huggingface/jinja/dist/index.js +1572 -0
- package/.output/server/node_modules/@huggingface/jinja/package.json +55 -0
- package/.output/server/node_modules/@xenova/transformers/package.json +84 -0
- package/.output/server/node_modules/@xenova/transformers/src/backends/onnx.js +50 -0
- package/.output/server/node_modules/@xenova/transformers/src/configs.js +107 -0
- package/.output/server/node_modules/@xenova/transformers/src/env.js +128 -0
- package/.output/server/node_modules/@xenova/transformers/src/models.js +6267 -0
- package/.output/server/node_modules/@xenova/transformers/src/pipelines.js +3287 -0
- package/.output/server/node_modules/@xenova/transformers/src/processors.js +2248 -0
- package/.output/server/node_modules/@xenova/transformers/src/tokenizers.js +4479 -0
- package/.output/server/node_modules/@xenova/transformers/src/transformers.js +24 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/audio.js +672 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/core.js +175 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/data-structures.js +415 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/generation.js +873 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/hub.js +658 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/image.js +731 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/maths.js +985 -0
- package/.output/server/node_modules/@xenova/transformers/src/utils/tensor.js +1239 -0
- package/.output/server/node_modules/color/index.js +496 -0
- package/.output/server/node_modules/color/package.json +47 -0
- package/.output/server/node_modules/color-convert/conversions.js +839 -0
- package/.output/server/node_modules/color-convert/index.js +81 -0
- package/.output/server/node_modules/color-convert/package.json +48 -0
- package/.output/server/node_modules/color-convert/route.js +97 -0
- package/.output/server/node_modules/color-name/index.js +152 -0
- package/.output/server/node_modules/color-name/package.json +28 -0
- package/.output/server/node_modules/color-string/index.js +242 -0
- package/.output/server/node_modules/color-string/package.json +39 -0
- package/.output/server/node_modules/detect-libc/lib/detect-libc.js +313 -0
- package/.output/server/node_modules/detect-libc/lib/elf.js +39 -0
- package/.output/server/node_modules/detect-libc/lib/filesystem.js +51 -0
- package/.output/server/node_modules/detect-libc/lib/process.js +24 -0
- package/.output/server/node_modules/detect-libc/package.json +44 -0
- package/.output/server/node_modules/is-arrayish/index.js +9 -0
- package/.output/server/node_modules/is-arrayish/package.json +45 -0
- package/.output/server/node_modules/onnxruntime-common/dist/ort-common.node.js +7 -0
- package/.output/server/node_modules/onnxruntime-common/package.json +31 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/darwin/arm64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/darwin/x64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/libonnxruntime.so.1.14.0 +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/arm64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/x64/libonnxruntime.so.1.14.0 +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/linux/x64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/win32/arm64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/bin/napi-v3/win32/x64/onnxruntime_binding.node +0 -0
- package/.output/server/node_modules/onnxruntime-node/dist/backend.js +75 -0
- package/.output/server/node_modules/onnxruntime-node/dist/binding.js +10 -0
- package/.output/server/node_modules/onnxruntime-node/dist/index.js +23 -0
- package/.output/server/node_modules/onnxruntime-node/package.json +58 -0
- package/.output/server/node_modules/onnxruntime-web/dist/ort-web.node.js +7 -0
- package/.output/server/node_modules/onnxruntime-web/package.json +84 -0
- package/.output/server/node_modules/semver/classes/semver.js +333 -0
- package/.output/server/node_modules/semver/functions/coerce.js +62 -0
- package/.output/server/node_modules/semver/functions/compare.js +7 -0
- package/.output/server/node_modules/semver/functions/gte.js +5 -0
- package/.output/server/node_modules/semver/functions/parse.js +18 -0
- package/.output/server/node_modules/semver/internal/constants.js +37 -0
- package/.output/server/node_modules/semver/internal/debug.js +11 -0
- package/.output/server/node_modules/semver/internal/identifiers.js +29 -0
- package/.output/server/node_modules/semver/internal/parse-options.js +17 -0
- package/.output/server/node_modules/semver/internal/re.js +223 -0
- package/.output/server/node_modules/semver/package.json +78 -0
- package/.output/server/node_modules/sharp/build/Release/sharp-linux-x64.node +0 -0
- package/.output/server/node_modules/sharp/lib/channel.js +174 -0
- package/.output/server/node_modules/sharp/lib/colour.js +184 -0
- package/.output/server/node_modules/sharp/lib/composite.js +210 -0
- package/.output/server/node_modules/sharp/lib/constructor.js +439 -0
- package/.output/server/node_modules/sharp/lib/index.js +16 -0
- package/.output/server/node_modules/sharp/lib/input.js +631 -0
- package/.output/server/node_modules/sharp/lib/is.js +155 -0
- package/.output/server/node_modules/sharp/lib/libvips.js +140 -0
- package/.output/server/node_modules/sharp/lib/operation.js +919 -0
- package/.output/server/node_modules/sharp/lib/output.js +1413 -0
- package/.output/server/node_modules/sharp/lib/platform.js +30 -0
- package/.output/server/node_modules/sharp/lib/resize.js +582 -0
- package/.output/server/node_modules/sharp/lib/sharp.js +38 -0
- package/.output/server/node_modules/sharp/lib/utility.js +287 -0
- package/.output/server/node_modules/sharp/package.json +204 -0
- package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/THIRD-PARTY-NOTICES.md +43 -0
- package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/lib/libvips-cpp.so.42 +0 -0
- package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/platform.json +1 -0
- package/.output/server/node_modules/sharp/vendor/8.14.5/linux-x64/versions.json +31 -0
- package/.output/server/node_modules/simple-swizzle/index.js +29 -0
- package/.output/server/node_modules/simple-swizzle/package.json +36 -0
- package/.output/server/package.json +15 -1
- package/README.md +2 -0
- package/package.json +12 -19
- package/.output/public/_nuxt/5FxpIoe_.js +0 -1
- package/.output/public/_nuxt/builds/meta/21578a05-1b7e-4847-a8ff-7480800ea4a6.json +0 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@huggingface/jinja",
|
|
3
|
+
"packageManager": "pnpm@8.10.5",
|
|
4
|
+
"version": "0.2.2",
|
|
5
|
+
"description": "A minimalistic JavaScript implementation of the Jinja templating engine, specifically designed for parsing and rendering ML chat templates.",
|
|
6
|
+
"repository": "https://github.com/huggingface/huggingface.js.git",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.cjs",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"require": "./dist/index.cjs",
|
|
18
|
+
"import": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"source": "src/index.ts",
|
|
25
|
+
"files": [
|
|
26
|
+
"src",
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"tsconfig.json"
|
|
30
|
+
],
|
|
31
|
+
"keywords": [
|
|
32
|
+
"huggingface",
|
|
33
|
+
"jinja",
|
|
34
|
+
"templates",
|
|
35
|
+
"hugging",
|
|
36
|
+
"face"
|
|
37
|
+
],
|
|
38
|
+
"author": "Hugging Face",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"typescript": "^5.3.2",
|
|
42
|
+
"@xenova/transformers": "^2.9.0",
|
|
43
|
+
"@huggingface/hub": "^0.14.2"
|
|
44
|
+
},
|
|
45
|
+
"scripts": {
|
|
46
|
+
"lint": "eslint --quiet --fix --ext .cjs,.ts .",
|
|
47
|
+
"lint:check": "eslint --ext .cjs,.ts .",
|
|
48
|
+
"format": "prettier --write .",
|
|
49
|
+
"format:check": "prettier --check .",
|
|
50
|
+
"build": "tsup src/index.ts --format cjs,esm --clean --dts",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"test:browser": "vitest run --browser.name=chrome --browser.headless",
|
|
53
|
+
"check": "tsc"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xenova/transformers",
|
|
3
|
+
"version": "2.17.2",
|
|
4
|
+
"description": "State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!",
|
|
5
|
+
"main": "./src/transformers.js",
|
|
6
|
+
"types": "./types/transformers.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"typegen": "tsc ./src/transformers.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outDir types",
|
|
10
|
+
"dev": "webpack serve --no-client-overlay",
|
|
11
|
+
"build": "webpack && npm run typegen",
|
|
12
|
+
"generate-tests": "python -m tests.generate_tests",
|
|
13
|
+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --verbose --maxConcurrency 1",
|
|
14
|
+
"readme": "python ./docs/scripts/build_readme.py",
|
|
15
|
+
"docs-api": "node ./docs/scripts/generate.js",
|
|
16
|
+
"docs-preview": "doc-builder preview transformers.js ./docs/source/ --not_python_module",
|
|
17
|
+
"docs-build": "doc-builder build transformers.js ./docs/source/ --not_python_module --build_dir ./docs/build/ --repo_owner xenova"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/xenova/transformers.js.git"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"transformers",
|
|
25
|
+
"transformers.js",
|
|
26
|
+
"huggingface",
|
|
27
|
+
"hugging face",
|
|
28
|
+
"machine learning",
|
|
29
|
+
"deep learning",
|
|
30
|
+
"artificial intelligence",
|
|
31
|
+
"AI",
|
|
32
|
+
"ML"
|
|
33
|
+
],
|
|
34
|
+
"author": "Xenova",
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/xenova/transformers.js/issues"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/xenova/transformers.js#readme",
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"onnxruntime-web": "1.14.0",
|
|
42
|
+
"sharp": "^0.32.0",
|
|
43
|
+
"@huggingface/jinja": "^0.2.2"
|
|
44
|
+
},
|
|
45
|
+
"optionalDependencies": {
|
|
46
|
+
"onnxruntime-node": "1.14.0"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@types/jest": "^29.5.1",
|
|
50
|
+
"catharsis": "github:xenova/catharsis",
|
|
51
|
+
"copy-webpack-plugin": "^11.0.0",
|
|
52
|
+
"jest": "^29.5.0",
|
|
53
|
+
"jest-environment-node": "^29.5.0",
|
|
54
|
+
"jsdoc-to-markdown": "^8.0.1",
|
|
55
|
+
"typescript": "^5.2.2",
|
|
56
|
+
"wavefile": "^11.0.0",
|
|
57
|
+
"webpack": "^5.80.0",
|
|
58
|
+
"webpack-cli": "^5.0.2",
|
|
59
|
+
"webpack-dev-server": "^4.13.3"
|
|
60
|
+
},
|
|
61
|
+
"overrides": {
|
|
62
|
+
"semver": "^7.5.4",
|
|
63
|
+
"protobufjs": "^7.2.6"
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"src",
|
|
67
|
+
"dist",
|
|
68
|
+
"types",
|
|
69
|
+
"README.md",
|
|
70
|
+
"LICENSE"
|
|
71
|
+
],
|
|
72
|
+
"browser": {
|
|
73
|
+
"fs": false,
|
|
74
|
+
"path": false,
|
|
75
|
+
"url": false,
|
|
76
|
+
"sharp": false,
|
|
77
|
+
"onnxruntime-node": false
|
|
78
|
+
},
|
|
79
|
+
"publishConfig": {
|
|
80
|
+
"access": "public"
|
|
81
|
+
},
|
|
82
|
+
"jsdelivr": "./dist/transformers.min.js",
|
|
83
|
+
"unpkg": "./dist/transformers.min.js"
|
|
84
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Handler file for choosing the correct version of ONNX Runtime, based on the environment.
|
|
3
|
+
* Ideally, we could import the `onnxruntime-web` and `onnxruntime-node` packages only when needed,
|
|
4
|
+
* but dynamic imports don't seem to work with the current webpack version and/or configuration.
|
|
5
|
+
* This is possibly due to the experimental nature of top-level await statements.
|
|
6
|
+
* So, we just import both packages, and use the appropriate one based on the environment:
|
|
7
|
+
* - When running in node, we use `onnxruntime-node`.
|
|
8
|
+
* - When running in the browser, we use `onnxruntime-web` (`onnxruntime-node` is not bundled).
|
|
9
|
+
*
|
|
10
|
+
* This module is not directly exported, but can be accessed through the environment variables:
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { env } from '@xenova/transformers';
|
|
13
|
+
* console.log(env.backends.onnx);
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @module backends/onnx
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// NOTE: Import order matters here. We need to import `onnxruntime-node` before `onnxruntime-web`.
|
|
20
|
+
// In either case, we select the default export if it exists, otherwise we use the named export.
|
|
21
|
+
import * as ONNX_NODE from 'onnxruntime-node';
|
|
22
|
+
import * as ONNX_WEB from 'onnxruntime-web';
|
|
23
|
+
|
|
24
|
+
/** @type {import('onnxruntime-web')} The ONNX runtime module. */
|
|
25
|
+
export let ONNX;
|
|
26
|
+
|
|
27
|
+
export const executionProviders = [
|
|
28
|
+
// 'webgpu',
|
|
29
|
+
'wasm'
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
if (typeof process !== 'undefined' && process?.release?.name === 'node') {
|
|
33
|
+
// Running in a node-like environment.
|
|
34
|
+
ONNX = ONNX_NODE.default ?? ONNX_NODE;
|
|
35
|
+
|
|
36
|
+
// Add `cpu` execution provider, with higher precedence that `wasm`.
|
|
37
|
+
executionProviders.unshift('cpu');
|
|
38
|
+
|
|
39
|
+
} else {
|
|
40
|
+
// Running in a browser-environment
|
|
41
|
+
ONNX = ONNX_WEB.default ?? ONNX_WEB;
|
|
42
|
+
|
|
43
|
+
// SIMD for WebAssembly does not operate correctly in some recent versions of iOS (16.4.x).
|
|
44
|
+
// As a temporary fix, we disable it for now.
|
|
45
|
+
// For more information, see: https://github.com/microsoft/onnxruntime/issues/15644
|
|
46
|
+
const isIOS = typeof navigator !== 'undefined' && /iP(hone|od|ad).+16_4.+AppleWebKit/.test(navigator.userAgent);
|
|
47
|
+
if (isIOS) {
|
|
48
|
+
ONNX.env.wasm.simd = false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @file Helper module for using model configs. For more information, see the corresponding
|
|
4
|
+
* [Python documentation](https://huggingface.co/docs/transformers/main/en/model_doc/auto#transformers.AutoConfig).
|
|
5
|
+
*
|
|
6
|
+
* **Example:** Load an `AutoConfig`.
|
|
7
|
+
*
|
|
8
|
+
* ```javascript
|
|
9
|
+
* import { AutoConfig } from '@xenova/transformers';
|
|
10
|
+
* let config = await AutoConfig.from_pretrained('bert-base-uncased');
|
|
11
|
+
* console.log(config);
|
|
12
|
+
* // PretrainedConfig {
|
|
13
|
+
* // "model_type": "bert",
|
|
14
|
+
* // "is_encoder_decoder": false,
|
|
15
|
+
* // "architectures": [
|
|
16
|
+
* // "BertForMaskedLM"
|
|
17
|
+
* // ],
|
|
18
|
+
* // "vocab_size": 30522
|
|
19
|
+
* // "num_attention_heads": 12,
|
|
20
|
+
* // "num_hidden_layers": 12,
|
|
21
|
+
* // "hidden_size": 768,
|
|
22
|
+
* // "max_position_embeddings": 512,
|
|
23
|
+
* // ...
|
|
24
|
+
* // }
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @module configs
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
import {
|
|
31
|
+
getModelJSON,
|
|
32
|
+
} from './utils/hub.js';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @typedef {import('./utils/hub.js').PretrainedOptions} PretrainedOptions
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Loads a config from the specified path.
|
|
41
|
+
* @param {string} pretrained_model_name_or_path The path to the config directory.
|
|
42
|
+
* @param {PretrainedOptions} options Additional options for loading the config.
|
|
43
|
+
* @returns {Promise<Array>} A promise that resolves with information about the loaded config.
|
|
44
|
+
*/
|
|
45
|
+
async function loadConfig(pretrained_model_name_or_path, options) {
|
|
46
|
+
let info = await getModelJSON(pretrained_model_name_or_path, 'config.json', true, options);
|
|
47
|
+
return info;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Base class for all configuration classes. For more information, see the corresponding
|
|
52
|
+
* [Python documentation](https://huggingface.co/docs/transformers/main/en/main_classes/configuration#transformers.PretrainedConfig).
|
|
53
|
+
*/
|
|
54
|
+
export class PretrainedConfig {
|
|
55
|
+
// NOTE: Typo in original
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Create a new PreTrainedTokenizer instance.
|
|
59
|
+
* @param {Object} configJSON The JSON of the config.
|
|
60
|
+
*/
|
|
61
|
+
constructor(configJSON) {
|
|
62
|
+
this.model_type = null;
|
|
63
|
+
this.is_encoder_decoder = false;
|
|
64
|
+
|
|
65
|
+
Object.assign(this, configJSON);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Loads a pre-trained config from the given `pretrained_model_name_or_path`.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} pretrained_model_name_or_path The path to the pre-trained config.
|
|
72
|
+
* @param {PretrainedOptions} options Additional options for loading the config.
|
|
73
|
+
* @throws {Error} Throws an error if the config.json is not found in the `pretrained_model_name_or_path`.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<PretrainedConfig>} A new instance of the `PretrainedConfig` class.
|
|
76
|
+
*/
|
|
77
|
+
static async from_pretrained(pretrained_model_name_or_path, {
|
|
78
|
+
progress_callback = null,
|
|
79
|
+
config = null,
|
|
80
|
+
cache_dir = null,
|
|
81
|
+
local_files_only = false,
|
|
82
|
+
revision = 'main',
|
|
83
|
+
} = {}) {
|
|
84
|
+
|
|
85
|
+
let data = config ?? await loadConfig(pretrained_model_name_or_path, {
|
|
86
|
+
progress_callback,
|
|
87
|
+
config,
|
|
88
|
+
cache_dir,
|
|
89
|
+
local_files_only,
|
|
90
|
+
revision,
|
|
91
|
+
})
|
|
92
|
+
return new this(data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Helper class which is used to instantiate pretrained configs with the `from_pretrained` function.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* let config = await AutoConfig.from_pretrained('bert-base-uncased');
|
|
101
|
+
*/
|
|
102
|
+
export class AutoConfig {
|
|
103
|
+
/** @type {PretrainedConfig.from_pretrained} */
|
|
104
|
+
static async from_pretrained(...args) {
|
|
105
|
+
return PretrainedConfig.from_pretrained(...args);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Module used to configure Transformers.js.
|
|
3
|
+
*
|
|
4
|
+
* **Example:** Disable remote models.
|
|
5
|
+
* ```javascript
|
|
6
|
+
* import { env } from '@xenova/transformers';
|
|
7
|
+
* env.allowRemoteModels = false;
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* **Example:** Set local model path.
|
|
11
|
+
* ```javascript
|
|
12
|
+
* import { env } from '@xenova/transformers';
|
|
13
|
+
* env.localModelPath = '/path/to/local/models/';
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* **Example:** Set cache directory.
|
|
17
|
+
* ```javascript
|
|
18
|
+
* import { env } from '@xenova/transformers';
|
|
19
|
+
* env.cacheDir = '/path/to/cache/directory/';
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @module env
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import fs from 'fs';
|
|
26
|
+
import path from 'path';
|
|
27
|
+
import url from 'url';
|
|
28
|
+
|
|
29
|
+
import { ONNX } from './backends/onnx.js';
|
|
30
|
+
const { env: onnx_env } = ONNX;
|
|
31
|
+
|
|
32
|
+
const VERSION = '2.17.2';
|
|
33
|
+
|
|
34
|
+
// Check if various APIs are available (depends on environment)
|
|
35
|
+
const WEB_CACHE_AVAILABLE = typeof self !== 'undefined' && 'caches' in self;
|
|
36
|
+
const FS_AVAILABLE = !isEmpty(fs); // check if file system is available
|
|
37
|
+
const PATH_AVAILABLE = !isEmpty(path); // check if path is available
|
|
38
|
+
|
|
39
|
+
const RUNNING_LOCALLY = FS_AVAILABLE && PATH_AVAILABLE;
|
|
40
|
+
|
|
41
|
+
const __dirname = RUNNING_LOCALLY
|
|
42
|
+
? path.dirname(path.dirname(url.fileURLToPath(import.meta.url)))
|
|
43
|
+
: './';
|
|
44
|
+
|
|
45
|
+
// Only used for environments with access to file system
|
|
46
|
+
const DEFAULT_CACHE_DIR = RUNNING_LOCALLY
|
|
47
|
+
? path.join(__dirname, '/.cache/')
|
|
48
|
+
: null;
|
|
49
|
+
|
|
50
|
+
// Set local model path, based on available APIs
|
|
51
|
+
const DEFAULT_LOCAL_MODEL_PATH = '/models/';
|
|
52
|
+
const localModelPath = RUNNING_LOCALLY
|
|
53
|
+
? path.join(__dirname, DEFAULT_LOCAL_MODEL_PATH)
|
|
54
|
+
: DEFAULT_LOCAL_MODEL_PATH;
|
|
55
|
+
|
|
56
|
+
if (onnx_env?.wasm) {
|
|
57
|
+
// Set path to wasm files. This is needed when running in a web worker.
|
|
58
|
+
// https://onnxruntime.ai/docs/api/js/interfaces/Env.WebAssemblyFlags.html#wasmPaths
|
|
59
|
+
// We use remote wasm files by default to make it easier for newer users.
|
|
60
|
+
// In practice, users should probably self-host the necessary .wasm files.
|
|
61
|
+
onnx_env.wasm.wasmPaths = RUNNING_LOCALLY
|
|
62
|
+
? path.join(__dirname, '/dist/')
|
|
63
|
+
: `https://cdn.jsdelivr.net/npm/@xenova/transformers@${VERSION}/dist/`;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Global variable used to control execution. This provides users a simple way to configure Transformers.js.
|
|
68
|
+
* @property {Object} backends Expose environment variables of different backends,
|
|
69
|
+
* allowing users to set these variables if they want to.
|
|
70
|
+
* @property {string} __dirname Directory name of module. Useful for resolving local paths.
|
|
71
|
+
* @property {string} version This version of Transformers.js.
|
|
72
|
+
* @property {boolean} allowRemoteModels Whether to allow loading of remote files, defaults to `true`.
|
|
73
|
+
* If set to `false`, it will have the same effect as setting `local_files_only=true` when loading pipelines, models, tokenizers, processors, etc.
|
|
74
|
+
* @property {string} remoteHost Host URL to load models from. Defaults to the Hugging Face Hub.
|
|
75
|
+
* @property {string} remotePathTemplate Path template to fill in and append to `remoteHost` when loading models.
|
|
76
|
+
* @property {boolean} allowLocalModels Whether to allow loading of local files, defaults to `true`.
|
|
77
|
+
* If set to `false`, it will skip the local file check and try to load the model from the remote host.
|
|
78
|
+
* @property {string} localModelPath Path to load local models from. Defaults to `/models/`.
|
|
79
|
+
* @property {boolean} useFS Whether to use the file system to load files. By default, it is `true` if available.
|
|
80
|
+
* @property {boolean} useBrowserCache Whether to use Cache API to cache models. By default, it is `true` if available.
|
|
81
|
+
* @property {boolean} useFSCache Whether to use the file system to cache files. By default, it is `true` if available.
|
|
82
|
+
* @property {string} cacheDir The directory to use for caching files with the file system. By default, it is `./.cache`.
|
|
83
|
+
* @property {boolean} useCustomCache Whether to use a custom cache system (defined by `customCache`), defaults to `false`.
|
|
84
|
+
* @property {Object} customCache The custom cache to use. Defaults to `null`. Note: this must be an object which
|
|
85
|
+
* implements the `match` and `put` functions of the Web Cache API. For more information, see https://developer.mozilla.org/en-US/docs/Web/API/Cache
|
|
86
|
+
*/
|
|
87
|
+
export const env = {
|
|
88
|
+
/////////////////// Backends settings ///////////////////
|
|
89
|
+
backends: {
|
|
90
|
+
// onnxruntime-web/onnxruntime-node
|
|
91
|
+
onnx: onnx_env,
|
|
92
|
+
|
|
93
|
+
// TensorFlow.js
|
|
94
|
+
tfjs: {},
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
__dirname,
|
|
98
|
+
version: VERSION,
|
|
99
|
+
|
|
100
|
+
/////////////////// Model settings ///////////////////
|
|
101
|
+
allowRemoteModels: true,
|
|
102
|
+
remoteHost: 'https://huggingface.co/',
|
|
103
|
+
remotePathTemplate: '{model}/resolve/{revision}/',
|
|
104
|
+
|
|
105
|
+
allowLocalModels: true,
|
|
106
|
+
localModelPath: localModelPath,
|
|
107
|
+
useFS: FS_AVAILABLE,
|
|
108
|
+
|
|
109
|
+
/////////////////// Cache settings ///////////////////
|
|
110
|
+
useBrowserCache: WEB_CACHE_AVAILABLE,
|
|
111
|
+
|
|
112
|
+
useFSCache: FS_AVAILABLE,
|
|
113
|
+
cacheDir: DEFAULT_CACHE_DIR,
|
|
114
|
+
|
|
115
|
+
useCustomCache: false,
|
|
116
|
+
customCache: null,
|
|
117
|
+
//////////////////////////////////////////////////////
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @param {Object} obj
|
|
123
|
+
* @private
|
|
124
|
+
*/
|
|
125
|
+
function isEmpty(obj) {
|
|
126
|
+
return Object.keys(obj).length === 0;
|
|
127
|
+
}
|
|
128
|
+
|