@@ -78,43 +78,39 @@ const DropdownModelProvider = ({
7878 const [ searchValue , setSearchValue ] = useState ( '' )
7979 const searchInputRef = useRef < HTMLInputElement > ( null )
8080
81+ // Helper function to check if a model exists in providers
82+ const checkModelExists = useCallback ( ( providerName : string , modelId : string ) => {
83+ const provider = providers . find (
84+ ( p ) => p . provider === providerName && p . active
85+ )
86+ return provider ?. models . find ( ( m ) => m . id === modelId )
87+ } , [ providers ] )
88+
8189 // Initialize model provider only once
8290 useEffect ( ( ) => {
8391 // Auto select model when existing thread is passed
8492 if ( model ) {
8593 selectModelProvider ( model ?. provider as string , model ?. id as string )
94+ if ( ! checkModelExists ( model . provider , model . id ) ) {
95+ selectModelProvider ( '' , '' )
96+ }
8697 } else if ( useLastUsedModel ) {
8798 // Try to use last used model only when explicitly requested (for new chat)
8899 const lastUsed = getLastUsedModel ( )
89- if ( lastUsed ) {
90- // Verify the last used model still exists
91- const provider = providers . find (
92- ( p ) => p . provider === lastUsed . provider && p . active
93- )
94- const modelExists = provider ?. models . find (
95- ( m ) => m . id === lastUsed . model
96- )
97-
98- if ( provider && modelExists ) {
99- selectModelProvider ( lastUsed . provider , lastUsed . model )
100- } else {
101- // Fallback to default model if last used model no longer exists
102- selectModelProvider ( 'llamacpp' , 'llama3.2:3b' )
103- }
100+ if ( lastUsed && checkModelExists ( lastUsed . provider , lastUsed . model ) ) {
101+ selectModelProvider ( lastUsed . provider , lastUsed . model )
104102 } else {
105- // default model, we should add from setting
106- selectModelProvider ( 'llamacpp ' , 'llama3.2:3b ' )
103+ // Fallback to default model if last used model no longer exists
104+ selectModelProvider ( '' , '' )
107105 }
108- } else {
109- // default model for non-new-chat contexts
110- selectModelProvider ( 'llamacpp' , 'llama3.2:3b' )
111106 }
112107 } , [
113108 model ,
114109 selectModelProvider ,
115110 updateCurrentThreadModel ,
116111 providers ,
117112 useLastUsedModel ,
113+ checkModelExists ,
118114 ] )
119115
120116 // Update display model when selection changes
@@ -158,9 +154,11 @@ const DropdownModelProvider = ({
158154 provider &&
159155 predefinedProviders . some ( ( e ) =>
160156 e . provider . includes ( provider . provider )
161- ) && provider . provider !== 'llamacpp' && ! provider . api_key ?. length
157+ ) &&
158+ provider . provider !== 'llamacpp' &&
159+ ! provider . api_key ?. length
162160 )
163- return
161+ return
164162
165163 const capabilities = modelItem . capabilities || [ ]
166164 const capabilitiesString = capabilities . join ( ' ' )
0 commit comments