Skip to content

Commit

Permalink
fix: deleting threads manually breaks model settings and document upl…
Browse files Browse the repository at this point in the history
…oad (janhq#2456)

* fix: blank model settings and rag does not work

* fix: fallback support fro previous broken threads
  • Loading branch information
louis-jan authored Mar 22, 2024
1 parent 8303f74 commit 5edc24d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions web/hooks/useSendChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,15 @@ export default function useSendChatMessage() {

let modelRequest =
selectedModelRef?.current ?? activeThreadRef.current.assistants[0].model

// Fallback support for previous broken threads
if (activeThreadRef.current?.assistants[0]?.model?.id === '*') {
activeThreadRef.current.assistants[0].model = {
id: modelRequest.id,
settings: modelRequest.settings,
parameters: modelRequest.parameters,
}
}
if (runtimeParams.stream == null) {
runtimeParams.stream = true
}
Expand Down
14 changes: 12 additions & 2 deletions web/screens/Chat/ThreadList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { GalleryHorizontalEndIcon, MoreVerticalIcon } from 'lucide-react'
import { twMerge } from 'tailwind-merge'

import { useCreateNewThread } from '@/hooks/useCreateNewThread'
import useRecommendedModel from '@/hooks/useRecommendedModel'
import useSetActiveThread from '@/hooks/useSetActiveThread'

import { displayDate } from '@/utils/datetime'
Expand All @@ -35,6 +36,7 @@ export default function ThreadList() {
const threadDataReady = useAtomValue(threadDataReadyAtom)
const { requestCreateNewThread } = useCreateNewThread()
const setEditMessage = useSetAtom(editMessageAtom)
const { recommendedModel, downloadedModels } = useRecommendedModel()

const onThreadClick = useCallback(
(thread: Thread) => {
Expand All @@ -50,8 +52,14 @@ export default function ThreadList() {
* and there are no threads available
*/
useEffect(() => {
if (threadDataReady && assistants.length > 0 && threads.length === 0) {
requestCreateNewThread(assistants[0])
if (
threadDataReady &&
assistants.length > 0 &&
threads.length === 0 &&
(recommendedModel || downloadedModels[0])
) {
const model = recommendedModel || downloadedModels[0]
requestCreateNewThread(assistants[0], model)
} else if (threadDataReady && !activeThreadId) {
setActiveThread(threads[0])
}
Expand All @@ -62,6 +70,8 @@ export default function ThreadList() {
requestCreateNewThread,
activeThreadId,
setActiveThread,
recommendedModel,
downloadedModels,
])

return (
Expand Down

0 comments on commit 5edc24d

Please sign in to comment.