xenova / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
9.71k stars 571 forks source link

Method to send `HF_TOKEN` from the client side #777

Open AnmolBansalDEV opened 1 month ago

AnmolBansalDEV commented 1 month ago

Feature request

For using private/gated models, we should add functionality to pass the HF_TOKEN from the client side as well. Currently Transformer.js only provides ways to access private/gated models from the node js servers only i.e. backend (check here). But there are relevant use cases where passing the HF_TOKEN from the Frontend also makes sense.

Motivation

Usecases

One usecase I can think of is when the application developer wants the user to enter their own HF_TOKEN from the Frontend to access the model and use the application locally in their browser. This a a valid usecase that is being implemented in many AI applications coming up that expect the user to input the API key to use the application.

Security Considerations

I understand that it is a dangerous feature as it makes it possible for a developer to expose their token to the web. But I think not having functionality to support this is not the optimum way to handle the situation, instead, we should add an explicit warning regarding the pitfalls of accidentally exposing the token.

Your contribution

I can work on this, but I'm not very confident as I haven't gone through the codebase. But happy to have a stab at it if okay with maintainers.