feat: extract providers into their standalone configurables (#538)

* fix: extract services to their own configurables

* feat: switch to selected provider automatically upon apply

* fix: credentials loading at once

* fix: rename llama.cpp title
This commit is contained in:
Carl-Robert 2024-05-09 11:16:09 +03:00 committed by GitHub
parent 0852c27170
commit 7bee59a90e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
36 changed files with 579 additions and 418 deletions

View file

@ -0,0 +1,72 @@
package ee.carlrobert.codegpt.settings.service
import com.intellij.ide.DataManager
import com.intellij.openapi.components.service
import com.intellij.openapi.options.ex.Settings
import com.intellij.openapi.ui.ComboBox
import com.intellij.ui.EnumComboBoxModel
import com.intellij.ui.components.ActionLink
import com.intellij.ui.components.JBLabel
import com.intellij.util.ui.FormBuilder
import ee.carlrobert.codegpt.CodeGPTBundle
import ee.carlrobert.codegpt.settings.GeneralSettings
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceConfigurable
import ee.carlrobert.codegpt.settings.service.codegpt.CodeGPTServiceForm
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceConfigurable
import ee.carlrobert.codegpt.settings.service.google.GoogleSettingsConfigurable
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettingsConfigurable
import javax.swing.JPanel
class ServiceConfigurableComponent {
var form: CodeGPTServiceForm = CodeGPTServiceForm()
private var serviceComboBox: ComboBox<ServiceType> =
ComboBox(EnumComboBoxModel(ServiceType::class.java)).apply {
selectedItem = service<GeneralSettings>().state.selectedService
}
fun getSelectedService(): ServiceType {
return serviceComboBox.item
}
fun setSelectedService(serviceType: ServiceType?) {
serviceComboBox.selectedItem = serviceType
}
fun getPanel(): JPanel = FormBuilder.createFormBuilder()
.addLabeledComponent(
CodeGPTBundle.get("settingsConfigurable.service.label"),
serviceComboBox
)
.addVerticalGap(8)
.addComponent(JBLabel("All available providers that can be used with CodeGPT:"))
.addVerticalGap(8)
.addComponent(FormBuilder.createFormBuilder()
.setFormLeftIndent(16).apply {
addLinks(this)
}
.panel)
.addComponentFillVertically(JPanel(), 0)
.panel
private fun addLinks(formBuilder: FormBuilder) {
mapOf(
"CodeGPT" to CodeGPTServiceConfigurable::class.java,
"OpenAI" to OpenAIServiceConfigurable::class.java,
"Custom OpenAI" to CustomServiceConfigurable::class.java,
"Azure" to AzureServiceConfigurable::class.java,
"Anthropic" to AnthropicServiceConfigurable::class.java,
"Google" to GoogleSettingsConfigurable::class.java,
"You.com" to YouServiceConfigurable::class.java,
"LLaMA C/C++ (Local)" to LlamaServiceConfigurable::class.java,
"Ollama (Local)" to OllamaSettingsConfigurable::class.java,
).entries.forEach { (name, configurableClass) ->
formBuilder.addComponent(ActionLink(name) {
val context = service<DataManager>().getDataContext(it.source as ActionLink)
val settings = Settings.KEY.getData(context)
settings?.select(settings.find(configurableClass))
})
}
}
}