Transformers.js documentation

env

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

env

Module used to configure Transformers.js.

Example: Disable remote models.

import { env } from '@huggingface/transformers';
env.allowRemoteModels = false;

Example: Set local model path.

import { env } from '@huggingface/transformers';
env.localModelPath = '/path/to/local/models/';

Example: Set cache directory.

import { env } from '@huggingface/transformers';
env.cacheDir = '/path/to/cache/directory/';

env.apis

A read-only object containing information about the APIs available in the current environment.

Kind: static constant of env


env.env : <code> TransformersEnvironment </code>

Kind: static constant of env


env~IS_BROWSER_ENV

Whether we are running in a browser environment

Kind: inner property of env


env~IS_WEBWORKER_ENV

Whether we are running in a web worker environment

Kind: inner property of env


env~IS_WEB_CACHE_AVAILABLE

Whether the Cache API is available

Kind: inner property of env


env~IS_WEBGPU_AVAILABLE

Whether the WebGPU API is available

Kind: inner property of env


env~IS_WEBNN_AVAILABLE

Whether the WebNN API is available

Kind: inner property of env


env~IS_PROCESS_AVAILABLE

Whether the Node.js process API is available

Kind: inner property of env


env~IS_NODE_ENV

Whether we are running in a Node.js environment

Kind: inner property of env


env~IS_FS_AVAILABLE

Whether the filesystem API is available

Kind: inner property of env


env~IS_PATH_AVAILABLE

Whether the path API is available

Kind: inner property of env


env~TransformersEnvironment : <code> Object </code>

Global variable given visible to users to control execution. This provides users a simple way to configure Transformers.js.

Kind: inner typedef of env
Properties

NameTypeDescription
versionstring

This version of Transformers.js.

backends*

Expose environment variables of different backends, allowing users to set these variables if they want to.

allowRemoteModelsboolean

Whether to allow loading of remote files, defaults to true. If set to false, it will have the same effect as setting local_files_only=true when loading pipelines, models, tokenizers, processors, etc.

remoteHoststring

Host URL to load models from. Defaults to the Hugging Face Hub.

remotePathTemplatestring

Path template to fill in and append to remoteHost when loading models.

allowLocalModelsboolean

Whether to allow loading of local files, defaults to false if running in-browser, and true otherwise. If set to false, it will skip the local file check and try to load the model from the remote host.

localModelPathstring

Path to load local models from. Defaults to /models/.

useFSboolean

Whether to use the file system to load files. By default, it is true if available.

useBrowserCacheboolean

Whether to use Cache API to cache models. By default, it is true if available.

useFSCacheboolean

Whether to use the file system to cache files. By default, it is true if available.

cacheDirstring

The directory to use for caching files with the file system. By default, it is ./.cache.

useCustomCacheboolean

Whether to use a custom cache system (defined by customCache), defaults to false.

customCacheObject

The custom cache to use. Defaults to null. Note: this must be an object which 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


< > Update on GitHub