Skip to content

Commit 81ad90b

Browse files
authored
fix: stop button is gone after switching to a new model (#4356)
1 parent 9b8d8ab commit 81ad90b

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

web/helpers/atoms/Thread.atom.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,14 @@ export const resetThreadWaitingForResponseAtom = atom(null, (get, set) => {
204204
set(threadStatesAtom, currentState)
205205
})
206206

207+
/**
208+
* Reset all generating states
209+
**/
210+
export const resetGeneratingResponseAtom = atom(null, (get, set) => {
211+
set(resetThreadWaitingForResponseAtom)
212+
set(isGeneratingResponseAtom, false)
213+
})
214+
207215
/**
208216
* Update the thread last message
209217
*/

web/hooks/useActiveModel.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ export function useActiveModel() {
3838
const pendingModelLoad = useRef(false)
3939
const isVulkanEnabled = useAtomValue(vulkanEnabledAtom)
4040
const activeAssistant = useAtomValue(activeAssistantAtom)
41-
const setGeneratingResponse = useSetAtom(isGeneratingResponseAtom)
42-
const resetThreadWaitingForResponseState = useSetAtom(
43-
resetThreadWaitingForResponseAtom
44-
)
4541

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

@@ -147,8 +143,6 @@ export function useActiveModel() {
147143
return
148144

149145
const engine = EngineManager.instance().get(stoppingModel.engine)
150-
setGeneratingResponse(false)
151-
resetThreadWaitingForResponseState()
152146
return engine
153147
?.unloadModel(stoppingModel)
154148
.catch((e) => console.error(e))
@@ -158,14 +152,7 @@ export function useActiveModel() {
158152
pendingModelLoad.current = false
159153
})
160154
},
161-
[
162-
activeModel,
163-
setStateModel,
164-
setActiveModel,
165-
stateModel,
166-
setGeneratingResponse,
167-
resetThreadWaitingForResponseState,
168-
]
155+
[activeModel, setStateModel, setActiveModel, stateModel]
169156
)
170157

171158
const stopInference = useCallback(async () => {

web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
1212
import {
1313
activeThreadAtom,
1414
engineParamsUpdateAtom,
15+
resetGeneratingResponseAtom,
1516
} from '@/helpers/atoms/Thread.atom'
1617

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

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

0 commit comments

Comments
 (0)