@@ -7,6 +7,7 @@ import { atom, useAtomValue } from 'jotai'
77import { activeModelAtom } from './useActiveModel'
88
99import { activeAssistantAtom } from '@/helpers/atoms/Assistant.atom'
10+ import { installedEnginesAtom } from '@/helpers/atoms/Engines.atom'
1011import { downloadedModelsAtom } from '@/helpers/atoms/Model.atom'
1112import { activeThreadAtom } from '@/helpers/atoms/Thread.atom'
1213
@@ -30,6 +31,7 @@ export default function useRecommendedModel() {
3031 const activeThread = useAtomValue ( activeThreadAtom )
3132 const downloadedModels = useAtomValue ( downloadedModelsAtom )
3233 const activeAssistant = useAtomValue ( activeAssistantAtom )
34+ const engines = useAtomValue ( installedEnginesAtom )
3335
3436 const getAndSortDownloadedModels = useCallback ( async ( ) : Promise < Model [ ] > => {
3537 const models = downloadedModels . sort ( ( a , b ) =>
@@ -45,7 +47,12 @@ export default function useRecommendedModel() {
4547 const getRecommendedModel = useCallback ( async ( ) : Promise <
4648 Model | undefined
4749 > => {
48- const models = await getAndSortDownloadedModels ( )
50+ const models = ( await getAndSortDownloadedModels ( ) ) . filter ( ( e : Model ) =>
51+ engines ?. [ e . engine ] ?. [ 0 ] . type === 'local' ||
52+ ( engines ?. [ e . engine ] ?. [ 0 ] . api_key ?. length ?? 0 ) > 0
53+ ? true
54+ : false
55+ )
4956
5057 if ( ! activeThread || ! activeAssistant ) return
5158 const modelId = activeAssistant . model . id
@@ -63,10 +70,8 @@ export default function useRecommendedModel() {
6370 }
6471
6572 // sort the model, for display purpose
66-
6773 if ( models . length === 0 ) {
6874 // if we have no downloaded models, then can't recommend anything
69- console . debug ( "No downloaded models, can't recommend anything" )
7075 setRecommendedModel ( undefined )
7176 return
7277 }
@@ -94,7 +99,7 @@ export default function useRecommendedModel() {
9499
95100 setRecommendedModel ( lastUsedModel )
96101 // eslint-disable-next-line react-hooks/exhaustive-deps
97- } , [ getAndSortDownloadedModels , activeThread ] )
102+ } , [ getAndSortDownloadedModels , activeThread , engines ] )
98103
99104 useEffect ( ( ) => {
100105 getRecommendedModel ( )
0 commit comments