diff --git a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsComponent.kt b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsComponent.kt index 277323f..249ed76 100644 --- a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsComponent.kt +++ b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsComponent.kt @@ -36,14 +36,16 @@ class OllamaSettingsComponent { updateModelNames() } modelNameComboBox.isVisible = false + modelNameComboBox.addItemListener { event -> + if (event.stateChange == java.awt.event.ItemEvent.SELECTED) { + val selectedItem = event.item.toString() + println("Selected item: $selectedItem") + modelName = selectedItem + } + } refreshModelsButton.isEnabled = false promptText.margin = JBUI.insets(5) - val promptPanel: JPanel = UI.PanelFactory.panel(promptText).withComment("
Plugin is based on Ollama API. Please download" + - " Ollama firstly.
" + - "Parameters can be used in prompt:
" + - "{{fileChangeCount}}: number of changed files
" + - "{{gitDiff}}: changed code by git unified view
") + val promptPanel: JPanel = UI.PanelFactory.panel(promptText).withComment("Plugin is based on Ollama") .createPanel() panel = FormBuilder.createFormBuilder() .addLabeledComponent(JBLabel("Server URL:"), serverUrlText, 1, false) @@ -58,7 +60,7 @@ class OllamaSettingsComponent { .panel } - fun checkApiReachability() { + private fun checkApiReachability() { loadingLabel.text = "Checking API..." if(serverUrl.isNullOrEmpty()) { reachabilityStatusLabel.text = "API is not reachable, server URL is empty" @@ -66,23 +68,28 @@ class OllamaSettingsComponent { return } SwingUtilities.invokeLater { - val ollamaAPI = OllamaAPI(serverUrl) - if(!userName.isNullOrEmpty() && !password.isNullOrEmpty()) { - ollamaAPI.setBasicAuth(userName!!, password!!) - } - // Comment before deploying - ollamaAPI.setVerbose(true) - OllamaClientManager.setOllamaClient(ollamaAPI) - val isOllamaServerReachable = ollamaAPI.ping() - if (isOllamaServerReachable) { - reachabilityStatusLabel.text = "API is reachable" - refreshModelsButton.isEnabled = true - updateModelNames() - } else { + try { + val ollamaAPI = OllamaAPI(serverUrl) + if(!userName.isNullOrEmpty() && !password.isNullOrEmpty()) { + ollamaAPI.setBasicAuth(userName!!, password!!) + } + // Comment before deploying + ollamaAPI.setVerbose(true) + OllamaClientManager.setOllamaClient(ollamaAPI) + val isOllamaServerReachable = ollamaAPI.ping() + if (isOllamaServerReachable) { + reachabilityStatusLabel.text = "API is reachable" + refreshModelsButton.isEnabled = true + updateModelNames() + } else { + reachabilityStatusLabel.text = "API is not reachable" + refreshModelsButton.isEnabled = false + } + loadingLabel.text = "" + } catch (e: Exception){ + loadingLabel.text = "An error occurred: ${e.message}" reachabilityStatusLabel.text = "API is not reachable" - refreshModelsButton.isEnabled = false } - loadingLabel.text = "" } } @@ -109,12 +116,14 @@ class OllamaSettingsComponent { // Set the first model as selected if(modelNames.isNotEmpty()) { modelNameComboBox.isVisible = true - modelName = modelNames[0] + if(modelName.isNullOrEmpty()){ + modelName = modelNames[0] + } } else { modelNameComboBox.isVisible = false loadingModelsLabel.text = "No models found" } - loadingModelsLabel.text = "Models list successfully" + loadingModelsLabel.text = "Models fetched successfully" } val preferredFocusedComponent: JComponent @@ -145,7 +154,7 @@ class OllamaSettingsComponent { var modelName: String? get() = modelNameComboBox.item as String? ?: "" set(newText) { - modelNameComboBox.item = newText + modelNameComboBox.selectedItem = newText } @get:NotNull diff --git a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsConfigurable.kt b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsConfigurable.kt index e964592..12bef88 100644 --- a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsConfigurable.kt +++ b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsConfigurable.kt @@ -24,14 +24,14 @@ internal class OllamaSettingsConfigurable: Configurable { } override fun isModified(): Boolean { - val state: OllamaSettingsState.State = - Objects.requireNonNull(OllamaSettingsState.instance.state) - return !ollamaSettingsComponent.serverUrl.equals(state.serverUrl) || - !ollamaSettingsComponent.userName.equals(state.userName) || - !ollamaSettingsComponent.password.equals(state.password) || - !ollamaSettingsComponent.modelName.equals(state.modelName) || - !ollamaSettingsComponent.prompt.equals(state.prompt) - } + val state: OllamaSettingsState.State = + Objects.requireNonNull(OllamaSettingsState.instance.state) + return !ollamaSettingsComponent.serverUrl.equals(state.serverUrl) || + !ollamaSettingsComponent.userName.equals(state.userName) || + !ollamaSettingsComponent.password.equals(state.password) || + !ollamaSettingsComponent.modelName.equals(state.modelName) || + !ollamaSettingsComponent.prompt.equals(state.prompt) + } override fun apply() { val state: OllamaSettingsState.State = diff --git a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsState.kt b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsState.kt index edf41c1..da8af13 100644 --- a/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsState.kt +++ b/src/main/kotlin/me/itishermann/ollamacommitsummarizer/settings/OllamaSettingsState.kt @@ -19,7 +19,7 @@ internal class OllamaSettingsState var serverUrl: @NotNull @NonNls String? = "http://localhost:11434" var userName: @Nullable @NonNls String? = null var password: @Nullable @NonNls String? = null - var modelName: @NotNull @NonNls String? = "codegemma:2b" + var modelName: @NotNull @NonNls String? = null var prompt: @NotNull @NonNls String? = """ It is the code changes gives by unified view, changed file number is {{fileChangeCount}}: {{gitDiff}}