jan/web/app/_hooks/useInitModel.ts
NamH 00c944c0b5
Add empty model conversation (#254)
* add empty conversation model selection

Signed-off-by: James <james@jan.ai>

* chore: using secondary button instead of sidebar button

Signed-off-by: James <james@jan.ai>

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2023-10-02 19:36:10 -07:00

26 lines
851 B
TypeScript

import { Product } from "@/_models/Product";
import { executeSerial } from "@/_services/pluginService";
import { InfereceService } from "../../shared/coreService";
import { useAtom } from "jotai";
import { currentProductAtom } from "@/_helpers/atoms/Model.atom";
export default function useInitModel() {
const [activeModel, setActiveModel] = useAtom(currentProductAtom);
const initModel = async (model: Product) => {
if (activeModel && activeModel.id === model.id) {
console.debug(`Model ${model.id} is already init. Ignore..`);
return;
}
try {
await executeSerial(InfereceService.INIT_MODEL, model);
console.debug(`Init model ${model.name} successfully!`);
setActiveModel(model);
} catch (err) {
console.error(`Init model ${model.name} failed: ${err}`);
}
};
return { initModel };
}