File size: 793 Bytes
9662103 c7f83e1 9662103 c7f83e1 9662103 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import { page } from "$app/stores";
import type { ModelEntryWithTokenizer } from "$lib/components/InferencePlayground/types";
import { effect } from "$lib/utils/effect";
import { get, writable } from "svelte/store";
function createModelsStore() {
let hasStarted = false;
const store = writable<ModelEntryWithTokenizer[]>([]);
function init() {
store.set(get(page)?.data.models ?? []);
hasStarted = true;
}
const subscribe: (typeof store)["subscribe"] = (...args) => {
if (!hasStarted) init();
hasStarted = true;
const unsubs = [
effect(page, $page => {
store.set($page.data.models);
}),
store.subscribe(...args),
];
return () => {
unsubs.forEach(unsub => unsub());
};
};
return { ...store, subscribe };
}
export const models = createModelsStore();
|