fix: app does not gracefully stop a model (#2593)

This commit is contained in:
Louis 2024-04-03 22:22:43 +07:00 committed by GitHub
parent 402f85f179
commit d579d8a45c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 3 deletions

View File

@ -149,7 +149,7 @@ export const stopServer = async () => {
// Log server stop
if (isVerbose) logServer(`Debug: Server stopped`)
// Stop the server
await server.close()
await server?.close()
} catch (e) {
// Log any errors
if (isVerbose) logServer(`Error: ${e}`)

View File

@ -115,7 +115,8 @@ export function useActiveModel() {
}
const stopModel = useCallback(async () => {
if (!activeModel) return
if (!activeModel || (stateModel.state === 'stop' && stateModel.loading))
return
setStateModel({ state: 'stop', loading: true, model: activeModel.id })
const engine = EngineManager.instance().get(activeModel.engine)
@ -126,7 +127,7 @@ export function useActiveModel() {
setActiveModel(undefined)
setStateModel({ state: 'start', loading: false, model: '' })
})
}, [activeModel, setActiveModel, setStateModel])
}, [activeModel, stateModel, setActiveModel, setStateModel])
return { activeModel, startModel, stopModel, stateModel }
}