Skip to content

Commit ad04689

Browse files
committed
feat(clients): sort LLM client configurations by provider and name
1 parent 81e7665 commit ad04689

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Added
66

77
- Support for Azure OpenAI.
8+
- Sort LLM client configurations by provider name and configuration name.
89

910
## [2.4.1] - 2024-09-19
1011

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/LLMClientTable.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import javax.swing.table.DefaultTableCellRenderer
3131
import kotlin.math.max
3232

3333
class LLMClientTable {
34-
private var llmClients = AppSettings2.instance.llmClientConfigurations
34+
private var llmClients = fetchSortedLlmClients()
3535
private val tableModel = createTableModel()
3636

3737
val table = TableView(tableModel).apply {
@@ -60,33 +60,35 @@ class LLMClientTable {
6060
llmClients.toList()
6161
)
6262

63+
private fun fetchSortedLlmClients() = AppSettings2.instance.llmClientConfigurations.sortedWith(
64+
compareBy({ it.getClientName() }, { it.name })
65+
)
66+
67+
private fun updateLlmClients(newClients: List<LLMClientConfiguration>) {
68+
llmClients = newClients.sortedWith(compareBy({ it.getClientName() }, { it.name }))
69+
refreshTableModel()
70+
}
71+
6372
fun addLlmClient(): LLMClientConfiguration? {
6473
val dialog = LLMClientDialog()
65-
6674
if (dialog.showAndGet()) {
67-
llmClients = llmClients.plus(dialog.llmClient)
68-
refreshTableModel()
75+
updateLlmClients(llmClients + dialog.llmClient)
6976
return dialog.llmClient
7077
}
7178
return null
7279
}
7380

7481
fun removeLlmClient(): LLMClientConfiguration? {
7582
val selectedLlmClient = table.selectedObject ?: return null
76-
llmClients = llmClients.minus(selectedLlmClient)
77-
refreshTableModel()
83+
updateLlmClients(llmClients - selectedLlmClient)
7884
return selectedLlmClient
79-
8085
}
8186

8287
fun editLlmClient(): Pair<LLMClientConfiguration, LLMClientConfiguration>? {
8388
val selectedLlmClient = table.selectedObject ?: return null
8489
val dialog = LLMClientDialog(selectedLlmClient.clone())
85-
8690
if (dialog.showAndGet()) {
87-
llmClients = llmClients.minus(selectedLlmClient)
88-
llmClients = llmClients.plus(dialog.llmClient)
89-
refreshTableModel()
91+
updateLlmClients(llmClients - selectedLlmClient + dialog.llmClient)
9092
return selectedLlmClient to dialog.llmClient
9193
}
9294
return null
@@ -97,14 +99,14 @@ class LLMClientTable {
9799
}
98100

99101
fun reset() {
100-
llmClients = AppSettings2.instance.llmClientConfigurations
102+
llmClients = fetchSortedLlmClients()
101103
refreshTableModel()
102104
}
103105

104-
fun isModified() = llmClients != AppSettings2.instance.llmClientConfigurations
106+
fun isModified() = llmClients.toSet() != AppSettings2.instance.llmClientConfigurations
105107

106108
fun apply() {
107-
AppSettings2.instance.llmClientConfigurations = llmClients
109+
AppSettings2.instance.llmClientConfigurations = llmClients.toSet()
108110
}
109111

110112
private class LLMClientDialog(val newLlmClientConfiguration: LLMClientConfiguration? = null) : DialogWrapper(true) {

0 commit comments

Comments
 (0)