mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-06 16:29:04 +00:00
image models: downloads honour HF_ENDPOINT like setup and the MTP fetch (#4369)
This commit is contained in:
1 parent
a1047b7fdf
commit
a421f7dee6
2 files changed
+16
-1
No files matched your search
@@ -42,7 +42,7 @@ export function createImageModels({ dataDir, modelsDir, real = false, changed =
|
||||
variants: catalog.variants.map(v => ({ ...v, downloadGb: v.bytes / 1e9,
|
||||
state: runtime.get(v.id)?.state ?? (installed(v) ? 'installed' : 'available'),
|
||||
progress: runtime.get(v.id)?.progress, error: runtime.get(v.id)?.error,
|
||||
downloadUrl: `https://huggingface.co/${catalog.repo}/resolve/${catalog.revision}/${v.file}` })),
|
||||
downloadUrl: `${(process.env.HF_ENDPOINT || '').trim().replace(/\/+$/, '') || 'https://huggingface.co'}/${catalog.repo}/resolve/${catalog.revision}/${v.file}` })),
|
||||
};
|
||||
}
|
||||
const emit = () => changed(library());
|
||||
|
||||
@@ -62,6 +62,21 @@ test('real downloads verify exact bytes, GGUF header and hash at a pinned URL',
|
||||
assert.equal(restarted.library().variants[0].state, 'installed');
|
||||
assert.equal(restarted.library().applied, 'off');
|
||||
});
|
||||
test('real downloads honour HF_ENDPOINT at call time and keep the source page canonical', async t => {
|
||||
const previous = process.env.HF_ENDPOINT;
|
||||
t.after(() => { if (previous === undefined) delete process.env.HF_ENDPOINT; else process.env.HF_ENDPOINT = previous; });
|
||||
for (const endpoint of ['https://hf-mirror.example/', ' https://hf-mirror.example/// ', undefined, ' ', '///']) {
|
||||
delete process.env.HF_ENDPOINT;
|
||||
let fetched;
|
||||
const { service } = fixture(t, { real: true, catalog: smallCatalog, fetcher: async url => { fetched = url; return new Response(data); } });
|
||||
if (endpoint !== undefined) process.env.HF_ENDPOINT = endpoint;
|
||||
service.install('q4'); await service.whenIdle();
|
||||
const base = endpoint?.includes('hf-mirror') ? 'https://hf-mirror.example' : 'https://huggingface.co';
|
||||
assert.equal(fetched, `${base}/${smallCatalog.repo}/resolve/${smallCatalog.revision}/${smallCatalog.variants[0].file}`);
|
||||
assert.equal(service.library().variants[0].state, 'installed');
|
||||
assert.equal(service.library().sourceUrl, `https://huggingface.co/${smallCatalog.repo}`);
|
||||
}
|
||||
});
|
||||
test('failed verification and failed fetch do not leave installed or partial files', async t => {
|
||||
for (const body of [Buffer.from('bad!test-image-weights'), data.subarray(0, 7)]) {
|
||||
const { service, modelsDir } = fixture(t, { real: true, catalog: smallCatalog, fetcher: async () => new Response(body) });
|
||||
|
||||
Reference in new issue
Block a user