Skip to content

Commit

Permalink
fix: stop button is gone after switching to a new model (#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-jan authored Dec 30, 2024
1 parent 9b8d8ab commit 81ad90b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
8 changes: 8 additions & 0 deletions web/helpers/atoms/Thread.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,14 @@ export const resetThreadWaitingForResponseAtom = atom(null, (get, set) => {
set(threadStatesAtom, currentState)
})

/**
* Reset all generating states
**/
export const resetGeneratingResponseAtom = atom(null, (get, set) => {
set(resetThreadWaitingForResponseAtom)
set(isGeneratingResponseAtom, false)
})

/**
* Update the thread last message
*/
Expand Down
15 changes: 1 addition & 14 deletions web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ export function useActiveModel() {
const pendingModelLoad = useRef(false)
const isVulkanEnabled = useAtomValue(vulkanEnabledAtom)
const activeAssistant = useAtomValue(activeAssistantAtom)
const setGeneratingResponse = useSetAtom(isGeneratingResponseAtom)
const resetThreadWaitingForResponseState = useSetAtom(
resetThreadWaitingForResponseAtom
)

const downloadedModelsRef = useRef<Model[]>([])

Expand Down Expand Up @@ -147,8 +143,6 @@ export function useActiveModel() {
return

const engine = EngineManager.instance().get(stoppingModel.engine)
setGeneratingResponse(false)
resetThreadWaitingForResponseState()
return engine
?.unloadModel(stoppingModel)
.catch((e) => console.error(e))
Expand All @@ -158,14 +152,7 @@ export function useActiveModel() {
pendingModelLoad.current = false
})
},
[
activeModel,
setStateModel,
setActiveModel,
stateModel,
setGeneratingResponse,
resetThreadWaitingForResponseState,
]
[activeModel, setStateModel, setActiveModel, stateModel]
)

const stopInference = useCallback(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import {
activeThreadAtom,
engineParamsUpdateAtom,
resetGeneratingResponseAtom,
} from '@/helpers/atoms/Thread.atom'

type Props = {
Expand All @@ -24,6 +25,7 @@ const AssistantSetting: React.FC<Props> = ({ componentData }) => {
const { updateThreadMetadata } = useCreateNewThread()
const { stopModel } = useActiveModel()
const setEngineParamsUpdate = useSetAtom(engineParamsUpdateAtom)
const resetGenerating = useSetAtom(resetGeneratingResponseAtom)

const onValueChanged = useCallback(
(key: string, value: string | number | boolean | string[]) => {
Expand All @@ -32,6 +34,7 @@ const AssistantSetting: React.FC<Props> = ({ componentData }) => {
componentData.find((x) => x.key === key)?.requireModelReload ?? false
if (shouldReloadModel) {
setEngineParamsUpdate(true)
resetGenerating()
stopModel()
}

Expand Down

0 comments on commit 81ad90b

Please sign in to comment.