Buckets:

rtrm's picture
|
download
raw
7.07 kB
# env
Module used to configure Transformers.js.
**Example:** Disable remote models.
```javascript
import { env } from '@huggingface/transformers';
env.allowRemoteModels = false;
```
**Example:** Set local model path.
```javascript
import { env } from '@huggingface/transformers';
env.localModelPath = '/path/to/local/models/';
```
**Example:** Set cache directory.
```javascript
import { env } from '@huggingface/transformers';
env.cacheDir = '/path/to/cache/directory/';
```
* [env](#module_env)
* _static_
* [`.apis`](#module_env.apis)
* [`.env`](#module_env.env) : <code>TransformersEnvironment</code>
* _inner_
* [`~IS_BROWSER_ENV`](#module_env..IS_BROWSER_ENV)
* [`~IS_WEBWORKER_ENV`](#module_env..IS_WEBWORKER_ENV)
* [`~IS_WEB_CACHE_AVAILABLE`](#module_env..IS_WEB_CACHE_AVAILABLE)
* [`~IS_WEBGPU_AVAILABLE`](#module_env..IS_WEBGPU_AVAILABLE)
* [`~IS_WEBNN_AVAILABLE`](#module_env..IS_WEBNN_AVAILABLE)
* [`~IS_PROCESS_AVAILABLE`](#module_env..IS_PROCESS_AVAILABLE)
* [`~IS_NODE_ENV`](#module_env..IS_NODE_ENV)
* [`~IS_FS_AVAILABLE`](#module_env..IS_FS_AVAILABLE)
* [`~IS_PATH_AVAILABLE`](#module_env..IS_PATH_AVAILABLE)
* [`~TransformersEnvironment`](#module_env..TransformersEnvironment) : <code>Object</code>
* * *
<a id="module_env.apis" class="group"></a>
## `env.apis`
A read-only object containing information about the APIs available in the current environment.
**Kind**: static constant of [<code>env</code>](#module_env)
* * *
<a id="module_env.env" class="group"></a>
## `env.env` : <code>TransformersEnvironment</code>
**Kind**: static constant of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_BROWSER_ENV" class="group"></a>
## `env~IS_BROWSER_ENV`
Whether we are running in a browser environment (and not a web worker)
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_WEBWORKER_ENV" class="group"></a>
## `env~IS_WEBWORKER_ENV`
Whether we are running in a web worker environment
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_WEB_CACHE_AVAILABLE" class="group"></a>
## `env~IS_WEB_CACHE_AVAILABLE`
Whether the Cache API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_WEBGPU_AVAILABLE" class="group"></a>
## `env~IS_WEBGPU_AVAILABLE`
Whether the WebGPU API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_WEBNN_AVAILABLE" class="group"></a>
## `env~IS_WEBNN_AVAILABLE`
Whether the WebNN API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_PROCESS_AVAILABLE" class="group"></a>
## `env~IS_PROCESS_AVAILABLE`
Whether the Node.js process API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_NODE_ENV" class="group"></a>
## `env~IS_NODE_ENV`
Whether we are running in a Node.js-like environment (node, deno, bun)
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_FS_AVAILABLE" class="group"></a>
## `env~IS_FS_AVAILABLE`
Whether the filesystem API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..IS_PATH_AVAILABLE" class="group"></a>
## `env~IS_PATH_AVAILABLE`
Whether the path API is available
**Kind**: inner property of [<code>env</code>](#module_env)
* * *
<a id="module_env..TransformersEnvironment" class="group"></a>
## `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 [<code>env</code>](#module_env)
**Properties**
<table>
<thead>
<tr>
<th>Name</th><th>Type</th><th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>version</td><td><code>string</code></td><td><p>This version of Transformers.js.</p>
</td>
</tr><tr>
<td>backends</td><td><code>*</code></td><td><p>Expose environment variables of different backends,
allowing users to set these variables if they want to.</p>
</td>
</tr><tr>
<td>allowRemoteModels</td><td><code>boolean</code></td><td><p>Whether to allow loading of remote files, defaults to <code>true</code>.
If set to <code>false</code>, it will have the same effect as setting <code>local_files_only=true</code> when loading pipelines, models, tokenizers, processors, etc.</p>
</td>
</tr><tr>
<td>remoteHost</td><td><code>string</code></td><td><p>Host URL to load models from. Defaults to the Hugging Face Hub.</p>
</td>
</tr><tr>
<td>remotePathTemplate</td><td><code>string</code></td><td><p>Path template to fill in and append to <code>remoteHost</code> when loading models.</p>
</td>
</tr><tr>
<td>allowLocalModels</td><td><code>boolean</code></td><td><p>Whether to allow loading of local files, defaults to <code>false</code> if running in-browser, and <code>true</code> otherwise.
If set to <code>false</code>, it will skip the local file check and try to load the model from the remote host.</p>
</td>
</tr><tr>
<td>localModelPath</td><td><code>string</code></td><td><p>Path to load local models from. Defaults to <code>/models/</code>.</p>
</td>
</tr><tr>
<td>useFS</td><td><code>boolean</code></td><td><p>Whether to use the file system to load files. By default, it is <code>true</code> if available.</p>
</td>
</tr><tr>
<td>useBrowserCache</td><td><code>boolean</code></td><td><p>Whether to use Cache API to cache models. By default, it is <code>true</code> if available.</p>
</td>
</tr><tr>
<td>useFSCache</td><td><code>boolean</code></td><td><p>Whether to use the file system to cache files. By default, it is <code>true</code> if available.</p>
</td>
</tr><tr>
<td>cacheDir</td><td><code>string</code></td><td><p>The directory to use for caching files with the file system. By default, it is <code>./.cache</code>.</p>
</td>
</tr><tr>
<td>useCustomCache</td><td><code>boolean</code></td><td><p>Whether to use a custom cache system (defined by <code>customCache</code>), defaults to <code>false</code>.</p>
</td>
</tr><tr>
<td>customCache</td><td><code>Object</code></td><td><p>The custom cache to use. Defaults to <code>null</code>. Note: this must be an object which
implements the <code>match</code> and <code>put</code> functions of the Web Cache API. For more information, see <a href="https://developer.mozilla.org/en-US/docs/Web/API/Cache">https://developer.mozilla.org/en-US/docs/Web/API/Cache</a>.
If you wish, you may also return a <code>Promise&lt;string&gt;</code> from the <code>match</code> function if you&#39;d like to use a file path instead of <code>Promise&lt;Response&gt;</code>.</p>
</td>
</tr> </tbody>
</table>
* * *
<EditOnGithub source="https://github.com/huggingface/transformers.js/blob/main/docs/source/api/env.md" />

Xet Storage Details

Size:
7.07 kB
·
Xet hash:
b6d8d9473e19784bfcb567c5cd74b9cb550244ee76f951abbfd5237b47633a7d

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.