Description
Currently, the @huggingface/transformers library is imported and executed entirely within a Web Worker. Because Web Workers have isolated execution environments, the exported env object from @huggingface/transformers is trapped inside the worker thread.
As a result, developers using this library from the main thread cannot access or modify the env variables (e.g., env.allowLocalModels, etc.). This strict isolation makes it difficult to customize the behavior of the transformers library dynamically.
Solution
Add support for an additional env parameter in the createOptions argument of createXxxProvider to be passed to the worker. Furthermore, after instantiating new Worker, automatically check if a custom env was provided, and automatically call the worker's env modification method.
Description
Currently, the
@huggingface/transformerslibrary is imported and executed entirely within a Web Worker. Because Web Workers have isolated execution environments, the exportedenvobject from@huggingface/transformersis trapped inside the worker thread.As a result, developers using this library from the main thread cannot access or modify the
envvariables (e.g.,env.allowLocalModels, etc.). This strict isolation makes it difficult to customize the behavior of the transformers library dynamically.Solution
Add support for an additional
envparameter in thecreateOptionsargument ofcreateXxxProviderto be passed to the worker. Furthermore, after instantiatingnew Worker, automatically check if a customenvwas provided, and automatically call the worker'senvmodification method.