@@ -12,6 +12,7 @@ import { modelConfigSelectors, modelProviderSelectors } from '@/store/global/sel
12
12
import { GlobalLLMProviderKey } from '@/types/settings' ;
13
13
14
14
import ModelConfigModal from './ModelConfigModal' ;
15
+ import ModelFetcher from './ModelFetcher' ;
15
16
import OptionRender from './Option' ;
16
17
17
18
const styles = {
@@ -36,20 +37,24 @@ interface CustomModelSelectProps {
36
37
placeholder ?: string ;
37
38
provider : GlobalLLMProviderKey ;
38
39
showAzureDeployName ?: boolean ;
40
+ showModelFetcher ?: boolean ;
39
41
}
40
42
41
43
const ProviderModelListSelect = memo < CustomModelSelectProps > (
42
- ( { provider, showAzureDeployName, notFoundContent, placeholder } ) => {
44
+ ( { showModelFetcher = false , provider, showAzureDeployName, notFoundContent, placeholder } ) => {
43
45
const { t } = useTranslation ( 'common' ) ;
44
46
const { t : transSetting } = useTranslation ( 'setting' ) ;
45
- const chatModelCards = useGlobalStore (
46
- modelConfigSelectors . providerModelCards ( provider ) ,
47
- isEqual ,
48
- ) ;
49
47
const [ setModelProviderConfig , dispatchCustomModelCards ] = useGlobalStore ( ( s ) => [
50
48
s . setModelProviderConfig ,
51
49
s . dispatchCustomModelCards ,
50
+ s . useFetchProviderModelList ,
52
51
] ) ;
52
+
53
+ const chatModelCards = useGlobalStore (
54
+ modelConfigSelectors . providerModelCards ( provider ) ,
55
+ isEqual ,
56
+ ) ;
57
+
53
58
const defaultEnableModel = useGlobalStore (
54
59
modelProviderSelectors . defaultEnabledProviderModels ( provider ) ,
55
60
isEqual ,
@@ -58,72 +63,78 @@ const ProviderModelListSelect = memo<CustomModelSelectProps>(
58
63
modelConfigSelectors . providerEnableModels ( provider ) ,
59
64
isEqual ,
60
65
) ;
66
+
61
67
const showReset = ! ! enabledModels && ! isEqual ( defaultEnableModel , enabledModels ) ;
62
68
63
69
return (
64
- < div style = { { position : 'relative' } } >
65
- < div className = { cx ( styles . reset ) } >
66
- { showReset && (
67
- < ActionIcon
68
- icon = { RotateCwIcon }
69
- onClick = { ( ) => {
70
- setModelProviderConfig ( provider , { enabledModels : null } ) ;
71
- } }
72
- size = { 'small' }
73
- title = { t ( 'reset' ) }
74
- />
75
- ) }
76
- </ div >
77
- < Select < string [ ] >
78
- allowClear
79
- mode = "tags"
80
- notFoundContent = { notFoundContent }
81
- onChange = { ( value , options ) => {
82
- setModelProviderConfig ( provider , { enabledModels : value . filter ( Boolean ) } ) ;
70
+ < >
71
+ < Flexbox gap = { 8 } >
72
+ < div style = { { position : 'relative' } } >
73
+ < div className = { cx ( styles . reset ) } >
74
+ { showReset && (
75
+ < ActionIcon
76
+ icon = { RotateCwIcon }
77
+ onClick = { ( ) => {
78
+ setModelProviderConfig ( provider , { enabledModels : null } ) ;
79
+ } }
80
+ size = { 'small' }
81
+ title = { t ( 'reset' ) }
82
+ />
83
+ ) }
84
+ </ div >
85
+ < Select < string [ ] >
86
+ allowClear
87
+ mode = "tags"
88
+ notFoundContent = { notFoundContent }
89
+ onChange = { ( value , options ) => {
90
+ setModelProviderConfig ( provider , { enabledModels : value . filter ( Boolean ) } ) ;
83
91
84
- // if there is a new model, add it to `customModelCards`
85
- options . forEach ( ( option : { label ?: string ; value ?: string } , index : number ) => {
86
- // if is a known model, it should have value
87
- // if is an unknown model, the option will be {}
88
- if ( option . value ) return ;
92
+ // if there is a new model, add it to `customModelCards`
93
+ options . forEach ( ( option : { label ?: string ; value ?: string } , index : number ) => {
94
+ // if is a known model, it should have value
95
+ // if is an unknown model, the option will be {}
96
+ if ( option . value ) return ;
89
97
90
- const modelId = value [ index ] ;
98
+ const modelId = value [ index ] ;
91
99
92
- dispatchCustomModelCards ( provider , {
93
- modelCard : { id : modelId } ,
94
- type : 'add' ,
95
- } ) ;
96
- } ) ;
97
- } }
98
- optionFilterProp = "label"
99
- optionRender = { ( { label, value } ) => {
100
- // model is in the chatModels
101
- if ( chatModelCards . some ( ( c ) => c . id === value ) )
102
- return (
103
- < OptionRender
104
- displayName = { label as string }
105
- id = { value as string }
106
- provider = { provider }
107
- />
108
- ) ;
100
+ dispatchCustomModelCards ( provider , {
101
+ modelCard : { id : modelId } ,
102
+ type : 'add' ,
103
+ } ) ;
104
+ } ) ;
105
+ } }
106
+ optionFilterProp = "label"
107
+ optionRender = { ( { label, value } ) => {
108
+ // model is in the chatModels
109
+ if ( chatModelCards . some ( ( c ) => c . id === value ) )
110
+ return (
111
+ < OptionRender
112
+ displayName = { label as string }
113
+ id = { value as string }
114
+ provider = { provider }
115
+ />
116
+ ) ;
109
117
110
- // model is defined by user in client
111
- return (
112
- < Flexbox align = { 'center' } gap = { 8 } horizontal >
113
- { transSetting ( 'llm.customModelCards.addNew' , { id : value } ) }
114
- </ Flexbox >
115
- ) ;
116
- } }
117
- options = { chatModelCards . map ( ( model ) => ( {
118
- label : model . displayName || model . id ,
119
- value : model . id ,
120
- } ) ) }
121
- placeholder = { placeholder }
122
- popupClassName = { cx ( styles . popup ) }
123
- value = { enabledModels ?? defaultEnableModel }
124
- />
118
+ // model is defined by user in client
119
+ return (
120
+ < Flexbox align = { 'center' } gap = { 8 } horizontal >
121
+ { transSetting ( 'llm.customModelCards.addNew' , { id : value } ) }
122
+ </ Flexbox >
123
+ ) ;
124
+ } }
125
+ options = { chatModelCards . map ( ( model ) => ( {
126
+ label : model . displayName || model . id ,
127
+ value : model . id ,
128
+ } ) ) }
129
+ placeholder = { placeholder }
130
+ popupClassName = { cx ( styles . popup ) }
131
+ value = { enabledModels ?? defaultEnableModel }
132
+ />
133
+ </ div >
134
+ { showModelFetcher && < ModelFetcher provider = { provider } /> }
135
+ </ Flexbox >
125
136
< ModelConfigModal provider = { provider } showAzureDeployName = { showAzureDeployName } />
126
- </ div >
137
+ </ >
127
138
) ;
128
139
} ,
129
140
) ;
0 commit comments