loadRuntimeModel function domain exported
Last updated: 2026-02-24T19:46:21.733Z
Metrics
LOC: 38
Complexity: 5
Params: 0
Signature
loadRuntimeModel(): : Promise<{
model: LayersModel;
vocab: Map<string, number>;
labels: FieldType[];
} | null>
Summary
Loads the runtime-trained model from chrome.storage.local. Returns null if no runtime model has been trained yet.
Source Code
export async function loadRuntimeModel(): Promise<{
model: LayersModel;
vocab: Map<string, number>;
labels: FieldType[];
} | null> {
const result = await chrome.storage.local.get([
RUNTIME_MODEL_KEY,
RUNTIME_VOCAB_KEY,
RUNTIME_LABELS_KEY,
]);
const stored = result[RUNTIME_MODEL_KEY] as StoredModelArtifacts | undefined;
const vocabObj = result[RUNTIME_VOCAB_KEY] as
| Record<string, number>
| undefined;
const labelsArr = result[RUNTIME_LABELS_KEY] as string[] | undefined;
if (!stored || !vocabObj || !labelsArr) return null;
try {
const tf = await import("@tensorflow/tfjs");
const loadHandler: import("@tensorflow/tfjs").io.IOHandler = {
load: async () => ({
modelTopology: stored.topology as {},
weightSpecs:
stored.weightSpecs as import("@tensorflow/tfjs").io.WeightsManifestEntry[],
weightData: base64ToArrayBuffer(stored.weightDataB64),
format: "layers-model",
}),
};
const model = await tf.loadLayersModel(loadHandler);
const vocab = new Map(Object.entries(vocabObj));
return { model, vocab, labels: labelsArr as FieldType[] };
} catch (err) {
log.warn("Falha ao carregar modelo do storage:", err);
return null;
}
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| base64ToArrayBuffer | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| PretrainedState | uses |
| resetModelMock | uses |