diff --git a/src/main/java/com/devoxx/genie/chatmodel/anthropic/AnthropicChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/anthropic/AnthropicChatModelFactory.java index bf042499..b8a314e0 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/anthropic/AnthropicChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/anthropic/AnthropicChatModelFactory.java @@ -40,7 +40,7 @@ public StreamingChatLanguageModel createStreamingChatModel(@NotNull ChatModel ch @Override public String getApiKey() { - return SettingsStateService.getInstance().getAnthropicKey(); + return SettingsStateService.getInstance().getAnthropicKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/chatmodel/deepinfra/DeepInfraChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/deepinfra/DeepInfraChatModelFactory.java index 8b62a06d..db2e64db 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/deepinfra/DeepInfraChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/deepinfra/DeepInfraChatModelFactory.java @@ -42,7 +42,7 @@ public StreamingChatLanguageModel createStreamingChatModel(@NotNull ChatModel ch @Override public String getApiKey() { - return SettingsStateService.getInstance().getDeepInfraKey(); + return SettingsStateService.getInstance().getDeepInfraKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/chatmodel/gemini/GeminiChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/gemini/GeminiChatModelFactory.java index b8d36016..9295d8a1 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/gemini/GeminiChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/gemini/GeminiChatModelFactory.java @@ -26,7 +26,7 @@ public ChatLanguageModel createChatModel(@NotNull ChatModel chatModel) { @Override public String getApiKey() { - return SettingsStateService.getInstance().getGeminiKey(); + return SettingsStateService.getInstance().getGeminiKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/chatmodel/groq/GroqChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/groq/GroqChatModelFactory.java index 0a5af833..ad0cc46a 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/groq/GroqChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/groq/GroqChatModelFactory.java @@ -42,7 +42,7 @@ public ChatLanguageModel createChatModel(@NotNull ChatModel chatModel) { @Override public String getApiKey() { - return SettingsStateService.getInstance().getGroqKey(); + return SettingsStateService.getInstance().getGroqKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/chatmodel/mistral/MistralChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/mistral/MistralChatModelFactory.java index c59de930..e772eba2 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/mistral/MistralChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/mistral/MistralChatModelFactory.java @@ -42,7 +42,7 @@ public StreamingChatLanguageModel createStreamingChatModel(@NotNull ChatModel ch @Override public String getApiKey() { - return SettingsStateService.getInstance().getMistralKey(); + return SettingsStateService.getInstance().getMistralKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/chatmodel/openai/OpenAIChatModelFactory.java b/src/main/java/com/devoxx/genie/chatmodel/openai/OpenAIChatModelFactory.java index 1fe884e9..d20b0650 100644 --- a/src/main/java/com/devoxx/genie/chatmodel/openai/OpenAIChatModelFactory.java +++ b/src/main/java/com/devoxx/genie/chatmodel/openai/OpenAIChatModelFactory.java @@ -41,7 +41,7 @@ public StreamingChatLanguageModel createStreamingChatModel(@NotNull ChatModel ch @Override public String getApiKey() { - return SettingsStateService.getInstance().getOpenAIKey(); + return SettingsStateService.getInstance().getOpenAIKey().trim(); } @Override diff --git a/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java b/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java index a016c2c3..d66998b4 100644 --- a/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java +++ b/src/main/java/com/devoxx/genie/ui/DevoxxGenieSettingsManager.java @@ -9,6 +9,7 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectManager; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.messages.MessageBus; import com.intellij.util.ui.JBUI; import org.jetbrains.annotations.Nls; @@ -63,10 +64,11 @@ public class DevoxxGenieSettingsManager implements Configurable { private JCheckBox astReferenceFieldCheckBox; private JCheckBox astReferenceClassesCheckBox; - private JTextField testPromptField; - private JTextField explainPromptField; - private JTextField reviewPromptField; - private JTextField customPromptField; + private JTextArea testPromptField; + private JTextArea explainPromptField; + private JTextArea reviewPromptField; + private JTextArea customPromptField; + private JTextField maxOutputTokensField; public DevoxxGenieSettingsManager() { @@ -147,10 +149,10 @@ public JComponent createComponent() { setTitle("Predefined Command Prompts", settingsPanel, gbc); - testPromptField = addTextFieldWithLabel(settingsPanel, gbc, "Test prompt :", settings.getTestPrompt()); - explainPromptField = addTextFieldWithLabel(settingsPanel, gbc, "Explain prompt :", settings.getExplainPrompt()); - reviewPromptField = addTextFieldWithLabel(settingsPanel, gbc, "Review prompt :", settings.getReviewPrompt()); - customPromptField = addTextFieldWithLabel(settingsPanel, gbc, "Custom prompt :", settings.getCustomPrompt()); + testPromptField = addTextAreaWithLabel(settingsPanel, gbc, "Test prompt :", settings.getTestPrompt()); + explainPromptField = addTextAreaWithLabel(settingsPanel, gbc, "Explain prompt :", settings.getExplainPrompt()); + reviewPromptField = addTextAreaWithLabel(settingsPanel, gbc, "Review prompt :", settings.getReviewPrompt()); + customPromptField = addTextAreaWithLabel(settingsPanel, gbc, "Custom prompt :", settings.getCustomPrompt()); return settingsPanel; } @@ -183,7 +185,6 @@ private void setTitle(String title, /** * Add a text field with label - * * @param panel the panel * @param gbc the gridbag constraints * @param label the label @@ -202,6 +203,26 @@ private void setTitle(String title, return textField; } + /** + * Add a text area with label + * @param panel the panel + * @param gbc the gridbag constraints + * @param label the label + * @param value the value + * @return the text field + */ + private @NotNull JTextArea addTextAreaWithLabel(@NotNull JPanel panel, + GridBagConstraints gbc, + String label, + String value) { + panel.add(new JLabel(label), gbc); + gbc.gridx++; + JTextArea textArea = new JTextArea(value, 3, 80); + panel.add(textArea, gbc); + resetGbc(gbc); + return textArea; + } + /** * Add a field with label and a link button * @@ -369,10 +390,13 @@ public boolean isModified() { isModified |= isFieldModified(maxOutputTokensField, settings.getMaxOutputTokens()); isModified |= isFieldModified(retryField, settings.getMaxRetries()); isModified |= isFieldModified(chatMemorySizeField, settings.getChatMemorySize()); - isModified |= isFieldModified(testPromptField, settings.getTestPrompt()); - isModified |= isFieldModified(explainPromptField, settings.getExplainPrompt()); - isModified |= isFieldModified(reviewPromptField, settings.getReviewPrompt()); - isModified |= isFieldModified(customPromptField, settings.getCustomPrompt()); + + isModified |= !StringUtil.equals(testPromptField.getText(), settings.getTestPrompt()); + isModified |= !StringUtil.equals(explainPromptField.getText(), settings.getExplainPrompt()); + isModified |= !StringUtil.equals(reviewPromptField.getText(), settings.getReviewPrompt()); + + isModified |= !StringUtil.equals(customPromptField.getText(), settings.getCustomPrompt()); + isModified |= isFieldModified(openAiKeyField, settings.getOpenAIKey()); isModified |= isFieldModified(mistralKeyField, settings.getMistralKey()); isModified |= isFieldModified(anthropicKeyField, settings.getAnthropicKey()); @@ -430,10 +454,12 @@ public void apply() { updateSettingIfModified(timeoutField, settings.getTimeout(), value -> settings.setTimeout(safeCastToInteger(value))); updateSettingIfModified(retryField, settings.getMaxRetries(), value -> settings.setMaxRetries(safeCastToInteger(value))); updateSettingIfModified(maxOutputTokensField, settings.getMaxOutputTokens(), settings::setMaxOutputTokens); - updateSettingIfModified(testPromptField, settings.getTestPrompt(), settings::setTestPrompt); - updateSettingIfModified(explainPromptField, settings.getExplainPrompt(), settings::setExplainPrompt); - updateSettingIfModified(reviewPromptField, settings.getReviewPrompt(), settings::setReviewPrompt); - updateSettingIfModified(customPromptField, settings.getCustomPrompt(), settings::setCustomPrompt); + + updateTextAreaIfModified(testPromptField, settings.getTestPrompt(), settings::setTestPrompt); + updateTextAreaIfModified(explainPromptField, settings.getExplainPrompt(), settings::setExplainPrompt); + updateTextAreaIfModified(reviewPromptField, settings.getReviewPrompt(), settings::setReviewPrompt); + updateTextAreaIfModified(customPromptField, settings.getCustomPrompt(), settings::setCustomPrompt); + updateSettingIfModified(streamModeCheckBox, settings.getStreamMode(), value -> settings.setStreamMode(Boolean.parseBoolean(value))); updateSettingIfModified(astModeCheckBox, settings.getAstMode(), value -> settings.setAstMode(Boolean.parseBoolean(value))); @@ -447,6 +473,21 @@ public void apply() { } } + /** + * Update the text area if the value has changed + * @param textArea the text area + * @param currentValue the current value + * @param updateAction the update action + */ + public void updateTextAreaIfModified(@NotNull JTextArea textArea, + Object currentValue, + Consumer updateAction) { + String newValue = textArea.getText(); + if (newValue != null && !newValue.equals(currentValue)) { + updateAction.accept(newValue); + } + } + /** * Update the setting if the field value has changed * @param field the field