Skip to content

Commit 4d18e12

Browse files
Steve LandauSteve Landau
authored andcommitted
Use HF_ENDPOINT for remote host default
1 parent 6cc0630 commit 4d18e12

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

packages/transformers/src/env.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,10 @@ export const env = {
257257
},
258258
/////////////////// Model settings ///////////////////
259259
allowRemoteModels: true,
260-
remoteHost: 'https://huggingface.co/',
260+
remoteHost:
261+
typeof process !== 'undefined'
262+
? (process.env?.HF_ENDPOINT ?? 'https://huggingface.co/')
263+
: 'https://huggingface.co/',
261264
remotePathTemplate: '{model}/resolve/{revision}/',
262265

263266
allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV || IS_DENO_WEB_RUNTIME), // Default to true for non-web environments, false for web environments
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { spawnSync } from "child_process";
2+
3+
const ENV_MODULE_URL = new URL("../src/env.js", import.meta.url).href;
4+
5+
function readRemoteHost(env) {
6+
const code = `import { env } from ${JSON.stringify(ENV_MODULE_URL)}; process.stdout.write(env.remoteHost);`;
7+
const result = spawnSync("node", ["--input-type=module", "-e", code], { env });
8+
9+
expect(result.stderr.toString()).toEqual("");
10+
expect(result.status).toEqual(0);
11+
12+
return result.stdout.toString();
13+
}
14+
15+
describe("env", () => {
16+
it("defaults remoteHost to the Hugging Face Hub", async () => {
17+
const env = { ...process.env };
18+
delete env.HF_ENDPOINT;
19+
20+
expect(readRemoteHost(env)).toBe("https://huggingface.co/");
21+
});
22+
23+
it("uses HF_ENDPOINT as the default remoteHost when set", async () => {
24+
const env = { ...process.env, HF_ENDPOINT: "https://hf.example.com/" };
25+
26+
expect(readRemoteHost(env)).toBe("https://hf.example.com/");
27+
});
28+
});

0 commit comments

Comments
 (0)