saveModelToStorage function domain
Last updated: 2026-02-24T19:46:21.733Z
Metrics
LOC: 35
Complexity: 2
Params: 6
Signature
saveModelToStorage(
model: LayersModel,
vocab: Map<string, number>,
labels: FieldType[],
meta: TrainingMeta,
): : Promise<void>
Architecture violations
- [warning] max-parameters: 'saveModelToStorage' has 6 parameters (max 5)
Source Code
async function saveModelToStorage(
model: LayersModel,
vocab: Map<string, number>,
labels: FieldType[],
meta: TrainingMeta,
): Promise<void> {
// Custom IO handler: saves model artifacts to chrome.storage.local
const tf = await import("@tensorflow/tfjs");
const storageHandler: import("@tensorflow/tfjs").io.IOHandler = {
save: async (artifacts) => {
const weightData = artifacts.weightData as ArrayBuffer;
const stored: StoredModelArtifacts = {
topology: artifacts.modelTopology,
weightSpecs: (artifacts.weightSpecs ?? []) as unknown[],
weightDataB64: arrayBufferToBase64(weightData),
};
const vocabObj = Object.fromEntries(vocab);
await chrome.storage.local.set({
[RUNTIME_MODEL_KEY]: stored,
[RUNTIME_VOCAB_KEY]: vocabObj,
[RUNTIME_LABELS_KEY]: labels,
[RUNTIME_META_KEY]: meta,
});
return {
modelArtifactsInfo: {
dateSaved: new Date(),
modelTopologyType: "JSON" as const,
weightDataBytes: weightData.byteLength,
},
};
},
};
await model.save(storageHandler);
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| arrayBufferToBase64 | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| trainModelFromDataset | calls |