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: app picks model automatically edge cases #4322

Merged
merged 1 commit into from
Dec 23, 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
5 changes: 1 addition & 4 deletions web/containers/ModelDropdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,14 @@

const handleChangeStateOpen = useCallback(
(state: boolean) => {
setOpen(state)
setModelDropdownState(state)

Check warning on line 120 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

119-120 lines are not covered with tests
},
[setModelDropdownState]
)

const isModelSupportRagAndTools = useCallback((model: Model) => {
return (

Check warning on line 126 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

126 line is not covered with tests
model?.engine === InferenceEngine.openai ||
isLocalEngine(model?.engine as InferenceEngine)
)
Expand All @@ -134,7 +134,7 @@
configuredModels
.concat(
downloadedModels.filter(
(e) => !configuredModels.some((x) => x.id === e.id)

Check warning on line 137 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

137 line is not covered with tests
)
)
.filter((e) =>
Expand All @@ -144,24 +144,24 @@
if (searchFilter === 'local') {
return isLocalEngine(e.engine)
}
if (searchFilter === 'remote') {
return !isLocalEngine(e.engine)

Check warning on line 148 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

147-148 lines are not covered with tests
}
})
.sort((a, b) => a.name.localeCompare(b.name))

Check warning on line 151 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

151 line is not covered with tests
.sort((a, b) => {
const aInDownloadedModels = downloadedModels.some(
(item) => item.id === a.id

Check warning on line 154 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

153-154 lines are not covered with tests
)
const bInDownloadedModels = downloadedModels.some(
(item) => item.id === b.id

Check warning on line 157 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

156-157 lines are not covered with tests
)
if (aInDownloadedModels && !bInDownloadedModels) {
return -1
} else if (!aInDownloadedModels && bInDownloadedModels) {
return 1

Check warning on line 162 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

159-162 lines are not covered with tests
} else {
return 0

Check warning on line 164 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

164 line is not covered with tests
}
}),
[configuredModels, searchText, searchFilter, downloadedModels]
Expand All @@ -183,10 +183,7 @@
if (!activeThread) return
const modelId = activeAssistant?.model?.id

let model = downloadedModels.find((model) => model.id === modelId)
if (!model) {
model = undefined
}
const model = downloadedModels.find((model) => model.id === modelId)
setSelectedModel(model)
}, [
recommendedModel,
Expand All @@ -198,10 +195,10 @@

const onClickModelItem = useCallback(
async (modelId: string) => {
if (!activeAssistant) return
const model = downloadedModels.find((m) => m.id === modelId)
setSelectedModel(model)
setOpen(false)

Check warning on line 201 in web/containers/ModelDropdown/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

198-201 lines are not covered with tests

if (activeThread) {
// Change assistand tools based on model support RAG
Expand Down
5 changes: 4 additions & 1 deletion web/hooks/useDeleteThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { currentPromptAtom } from '@/containers/Providers/Jotai'

import { toaster } from '@/containers/Toast'

import useSetActiveThread from './useSetActiveThread'

import { extensionManager } from '@/extension/ExtensionManager'

import { deleteChatMessageAtom as deleteChatMessagesAtom } from '@/helpers/atoms/ChatMessage.atom'
Expand All @@ -27,6 +29,7 @@ export default function useDeleteThread() {
const deleteMessages = useSetAtom(deleteChatMessagesAtom)

const deleteThreadState = useSetAtom(deleteThreadStateAtom)
const { setActiveThread } = useSetActiveThread()

const cleanThread = useCallback(
async (threadId: string) => {
Expand Down Expand Up @@ -86,7 +89,7 @@ export default function useDeleteThread() {
type: 'success',
})
if (availableThreads.length > 0) {
setActiveThreadId(availableThreads[0].id)
setActiveThread(availableThreads[0])
} else {
setActiveThreadId(undefined)
}
Expand Down
5 changes: 1 addition & 4 deletions web/screens/Thread/ThreadRightPanel/Tools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,9 @@ const Tools = () => {

useEffect(() => {
if (!activeThread) return
let model = downloadedModels.find(
const model = downloadedModels.find(
(model) => model.id === activeAssistant?.model.id
)
if (!model) {
model = recommendedModel
}
setSelectedModel(model)
}, [
recommendedModel,
Expand Down
Loading