jan/web/app/_hooks/useStartStopModel.ts
Louis a57dfe743b
fixes: #247 - inference plugin should check nitro service available (#313)
* fix: #247 - inference plugin should check nitro service available

* fix: #247 check service status and emit error if any

* chore: error handling

* chore: typo

* fix: open conversation does not work when model is deleted

* chore: reload plugins in development mode without exiting the process

* chore: move model file check to inference plugin

* update package-lock.json

---------

Co-authored-by: Hien To <>
2023-10-10 18:24:33 +07:00

27 lines
890 B
TypeScript

import { executeSerial } from "@/_services/pluginService";
import { DataService, InferenceService } from "../../shared/coreService";
import useInitModel from "./useInitModel";
import { useSetAtom } from "jotai";
import { currentProductAtom } from "@/_helpers/atoms/Model.atom";
export default function useStartStopModel() {
const { initModel } = useInitModel();
const setActiveModel = useSetAtom(currentProductAtom);
const startModel = async (modelId: string) => {
const model = await executeSerial(DataService.GET_MODEL_BY_ID, 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.STOP_MODEL, modelId);
setActiveModel(undefined);
};
return { startModel, stopModel };
}