jan/web/app/_hooks/useInitModel.ts
NamH 6e2210cb22
feat: adding create bot functionality (#368)
* feat: adding create bot functionality

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

* update the temperature progress bar

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

* chore: remove tgz

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

* update core dependency

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

* fix e2e test

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

---------

Signed-off-by: James <james@jan.ai>
Co-authored-by: James <james@jan.ai>
2023-10-23 15:57:56 +07:00

34 lines
1.0 KiB
TypeScript

import { executeSerial } from '@/_services/pluginService'
import { InferenceService } from '@janhq/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 currentTime = Date.now()
console.debug('Init model: ', model._id)
const res = await executeSerial(InferenceService.InitModel, model._id)
if (res?.error) {
console.error('Failed to init model: ', res.error)
return res
} else {
console.debug(
`Init model successfully!, take ${Date.now() - currentTime}ms`
)
setActiveModel(model)
return {}
}
}
return { initModel }
}