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

View all

  • [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)

graph LR saveModelToStorage["saveModelToStorage"] arrayBufferToBase64["arrayBufferToBase64"] saveModelToStorage -->|calls| arrayBufferToBase64 style saveModelToStorage fill:#dbeafe,stroke:#2563eb,stroke-width:2px click saveModelToStorage "62ae3258e166f5da.html" click arrayBufferToBase64 "1f04fa87078e4837.html"
TargetType
arrayBufferToBase64 calls

Impact (Incoming)

graph LR saveModelToStorage["saveModelToStorage"] trainModelFromDataset["trainModelFromDataset"] trainModelFromDataset -->|calls| saveModelToStorage style saveModelToStorage fill:#dbeafe,stroke:#2563eb,stroke-width:2px click saveModelToStorage "62ae3258e166f5da.html" click trainModelFromDataset "116a4fd1e25c7132.html"
SourceType
trainModelFromDataset calls