chore: stop model accordingly on settings changes

This commit is contained in:
Louis 2024-01-04 10:45:56 +07:00 committed by Faisal Amir
parent 49d5703ac3
commit f97fdaed30
6 changed files with 15 additions and 16 deletions

View File

@ -26,7 +26,7 @@ export default function CommandListDownloadedModel() {
const onModelActionClick = (modelId: string) => { const onModelActionClick = (modelId: string) => {
if (activeModel && activeModel.id === modelId) { if (activeModel && activeModel.id === modelId) {
stopModel(modelId) stopModel()
} else { } else {
startModel(modelId) startModel(modelId)
} }

View File

@ -13,6 +13,7 @@ import { useAtomValue, useSetAtom } from 'jotai'
import { InfoIcon } from 'lucide-react' import { InfoIcon } from 'lucide-react'
import { useActiveModel } from '@/hooks/useActiveModel'
import useUpdateModelParameters from '@/hooks/useUpdateModelParameters' import useUpdateModelParameters from '@/hooks/useUpdateModelParameters'
import { getConfigurationsData } from '@/utils/componentSettings' import { getConfigurationsData } from '@/utils/componentSettings'
@ -54,10 +55,13 @@ const SliderRightPanel: React.FC<Props> = ({
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom) const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
const { stopModel } = useActiveModel()
const onValueChanged = (e: number[]) => { const onValueChanged = (e: number[]) => {
if (!threadId) return if (!threadId) return
if (engineParams.some((x) => x.name.includes(name))) { if (engineParams.some((x) => x.name.includes(name))) {
setEngineParamsUpdate(true) setEngineParamsUpdate(true)
stopModel()
} else { } else {
setEngineParamsUpdate(false) setEngineParamsUpdate(false)
} }

View File

@ -53,10 +53,12 @@ export function useActiveModel() {
events.emit(EventName.OnModelInit, model) events.emit(EventName.OnModelInit, model)
} }
const stopModel = async (modelId: string) => { const stopModel = async () => {
const model = downloadedModels.find((e) => e.id === modelId) if (activeModel) {
setStateModel({ state: 'stop', loading: true, model: modelId }) setActiveModel(undefined)
events.emit(EventName.OnModelStop, model) setStateModel({ state: 'stop', loading: true, model: activeModel.id })
events.emit(EventName.OnModelStop, activeModel)
}
} }
return { activeModel, startModel, stopModel, stateModel } return { activeModel, startModel, stopModel, stateModel }

View File

@ -1,11 +1,4 @@
import { import { ChangeEvent, Fragment, KeyboardEvent, useEffect, useRef } from 'react'
ChangeEvent,
Fragment,
KeyboardEvent,
useEffect,
useRef,
useState,
} from 'react'
import { EventName, MessageStatus, events } from '@janhq/core' import { EventName, MessageStatus, events } from '@janhq/core'
import { Button, Textarea } from '@janhq/uikit' import { Button, Textarea } from '@janhq/uikit'

View File

@ -39,7 +39,7 @@ export default function RowModel(props: RowModelProps) {
const onModelActionClick = (modelId: string) => { const onModelActionClick = (modelId: string) => {
if (activeModel && activeModel.id === modelId) { if (activeModel && activeModel.id === modelId) {
stopModel(modelId) stopModel()
} else { } else {
startModel(modelId) startModel(modelId)
} }
@ -134,7 +134,7 @@ export default function RowModel(props: RowModelProps) {
className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary" className="flex cursor-pointer items-center space-x-2 px-4 py-2 hover:bg-secondary"
onClick={() => { onClick={() => {
setTimeout(async () => { setTimeout(async () => {
await stopModel(props.data.id) await stopModel()
deleteModel(props.data) deleteModel(props.data)
}, 500) }, 500)
setMore(false) setMore(false)

View File

@ -101,7 +101,7 @@ export default function SystemMonitorScreen() {
} }
className="w-16" className="w-16"
loading={stateModel.loading} loading={stateModel.loading}
onClick={() => stopModel(activeModel.id)} onClick={() => stopModel()}
> >
Stop Stop
</Button> </Button>