Skip to content

Commit

Permalink
Merge pull request #4341 from janhq/fix/stop-button-state
Browse files Browse the repository at this point in the history
fix: send message button state reset on stop
  • Loading branch information
louis-jan authored Dec 26, 2024
2 parents 3cd4db0 + a720aff commit c77275a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
15 changes: 15 additions & 0 deletions web/helpers/atoms/Thread.atom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,21 @@ export const updateThreadWaitingForResponseAtom = atom(
}
)

/**
* Reset the thread waiting for response state
*/
export const resetThreadWaitingForResponseAtom = atom(null, (get, set) => {
const currentState = { ...get(threadStatesAtom) }
Object.keys(currentState).forEach((threadId) => {
currentState[threadId] = {
...currentState[threadId],
waitingForResponse: false,
error: undefined,
}
})
set(threadStatesAtom, currentState)
})

/**
* Update the thread last message
*/
Expand Down
19 changes: 18 additions & 1 deletion web/hooks/useActiveModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { LAST_USED_MODEL_ID } from './useRecommendedModel'
import { vulkanEnabledAtom } from '@/helpers/atoms/AppConfig.atom'
import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
import {
isGeneratingResponseAtom,
resetThreadWaitingForResponseAtom,
} from '@/helpers/atoms/Thread.atom'

export const activeModelAtom = atom<Model | undefined>(undefined)
export const loadModelErrorAtom = atom<string | undefined>(undefined)
Expand All @@ -34,6 +38,10 @@ 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 @@ -139,6 +147,8 @@ 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 @@ -148,7 +158,14 @@ export function useActiveModel() {
pendingModelLoad.current = false
})
},
[activeModel, setStateModel, setActiveModel, stateModel]
[
activeModel,
setStateModel,
setActiveModel,
stateModel,
setGeneratingResponse,
resetThreadWaitingForResponseState,
]
)

const stopInference = useCallback(async () => {
Expand Down
1 change: 1 addition & 0 deletions web/hooks/useDeleteThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default function useDeleteThread() {
if (thread) {
const updatedThread = {
...thread,
title: 'New Thread',
metadata: {
...thread.metadata,
title: 'New Thread',
Expand Down
4 changes: 1 addition & 3 deletions web/screens/Thread/ThreadCenterPanel/ChatInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ const ChatInput = () => {
</div>
)}

{messages[messages.length - 1]?.status !== MessageStatus.Pending &&
!isGeneratingResponse &&
!isStreamingResponse ? (
{!isGeneratingResponse && !isStreamingResponse ? (
<>
{currentPrompt.length !== 0 && (
<Button
Expand Down

0 comments on commit c77275a

Please sign in to comment.