chore: attempt to stop model before switching engine variant

This commit is contained in:
Louis 2025-01-16 16:18:32 +07:00
parent 687b034b06
commit 713926e68c
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2
2 changed files with 5 additions and 12 deletions

View File

@ -71,18 +71,6 @@ function dispose() {
watchdog?.terminate()
}
function addEnvPaths(dest: string) {
// Add engine path to the PATH and LD_LIBRARY_PATH
if (process.platform === 'win32') {
process.env.PATH = (process.env.PATH || '').concat(path.delimiter, dest)
} else {
process.env.LD_LIBRARY_PATH = (process.env.LD_LIBRARY_PATH || '').concat(
path.delimiter,
dest
)
}
}
/**
* Cortex process info
*/

View File

@ -26,6 +26,7 @@ import { formatDownloadPercentage } from '@/utils/converter'
import ExtensionSetting from '../ExtensionSetting'
import DeleteEngineVariant from './DeleteEngineVariant'
import { useActiveModel } from '@/hooks/useActiveModel'
const os = () => {
switch (PLATFORM) {
case 'win32':
@ -52,6 +53,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
const [installingEngines, setInstallingEngines] = useState<
Map<string, number>
>(new Map())
const { stopModel } = useActiveModel()
const isEngineUpdated =
latestReleasedEngine &&
@ -104,6 +106,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
const handleEngineUpdate = useCallback(
(event: { id: string; type: DownloadEvent; percent: number }) => {
stopModel()
mutateInstalledEngines()
mutateDefaultEngineVariant()
// Backward compatible support - cortex.cpp returns full variant file name
@ -138,6 +141,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
})
},
[
stopModel,
mutateDefaultEngineVariant,
mutateInstalledEngines,
setInstallingEngines,
@ -153,6 +157,7 @@ const LocalEngineSettings = ({ engine }: { engine: InferenceEngine }) => {
}, [handleEngineUpdate])
const handleChangeVariant = (e: string) => {
stopModel()
setSelectedVariants(e)
setDefaultEngineVariant(engine, {
variant: e,