From d160d0351f85b4098affd8f21cb57866031551ae Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 24 Oct 2024 00:48:34 -0700 Subject: [PATCH] refac --- src/lib/components/admin/Evaluations.svelte | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/lib/components/admin/Evaluations.svelte b/src/lib/components/admin/Evaluations.svelte index 3dd4d3ae4..ef9beb7a7 100644 --- a/src/lib/components/admin/Evaluations.svelte +++ b/src/lib/components/admin/Evaluations.svelte @@ -298,8 +298,18 @@ feedbacks = await getAllFeedbacks(localStorage.token); loaded = true; - tokenizer = await AutoTokenizer.from_pretrained(EMBEDDING_MODEL); - model = await AutoModel.from_pretrained(EMBEDDING_MODEL); + // Check if the tokenizer and model are already loaded and stored in the window object + if (!window.tokenizer) { + window.tokenizer = await AutoTokenizer.from_pretrained(EMBEDDING_MODEL); + } + + if (!window.model) { + window.model = await AutoModel.from_pretrained(EMBEDDING_MODEL); + } + + // Use the tokenizer and model from the window object + tokenizer = window.tokenizer; + model = window.model; // Pre-compute embeddings for all unique tags const allTags = new Set(feedbacks.flatMap((feedback) => feedback.data.tags || []));