Skip to content

Commit 47a54b5

Browse files
Merge pull request justadudewhohacks#69 from bmaguireibm/master
Adding support for external model uris
2 parents f81d35a + 35b8913 commit 47a54b5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/commons/loadWeightMap.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ export function getModelUris(uri: string | undefined, defaultModelName: string)
1616
manifestUri: `/${defaultManifestFilename}`
1717
}
1818
}
19+
const protocol = uri.startsWith('http://') ? 'http://' : uri.startsWith('https://') ? 'https://' : '';
20+
uri = uri.replace(protocol, '');
1921

2022
const parts = uri.split('/').filter(s => s)
2123

2224
const manifestFile = uri.endsWith('.json')
2325
? parts[parts.length - 1]
2426
: defaultManifestFilename
2527

26-
let modelBaseUri = (uri.endsWith('.json') ? parts.slice(0, parts.length - 1) : parts).join('/')
28+
let modelBaseUri = protocol + (uri.endsWith('.json') ? parts.slice(0, parts.length - 1) : parts).join('/')
2729
modelBaseUri = uri.startsWith('/') ? `/${modelBaseUri}` : modelBaseUri
2830

2931
return {

test/tests/commons/loadWeightMap.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ describe('loadWeightMap', () => {
5959
expect(result.modelBaseUri).toEqual('/path/to/modelfiles')
6060
})
6161

62+
it('returns correct uris, given external path', () => {
63+
const uri = 'https://example.com/path/to/modelfiles/';
64+
const result = getModelUris(uri, FAKE_DEFAULT_MODEL_NAME)
65+
66+
expect(result.manifestUri).toEqual(uri + 'model-weights_manifest.json')
67+
expect(result.modelBaseUri).toEqual(uri)
68+
})
69+
6270
})
6371

6472
})

0 commit comments

Comments
 (0)