mirror of
https://github.com/carlrobertoh/ProxyAI.git
synced 2026-05-11 04:50:31 +00:00
* Initial implementation of Ollama as a service * Fix model selector in tool window * Enable image attachment * Rewrite OllamaSettingsForm in Kt * Create OllamaInlineCompletionModel and use it for building completion template * Add support for blocking code completion on models that we don't know support it * Allow disabling code completion settings * Disable code completion settings when an unsupported model is entered * Track FIM template in settings as a derived state * Update llm-client * Initial implementation of model combo box * Add Ollama icon and display models as list * Make OllamaSettingsState immutable & convert OllamaSettings to Kotlin * Add refresh models button * Distinguish between empty/needs refresh/loading * Avoid storing any model if the combo box is empty * Fix icon size * Back to mutable settings There were some bugs with immutable settings * Store available models in settings state * Expose available models in model dropdown * Add dark icon * Cleanups for CompletionRequestProvider * Fix checkstyle issues * refactor: migrate to SimplePersistentStateComponent * fix: add code completion stop tokens * fix: display only one item in the model popup action group * fix: add back multi model selection --------- Co-authored-by: Carl-Robert Linnupuu <carlrobertoh@gmail.com>
177 lines
6.7 KiB
Java
177 lines
6.7 KiB
Java
package ee.carlrobert.codegpt.settings;
|
|
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.ANTHROPIC;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.AZURE;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.CUSTOM_OPENAI;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.LLAMA_CPP;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.OLLAMA;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.OPENAI;
|
|
import static ee.carlrobert.codegpt.settings.service.ServiceType.YOU;
|
|
|
|
import com.intellij.openapi.Disposable;
|
|
import com.intellij.openapi.ui.ComboBox;
|
|
import com.intellij.ui.components.JBTextField;
|
|
import com.intellij.util.ui.FormBuilder;
|
|
import ee.carlrobert.codegpt.CodeGPTBundle;
|
|
import ee.carlrobert.codegpt.settings.service.ServiceType;
|
|
import ee.carlrobert.codegpt.settings.service.anthropic.AnthropicSettings;
|
|
import ee.carlrobert.codegpt.settings.service.anthropic.AnthropicSettingsForm;
|
|
import ee.carlrobert.codegpt.settings.service.azure.AzureSettings;
|
|
import ee.carlrobert.codegpt.settings.service.azure.AzureSettingsForm;
|
|
import ee.carlrobert.codegpt.settings.service.custom.CustomServiceForm;
|
|
import ee.carlrobert.codegpt.settings.service.llama.LlamaSettings;
|
|
import ee.carlrobert.codegpt.settings.service.llama.form.LlamaSettingsForm;
|
|
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettings;
|
|
import ee.carlrobert.codegpt.settings.service.ollama.OllamaSettingsForm;
|
|
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettings;
|
|
import ee.carlrobert.codegpt.settings.service.openai.OpenAISettingsForm;
|
|
import ee.carlrobert.codegpt.settings.service.you.YouSettings;
|
|
import ee.carlrobert.codegpt.settings.service.you.YouSettingsForm;
|
|
import java.awt.CardLayout;
|
|
import java.awt.Component;
|
|
import java.awt.Container;
|
|
import java.awt.Dimension;
|
|
import java.awt.Insets;
|
|
import java.util.Arrays;
|
|
import javax.swing.DefaultComboBoxModel;
|
|
import javax.swing.JComponent;
|
|
import javax.swing.JPanel;
|
|
|
|
public class GeneralSettingsComponent {
|
|
|
|
private final JPanel mainPanel;
|
|
private final JBTextField displayNameField;
|
|
private final ComboBox<ServiceType> serviceComboBox;
|
|
private final OpenAISettingsForm openAISettingsForm;
|
|
private final CustomServiceForm customConfigurationSettingsForm;
|
|
private final AnthropicSettingsForm anthropicSettingsForm;
|
|
private final AzureSettingsForm azureSettingsForm;
|
|
private final YouSettingsForm youSettingsForm;
|
|
private final LlamaSettingsForm llamaSettingsForm;
|
|
private final OllamaSettingsForm ollamaSettingsForm;
|
|
|
|
public GeneralSettingsComponent(Disposable parentDisposable, GeneralSettings settings) {
|
|
displayNameField = new JBTextField(settings.getState().getDisplayName(), 20);
|
|
openAISettingsForm = new OpenAISettingsForm(OpenAISettings.getCurrentState());
|
|
customConfigurationSettingsForm = new CustomServiceForm();
|
|
anthropicSettingsForm = new AnthropicSettingsForm(AnthropicSettings.getCurrentState());
|
|
azureSettingsForm = new AzureSettingsForm(AzureSettings.getCurrentState());
|
|
youSettingsForm = new YouSettingsForm(YouSettings.getCurrentState(), parentDisposable);
|
|
llamaSettingsForm = new LlamaSettingsForm(LlamaSettings.getCurrentState());
|
|
ollamaSettingsForm = new OllamaSettingsForm();
|
|
|
|
var cardLayout = new DynamicCardLayout();
|
|
var cards = new JPanel(cardLayout);
|
|
cards.add(openAISettingsForm.getForm(), OPENAI.getCode());
|
|
cards.add(customConfigurationSettingsForm.getForm(), CUSTOM_OPENAI.getCode());
|
|
cards.add(anthropicSettingsForm.getForm(), ANTHROPIC.getCode());
|
|
cards.add(azureSettingsForm.getForm(), AZURE.getCode());
|
|
cards.add(youSettingsForm, YOU.getCode());
|
|
cards.add(llamaSettingsForm, LLAMA_CPP.getCode());
|
|
cards.add(ollamaSettingsForm.getForm(), OLLAMA.getCode());
|
|
var serviceComboBoxModel = new DefaultComboBoxModel<ServiceType>();
|
|
serviceComboBoxModel.addAll(Arrays.stream(ServiceType.values()).toList());
|
|
serviceComboBox = new ComboBox<>(serviceComboBoxModel);
|
|
serviceComboBox.setSelectedItem(OPENAI);
|
|
serviceComboBox.setPreferredSize(displayNameField.getPreferredSize());
|
|
serviceComboBox.addItemListener(e ->
|
|
cardLayout.show(cards, ((ServiceType) e.getItem()).getCode()));
|
|
mainPanel = FormBuilder.createFormBuilder()
|
|
.addLabeledComponent(
|
|
CodeGPTBundle.get("settingsConfigurable.displayName.label"),
|
|
displayNameField)
|
|
.addLabeledComponent(
|
|
CodeGPTBundle.get("settingsConfigurable.service.label"),
|
|
serviceComboBox)
|
|
.addComponent(cards)
|
|
.addComponentFillVertically(new JPanel(), 0)
|
|
.getPanel();
|
|
}
|
|
|
|
public OpenAISettingsForm getOpenAISettingsForm() {
|
|
return openAISettingsForm;
|
|
}
|
|
|
|
public CustomServiceForm getCustomConfigurationSettingsForm() {
|
|
return customConfigurationSettingsForm;
|
|
}
|
|
|
|
public AnthropicSettingsForm getAnthropicSettingsForm() {
|
|
return anthropicSettingsForm;
|
|
}
|
|
|
|
public AzureSettingsForm getAzureSettingsForm() {
|
|
return azureSettingsForm;
|
|
}
|
|
|
|
public LlamaSettingsForm getLlamaSettingsForm() {
|
|
return llamaSettingsForm;
|
|
}
|
|
|
|
public YouSettingsForm getYouSettingsForm() {
|
|
return youSettingsForm;
|
|
}
|
|
|
|
public OllamaSettingsForm getOllamaSettingsForm() {
|
|
return ollamaSettingsForm;
|
|
}
|
|
|
|
public ServiceType getSelectedService() {
|
|
return serviceComboBox.getItem();
|
|
}
|
|
|
|
public void setSelectedService(ServiceType serviceType) {
|
|
serviceComboBox.setSelectedItem(serviceType);
|
|
}
|
|
|
|
public JPanel getPanel() {
|
|
return mainPanel;
|
|
}
|
|
|
|
public JComponent getPreferredFocusedComponent() {
|
|
return displayNameField;
|
|
}
|
|
|
|
public String getDisplayName() {
|
|
return displayNameField.getText();
|
|
}
|
|
|
|
public void setDisplayName(String displayName) {
|
|
displayNameField.setText(displayName);
|
|
}
|
|
|
|
public void resetForms() {
|
|
openAISettingsForm.resetForm();
|
|
customConfigurationSettingsForm.resetForm();
|
|
anthropicSettingsForm.resetForm();
|
|
azureSettingsForm.resetForm();
|
|
youSettingsForm.resetForm();
|
|
llamaSettingsForm.resetForm();
|
|
ollamaSettingsForm.resetForm();
|
|
}
|
|
|
|
static class DynamicCardLayout extends CardLayout {
|
|
|
|
@Override
|
|
public Dimension preferredLayoutSize(Container parent) {
|
|
Component current = findVisibleComponent(parent);
|
|
if (current != null) {
|
|
Insets insets = parent.getInsets();
|
|
Dimension preferredSize = current.getPreferredSize();
|
|
preferredSize.width += insets.left + insets.right;
|
|
preferredSize.height += insets.top + insets.bottom;
|
|
return preferredSize;
|
|
}
|
|
return super.preferredLayoutSize(parent);
|
|
}
|
|
|
|
private Component findVisibleComponent(Container parent) {
|
|
for (Component comp : parent.getComponents()) {
|
|
if (comp.isVisible()) {
|
|
return comp;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
}
|