Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/transformers/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ export const env = {
},
/////////////////// Model settings ///////////////////
allowRemoteModels: true,
remoteHost: 'https://huggingface.co/',
remoteHost:
typeof process !== 'undefined'
? (process.env?.HF_ENDPOINT ?? 'https://huggingface.co/')
: 'https://huggingface.co/',
remotePathTemplate: '{model}/resolve/{revision}/',

allowLocalModels: !(IS_BROWSER_ENV || IS_WEBWORKER_ENV || IS_DENO_WEB_RUNTIME), // Default to true for non-web environments, false for web environments
Expand Down
28 changes: 28 additions & 0 deletions packages/transformers/tests/env.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { spawnSync } from "child_process";

const ENV_MODULE_URL = new URL("../src/env.js", import.meta.url).href;

function readRemoteHost(env) {
const code = `import { env } from ${JSON.stringify(ENV_MODULE_URL)}; process.stdout.write(env.remoteHost);`;
const result = spawnSync("node", ["--input-type=module", "-e", code], { env });

expect(result.stderr.toString()).toEqual("");
expect(result.status).toEqual(0);

return result.stdout.toString();
}

describe("env", () => {
it("defaults remoteHost to the Hugging Face Hub", async () => {
const env = { ...process.env };
delete env.HF_ENDPOINT;

expect(readRemoteHost(env)).toBe("https://huggingface.co/");
});

it("uses HF_ENDPOINT as the default remoteHost when set", async () => {
const env = { ...process.env, HF_ENDPOINT: "https://hf.example.com/" };

expect(readRemoteHost(env)).toBe("https://hf.example.com/");
});
});