@@ -18,6 +18,8 @@ import cc.unitmesh.devti.llms.tokenizer.TokenizerFactory
18
18
import cc.unitmesh.devti.provider.RelatedClassesProvider
19
19
import cc.unitmesh.devti.settings.AutoDevSettingsState
20
20
import cc.unitmesh.devti.settings.customize.customizeSetting
21
+ import cc.unitmesh.devti.settings.model.LLMModelManager
22
+ import cc.unitmesh.devti.settings.ui.ModelItem
21
23
import cc.unitmesh.devti.util.AutoDevCoroutineScope
22
24
import cc.unitmesh.devti.util.parser.CodeFence
23
25
import com.intellij.codeInsight.lookup.LookupManagerListener
@@ -67,15 +69,18 @@ import javax.swing.*
67
69
import kotlin.math.max
68
70
import kotlin.math.min
69
71
70
- class AutoDevInputSection (private val project : Project , val disposable : Disposable ? , showAgent : Boolean = true ) :
71
- BorderLayoutPanel () {
72
+ class AutoDevInputSection (
73
+ private val project : Project ,
74
+ val disposable : Disposable ? ,
75
+ showAgent : Boolean = true
76
+ ) : BorderLayoutPanel() {
72
77
private val input: AutoDevInput
73
78
private val documentListener: DocumentListener
74
79
private val sendButtonPresentation: Presentation
75
80
private val stopButtonPresentation: Presentation
76
81
private val enhanceButtonPresentation: Presentation
77
82
private val sendButton: ActionButton
78
- private val modelLabel : JBLabel
83
+ private val modelSelector : JComboBox < ModelItem >
79
84
private val stopButton: ActionButton
80
85
private val enhanceButton: ActionButton
81
86
private var buttonPanel: JPanel = JPanel (CardLayout ())
@@ -121,9 +126,25 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
121
126
input = AutoDevInput (project, listOf (), disposable, this )
122
127
workspaceFilePanel = WorkspaceFilePanel (project)
123
128
124
- // Create a label to display the current model ID
125
- val modelId = AutoDevSettingsState .getInstance().defaultModelId.ifEmpty { " Default" }
126
- modelLabel = JBLabel (" Model: $modelId " ).apply { foreground = JBUI .CurrentTheme .Label .disabledForeground() }
129
+ // Create model selector
130
+ val modelItems = LLMModelManager .getInstance().getAllAvailableModels()
131
+ modelSelector = JComboBox (modelItems.toTypedArray())
132
+
133
+ val currentModel = AutoDevSettingsState .getInstance().defaultModelId.ifEmpty { " Default" }
134
+ val currentModelId = LLMModelManager .getInstance().getModelIdFromProvider(currentModel)
135
+ for (i in 0 until modelSelector.itemCount) {
136
+ val item = modelSelector.getItemAt(i)
137
+ if (item.modelId == currentModelId) {
138
+ modelSelector.selectedIndex = i
139
+ break
140
+ }
141
+ }
142
+
143
+ modelSelector.addActionListener {
144
+ val selected = modelSelector.selectedItem as ? ModelItem ? : return @addActionListener
145
+ val newProvider = LLMModelManager .getInstance().getProviderFromModelId(selected.modelId)
146
+ AutoDevSettingsState .getInstance().defaultModelId = newProvider
147
+ }
127
148
128
149
setupElementsList()
129
150
val sendButtonPresentation = Presentation (AutoDevBundle .message(" chat.panel.send" ))
@@ -202,13 +223,17 @@ class AutoDevInputSection(private val project: Project, val disposable: Disposab
202
223
203
224
input.minimumSize = Dimension (input.minimumSize.width, 64 )
204
225
layoutPanel.addToLeft(customAgent)
205
- // Add model label next to the custom agent dropdown
226
+ // Add model selector next to the custom agent dropdown
206
227
layoutPanel.addToLeft(Box .createHorizontalStrut(JBUI .scale(8 )))
207
- layoutPanel.addToLeft(modelLabel )
228
+ layoutPanel.addToLeft(modelSelector )
208
229
} else {
209
- layoutPanel.addToLeft(modelLabel )
230
+ layoutPanel.addToLeft(modelSelector )
210
231
}
211
232
233
+ // Set style for model selector
234
+ modelSelector.border = JBUI .Borders .empty(0 , 4 )
235
+ modelSelector.preferredSize = Dimension (200 , modelSelector.preferredSize.height)
236
+
212
237
buttonPanel = createButtonPanel()
213
238
214
239
layoutPanel.addToCenter(horizontalGlue)
0 commit comments