Skip to content

Commit

Permalink
Standardize HF_ACCESS_TOKEN -> HF_TOKEN (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenova authored Dec 6, 2023
1 parent ceb75dc commit 374c105
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions docs/source/guides/private.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ To delete or refresh User Access Tokens, you can click the **Manage** button.

## Step 2: Using the access token in Transformers.js

Transformers.js will attach an Authorization header to requests made to the Hugging Face Hub when the `HF_ACCESS_TOKEN` environment variable is set and visible to the process.
Transformers.js will attach an Authorization header to requests made to the Hugging Face Hub when the `HF_TOKEN` environment variable is set and visible to the process.

One way to do this is to call your program with the environment variable set. For example, let's say you have a file called `llama.js` with the following code:

Expand All @@ -39,10 +39,10 @@ const encoded = tokenizer.encode(text);
console.log(encoded);
```

You can then use the following command to set the `HF_ACCESS_TOKEN` environment variable and run the file:
You can then use the following command to set the `HF_TOKEN` environment variable and run the file:

```bash
HF_ACCESS_TOKEN=hf_... node tests/llama.js
HF_TOKEN=hf_... node tests/llama.js
```

(remember to replace `hf_...` with your actual access token).
Expand All @@ -57,7 +57,7 @@ If done correctly, you should see the following output:
Alternatively, you can set the environment variable directly in your code:
```js
// Set access token (NB: Keep this private!)
process.env.HF_ACCESS_TOKEN = 'hf_...';
process.env.HF_TOKEN = 'hf_...';

// ... rest of your code
```
3 changes: 2 additions & 1 deletion src/utils/hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export async function getFile(urlOrPath) {
if (isHFURL) {
// If an access token is present in the environment variables,
// we add it to the request headers.
const token = process.env?.HF_ACCESS_TOKEN;
// NOTE: We keep `HF_ACCESS_TOKEN` for backwards compatibility (as a fallback).
const token = process.env?.HF_TOKEN ?? process.env?.HF_ACCESS_TOKEN;
if (token) {
headers.set('Authorization', `Bearer ${token}`);
}
Expand Down

0 comments on commit 374c105

Please sign in to comment.