jan/web/app/_hooks/useGetDownloadedModels.ts
Louis 5fc1ba7067
feature: @janhq/plugin-core module & plugins update (#321)
* @janhq/plugin-core module

* refactor web to use exported services from module

* refactor data-plugin to provide DAL & move model logics to model management plugin

* model-management in TS

* add ci auto package, increate version, and publish to npm repository

* chore: storage operations

* chore: hybrid data-plugin esm & cjs module

* chore: PouchDB Driver

* chore: documentation

---------

Co-authored-by: Hien To <hien@jan.ai>
Co-authored-by: Service Account <service@jan.ai>
2023-10-14 15:59:28 +07:00

31 lines
1.1 KiB
TypeScript

import { Product } from "@/_models/Product";
import { useEffect } from "react";
import { executeSerial } from "../../../electron/core/plugin-manager/execution/extension-manager";
import { ModelManagementService } from "@janhq/plugin-core";
import { useAtom } from "jotai";
import { downloadedModelAtom } from "@/_helpers/atoms/DownloadedModel.atom";
import { AssistantModel } from "@/_models/AssistantModel";
export function useGetDownloadedModels() {
const [downloadedModels, setDownloadedModels] = useAtom(downloadedModelAtom);
useEffect(() => {
getDownloadedModels().then((downloadedModels) => {
setDownloadedModels(downloadedModels);
});
}, []);
return { downloadedModels };
}
export async function getDownloadedModels(): Promise<AssistantModel[]> {
const downloadedModels: AssistantModel[] = await executeSerial(
ModelManagementService.GetFinishedDownloadModels
);
return downloadedModels ?? [];
}
export async function getConfiguredModels(): Promise<Product[]> {
return executeSerial(ModelManagementService.GetConfiguredModels);
}