jan/web/app/_hooks/useStartStopModel.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

27 lines
914 B
TypeScript

import { executeSerial } from "@/_services/pluginService";
import { ModelManagementService, InferenceService } from "@janhq/plugin-core";
import useInitModel from "./useInitModel";
import { useSetAtom } from "jotai";
import { activeAssistantModelAtom } from "@/_helpers/atoms/Model.atom";
export default function useStartStopModel() {
const { initModel } = useInitModel();
const setActiveModel = useSetAtom(activeAssistantModelAtom);
const startModel = async (modelId: string) => {
const model = await executeSerial(ModelManagementService.GetModelById, modelId);
if (!model) {
alert(`Model ${modelId} not found! Please re-download the model first.`);
} else {
await initModel(model);
}
};
const stopModel = async (modelId: string) => {
await executeSerial(InferenceService.StopModel, modelId);
setActiveModel(undefined);
};
return { startModel, stopModel };
}