MCPcopy Create free account
hub / github.com/tensorflow/tfjs / constructor

Method constructor

tfjs-core/src/io/http.ts:49–87  ·  view source on GitHub ↗
(path: string, loadOptions?: LoadOptions)

Source from the content-addressed store, hash-verified

47 private readonly loadOptions: LoadOptions;
48
49 constructor(path: string, loadOptions?: LoadOptions) {
50 if (loadOptions == null) {
51 loadOptions = {};
52 }
53 this.weightPathPrefix = loadOptions.weightPathPrefix;
54 this.weightUrlConverter = loadOptions.weightUrlConverter;
55
56 if (loadOptions.fetchFunc != null) {
57 assert(
58 typeof loadOptions.fetchFunc === 'function',
59 () => 'Must pass a function that matches the signature of ' +
60 '`fetch` (see ' +
61 'https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)');
62 this.fetch = loadOptions.fetchFunc;
63 } else {
64 this.fetch = env().platform.fetch;
65 }
66
67 assert(
68 path != null && path.length > 0,
69 () => 'URL path for http must not be null, undefined or ' +
70 'empty.');
71
72 if (Array.isArray(path)) {
73 assert(
74 path.length === 2,
75 () => 'URL paths for http must have a length of 2, ' +
76 `(actual length is ${path.length}).`);
77 }
78 this.path = path;
79
80 if (loadOptions.requestInit != null &&
81 loadOptions.requestInit.body != null) {
82 throw new Error(
83 'requestInit is expected to have no pre-existing body, but has one.');
84 }
85 this.requestInit = loadOptions.requestInit || {};
86 this.loadOptions = loadOptions;
87 }
88
89 async save(modelArtifacts: ModelArtifacts): Promise<SaveResult> {
90 if (modelArtifacts.modelTopology instanceof ArrayBuffer) {

Callers

nothing calls this directly

Calls 2

assertFunction · 0.90
envFunction · 0.90

Tested by

no test coverage detected