Allow WASM threading for non-Android. Fix eslint for transformers.mjs

This commit is contained in:
Cohee 2024-07-17 12:48:59 +00:00
parent 921297f1e5
commit c3d04066bc
2 changed files with 11 additions and 3 deletions

View File

@ -17,6 +17,15 @@ module.exports = {
node: true, node: true,
}, },
}, },
{
files: ['src/**/*.mjs'],
parserOptions: {
sourceType: 'module',
},
env: {
node: true,
},
},
{ {
// Browser-side files // Browser-side files
files: ['public/**/*.js'], files: ['public/**/*.js'],

View File

@ -1,13 +1,12 @@
import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers'; import { pipeline, env, RawImage, Pipeline } from 'sillytavern-transformers';
import { getConfigValue } from './util.js'; import { getConfigValue } from './util.js';
import path from 'path'; import path from 'path';
import _ from 'lodash';
configureTransformers(); configureTransformers();
function configureTransformers() { function configureTransformers() {
// Limit the number of threads to 1 to avoid issues on Android // Limit the number of threads to 1 to avoid issues on Android
env.backends.onnx.wasm.numThreads = 1; env.backends.onnx.wasm.numThreads = process.platform === 'android' ? 1 : 0;
// Use WASM from a local folder to avoid CDN connections // 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;
} }
@ -114,4 +113,4 @@ async function getPipeline(task, forceModel = '') {
export default { export default {
getPipeline, getPipeline,
getRawImage, getRawImage,
} };