* @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>
29 lines
900 B
TypeScript
29 lines
900 B
TypeScript
import { executeSerial } from "@/_services/pluginService";
|
|
import { InferenceService } from "@janhq/plugin-core";
|
|
import { useAtom } from "jotai";
|
|
import { activeAssistantModelAtom } from "@/_helpers/atoms/Model.atom";
|
|
import { AssistantModel } from "@/_models/AssistantModel";
|
|
|
|
export default function useInitModel() {
|
|
const [activeModel, setActiveModel] = useAtom(activeAssistantModelAtom);
|
|
|
|
const initModel = async (model: AssistantModel) => {
|
|
if (activeModel && activeModel._id === model._id) {
|
|
console.debug(`Model ${model._id} is already init. Ignore..`);
|
|
return;
|
|
}
|
|
|
|
const res = await executeSerial(InferenceService.InitModel, model._id);
|
|
if (res?.error) {
|
|
console.log("error occured: ", res);
|
|
return res;
|
|
} else {
|
|
console.log(`Init model successfully!`);
|
|
setActiveModel(model);
|
|
return {};
|
|
}
|
|
};
|
|
|
|
return { initModel };
|
|
}
|