[wip] Update transformers.js

This commit is contained in:
Cohee
2025-04-15 21:14:09 +03:00
parent 5510e6da31
commit ba1c69d7a7
4 changed files with 631 additions and 882 deletions

1496
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -3,6 +3,7 @@
"@adobe/css-tools": "^4.4.2",
"@agnai/sentencepiece-js": "^1.1.1",
"@agnai/web-tokenizers": "^0.1.3",
"@huggingface/transformers": "^3.4.2",
"@iconfu/svg-inject": "^1.2.3",
"@jimp/core": "^1.6.0",
"@jimp/js-bmp": "^1.6.0",
@@ -74,7 +75,6 @@
"sanitize-filename": "^1.6.3",
"seedrandom": "^3.0.5",
"showdown": "^2.1.0",
"sillytavern-transformers": "2.14.6",
"simple-git": "^3.27.0",
"slidetoggle": "^4.0.0",
"tiktoken": "^1.0.20",
@@ -100,6 +100,9 @@
},
"node-fetch": {
"whatwg-url": "^14.0.0"
},
"@huggingface/transformers": {
"onnxruntime-node": "https://github.com/Cohee1207/onnxruntime/releases/download/1.20.1/onnxruntime-node-1.20.1.tgz"
}
},
"name": "sillytavern",

View File

@@ -332,7 +332,7 @@ try {
// 1. Create default config files
createDefaultFiles();
// 2. Copy transformers WASM binaries from node_modules
copyWasmFiles();
// copyWasmFiles();
// 3. Add missing config values
addMissingConfigValues();
} catch (error) {

View File

@@ -3,16 +3,16 @@ import fs from 'node:fs';
import process from 'node:process';
import { Buffer } from 'node:buffer';
import { pipeline, env, RawImage } from 'sillytavern-transformers';
import { pipeline, env, RawImage } from '@huggingface/transformers';
import { getConfigValue } from './util.js';
configureTransformers();
function configureTransformers() {
// Limit the number of threads to 1 to avoid issues on Android
env.backends.onnx.wasm.numThreads = 1;
// env.backends.onnx.wasm.numThreads = 1;
// Use WASM from a local folder to avoid CDN connections
env.backends.onnx.wasm.wasmPaths = path.join(process.cwd(), 'dist') + path.sep;
// env.backends.onnx.wasm.wasmPaths = path.join(process.cwd(), 'dist') + path.sep;
}
const tasks = {
@@ -115,9 +115,9 @@ async function migrateCacheToDataDir() {
/**
* Gets the transformers.js pipeline for a given task.
* @param {import('sillytavern-transformers').PipelineType} task The task to get the pipeline for
* @param {import('@huggingface/transformers').PipelineType} task The task to get the pipeline for
* @param {string} forceModel The model to use for the pipeline, if any
* @returns {Promise<import('sillytavern-transformers').Pipeline>} The transformers.js pipeline
* @returns {Promise<import('@huggingface/transformers').Pipeline>} The transformers.js pipeline
*/
export async function getPipeline(task, forceModel = '') {
await migrateCacheToDataDir();