jan/web/app/_hooks/useStartStopModel.ts
James d982dce090 feat: allowing user to fetch models from github
Signed-off-by: James <james@jan.ai>
2023-10-12 07:30:29 -07:00

27 lines
902 B
TypeScript

import { executeSerial } from "@/_services/pluginService";
import { DataService, InferenceService } from "../../shared/coreService";
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(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 };
}