From 501d52245fe35865ceaf70814f243101e86023ee Mon Sep 17 00:00:00 2001 From: NEO Date: Fri, 19 Jul 2024 08:11:03 +0800 Subject: [PATCH] fix: ollama settings sync (#617) * fix: Updated Ollama settings to sort models and add available models. 1) sort ollama models list when select the model from settings 2) fix: settings of cached ollama models need update 3) sort cached ollama models * remove code comments * remove code comments --------- Co-authored-by: neo --- .../service/ollama/OllamaSettingsForm.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/kotlin/ee/carlrobert/codegpt/settings/service/ollama/OllamaSettingsForm.kt b/src/main/kotlin/ee/carlrobert/codegpt/settings/service/ollama/OllamaSettingsForm.kt index 348e3046..b2e3b533 100644 --- a/src/main/kotlin/ee/carlrobert/codegpt/settings/service/ollama/OllamaSettingsForm.kt +++ b/src/main/kotlin/ee/carlrobert/codegpt/settings/service/ollama/OllamaSettingsForm.kt @@ -1,6 +1,7 @@ package ee.carlrobert.codegpt.settings.service.ollama import com.intellij.notification.NotificationType +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.ReadAction import com.intellij.openapi.components.service @@ -155,6 +156,9 @@ class OllamaSettingsForm { .modelTags .models .map { it.name } + .sortedWith(compareBy({ it.split(":").first() }, { + if (it.contains("latest")) 1 else 0 + })) } catch (t: Throwable) { handleModelLoadingError(t) throw t @@ -187,6 +191,20 @@ class OllamaSettingsForm { } else { modelComboBox.model = DefaultComboBoxModel(arrayOf("No models")) } + val availableModels = ApplicationManager.getApplication() + .getService(OllamaSettings::class.java) + .state.availableModels + availableModels.removeAll { !models.contains(it) } + models.forEach { model -> + if (!availableModels.contains(model)) { + availableModels.add(model) + } + } + availableModels.sortWith( + compareBy({ it.split(":").first() }, { + if (it.contains("latest")) 1 else 0 + }) + ) } private fun handleModelLoadingError(ex: Throwable) {