Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: button state reset on switching models #4356

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -11,8 +11,8 @@
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
import {
isGeneratingResponseAtom,

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'isGeneratingResponseAtom' is defined but never used

Check warning on line 14 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'isGeneratingResponseAtom' is defined but never used
resetThreadWaitingForResponseAtom,

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-macos

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

'resetThreadWaitingForResponseAtom' is defined but never used

Check warning on line 15 in web/hooks/useActiveModel.ts

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

'resetThreadWaitingForResponseAtom' is defined but never used
} from '@/helpers/atoms/Thread.atom'

export const activeModelAtom = atom<Model | undefined>(undefined)
Expand All @@ -38,10 +38,6 @@
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 @@
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 @@
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 {
activeThreadAtom,
engineParamsUpdateAtom,
resetGeneratingResponseAtom,
} from '@/helpers/atoms/Thread.atom'

type Props = {
Expand All @@ -24,6 +25,7 @@
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 @@
componentData.find((x) => x.key === key)?.requireModelReload ?? false
if (shouldReloadModel) {
setEngineParamsUpdate(true)
resetGenerating()
stopModel()
}

Expand Down Expand Up @@ -78,7 +81,7 @@
],
})
},
[

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-macos

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-ubuntu

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array

Check warning on line 84 in web/screens/Thread/ThreadCenterPanel/AssistantSetting/index.tsx

View workflow job for this annotation

GitHub Actions / test-on-windows-pr

React Hook useCallback has a missing dependency: 'resetGenerating'. Either include it or remove the dependency array
activeAssistant,
activeThread,
componentData,
Expand Down
Loading