diff --git a/src/main/java/io/github/jeddict/ai/JeddictChatModel.java b/src/main/java/io/github/jeddict/ai/JeddictChatModel.java index 596b338..0e9b1f6 100644 --- a/src/main/java/io/github/jeddict/ai/JeddictChatModel.java +++ b/src/main/java/io/github/jeddict/ai/JeddictChatModel.java @@ -34,6 +34,7 @@ import static io.github.jeddict.ai.settings.GenAIProvider.ANTHROPIC; import static io.github.jeddict.ai.settings.GenAIProvider.OLLAMA; import io.github.jeddict.ai.models.LMStudioChatModel; +import static io.github.jeddict.ai.settings.GenAIProvider.DEEPINFRA; import static io.github.jeddict.ai.settings.GenAIProvider.LM_STUDIO; import static io.github.jeddict.ai.settings.GenAIProvider.OPEN_AI; import io.github.jeddict.ai.settings.PreferencesManager; @@ -70,7 +71,12 @@ public JeddictChatModel() { .modelName(preferencesManager.getModelName()) .build(); case DEEPINFRA -> model = OpenAiChatModel.builder() - .baseUrl("https://api.deepinfra.com/v1/openai") + .baseUrl(preferencesManager.getProviderLocation()) + .apiKey(preferencesManager.getApiKey()) + .modelName(preferencesManager.getModelName()) + .build(); + case CUSTOM_OPEN_AI -> model = OpenAiChatModel.builder() + .baseUrl(preferencesManager.getProviderLocation()) .apiKey(preferencesManager.getApiKey()) .modelName(preferencesManager.getModelName()) .build(); diff --git a/src/main/java/io/github/jeddict/ai/models/Constant.java b/src/main/java/io/github/jeddict/ai/models/Constant.java new file mode 100644 index 0000000..e2b1dd2 --- /dev/null +++ b/src/main/java/io/github/jeddict/ai/models/Constant.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.github.jeddict.ai.models; + +/** + * + * @author Shiwani Gupta + */ +public interface Constant { + + String DEEPINFRA_URL = "https://api.deepinfra.com/v1/openai"; +} diff --git a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form index 84c20e5..1409dae 100644 --- a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form +++ b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.form @@ -37,18 +37,12 @@ - - - - + - - - - + @@ -60,7 +54,7 @@ - + @@ -99,6 +93,7 @@ + @@ -127,13 +122,9 @@ - + - - - - - + @@ -167,50 +158,81 @@ - + - + + + + + + + + - + - + + + - - + + + + + + + + + + - + - + - + + - + + + + + + + + - + + + - - - - + + + + + + + + @@ -219,6 +241,29 @@ + + + + + + + + + + + + + + + + + + + + + + + @@ -236,64 +281,50 @@ + + + + + + + + - + - - - + + - + - - + + - - + + + + + + + + + - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -333,19 +364,6 @@ - - - - - - - - - - - - - diff --git a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java index c82573b..0932f53 100644 --- a/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java +++ b/src/main/java/io/github/jeddict/ai/settings/AIAssistancePanel.java @@ -18,6 +18,7 @@ */ package io.github.jeddict.ai.settings; +import static io.github.jeddict.ai.models.Constant.DEEPINFRA_URL; import io.github.jeddict.ai.models.GPT4AllModelFetcher; import io.github.jeddict.ai.models.OllamaModelFetcher; import io.github.jeddict.ai.models.LMStudioModelFetcher; @@ -26,6 +27,11 @@ import java.util.stream.Collectors; import javax.swing.JOptionPane; import static io.github.jeddict.ai.settings.GenAIModel.MODELS; +import java.awt.Cursor; +import java.awt.Desktop; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.net.URI; final class AIAssistancePanel extends javax.swing.JPanel { @@ -45,25 +51,30 @@ final class AIAssistancePanel extends javax.swing.JPanel { private void initComponents() { jLayeredPane1 = new javax.swing.JLayeredPane(); - jLayeredPane2 = new javax.swing.JLayeredPane(); + classContextPane = new javax.swing.JLayeredPane(); jLayeredPane7 = new javax.swing.JLayeredPane(); classContextLabel = new javax.swing.JLabel(); classContextHelp = new javax.swing.JLabel(); classContextComboBox = new javax.swing.JComboBox<>(); - jLayeredPane16 = new javax.swing.JLayeredPane(); + providerPane = new javax.swing.JLayeredPane(); jLayeredPane8 = new javax.swing.JLayeredPane(); providerLabel = new javax.swing.JLabel(); providerComboBox = new javax.swing.JComboBox<>(); - jLayeredPane13 = new javax.swing.JLayeredPane(); - providerKeyLabel = new javax.swing.JLabel(); - jLayeredPane6 = new javax.swing.JLayeredPane(); + providerLocationPane = new javax.swing.JLayeredPane(); + providerLocationLabel = new javax.swing.JLabel(); providerLocationField = new javax.swing.JTextField(); + apiKeyPane = new javax.swing.JLayeredPane(); + jLayeredPane2 = new javax.swing.JLayeredPane(); + apiKeyLabel = new javax.swing.JLabel(); + apiKeyInfo = new javax.swing.JLabel(); apiKeyField = new javax.swing.JPasswordField(); - jLayeredPane5 = new javax.swing.JLayeredPane(); + modelPane = new javax.swing.JLayeredPane(); + jLayeredPane6 = new javax.swing.JLayeredPane(); gptModelLabel = new javax.swing.JLabel(); - modelComboBox = new javax.swing.JComboBox<>(); - jLayeredPane17 = new javax.swing.JLayeredPane(); gptModelHelp = new javax.swing.JLabel(); + jLayeredPane5 = new javax.swing.JLayeredPane(); + modelComboBox = new javax.swing.JComboBox<>(); + modelsInfo = new javax.swing.JLabel(); jLayeredPane4 = new javax.swing.JLayeredPane(); aiAssistantActivationCheckBox = new javax.swing.JCheckBox(); enableHintCheckBox = new javax.swing.JCheckBox(); @@ -71,13 +82,12 @@ private void initComponents() { enableSmartCodeCheckBox = new javax.swing.JCheckBox(); showDescriptionCheckBox = new javax.swing.JCheckBox(); jLayeredPane3 = new javax.swing.JLayeredPane(); - resetKeyButton = new javax.swing.JButton(); cleanDataButton = new javax.swing.JButton(); jLayeredPane1.setLayout(new java.awt.GridLayout(0, 1)); - jLayeredPane2.setPreferredSize(new java.awt.Dimension(125, 75)); - jLayeredPane2.setLayout(new java.awt.GridLayout(0, 1)); + classContextPane.setPreferredSize(new java.awt.Dimension(125, 75)); + classContextPane.setLayout(new java.awt.GridLayout(0, 1)); jLayeredPane7.setPreferredSize(new java.awt.Dimension(125, 40)); jLayeredPane7.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 5, 0)); @@ -87,10 +97,11 @@ private void initComponents() { classContextHelp.setFont(new java.awt.Font("Segoe UI", 0, 10)); // NOI18N classContextHelp.setForeground(new java.awt.Color(100, 100, 100)); + classContextHelp.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); org.openide.awt.Mnemonics.setLocalizedText(classContextHelp, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.classContextHelp.text")); // NOI18N jLayeredPane7.add(classContextHelp); - jLayeredPane2.add(jLayeredPane7); + classContextPane.add(jLayeredPane7); classContextComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(AIClassContext.values())); classContextComboBox.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.classContextComboBox.toolTipText")); // NOI18N @@ -100,11 +111,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { classContextComboBoxActionPerformed(evt); } }); - jLayeredPane2.add(classContextComboBox); + classContextPane.add(classContextComboBox); - jLayeredPane1.add(jLayeredPane2); + jLayeredPane1.add(classContextPane); - jLayeredPane16.setLayout(new java.awt.GridLayout(0, 3, 5, 0)); + providerPane.setLayout(new javax.swing.BoxLayout(providerPane, javax.swing.BoxLayout.LINE_AXIS)); jLayeredPane8.setLayout(new java.awt.GridLayout(0, 1)); @@ -120,29 +131,54 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); jLayeredPane8.add(providerComboBox); - jLayeredPane16.add(jLayeredPane8); - - jLayeredPane13.setLayout(new java.awt.GridLayout(0, 1)); + providerPane.add(jLayeredPane8); - org.openide.awt.Mnemonics.setLocalizedText(providerKeyLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.providerKeyLabel.text")); // NOI18N - jLayeredPane13.add(providerKeyLabel); + providerLocationPane.setLayout(new java.awt.GridLayout(0, 1)); - jLayeredPane6.setLayout(new javax.swing.BoxLayout(jLayeredPane6, javax.swing.BoxLayout.Y_AXIS)); + org.openide.awt.Mnemonics.setLocalizedText(providerLocationLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.providerLocationLabel.text")); // NOI18N + providerLocationPane.add(providerLocationLabel); providerLocationField.setText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.providerLocationField.text")); // NOI18N - jLayeredPane6.add(providerLocationField); + providerLocationPane.add(providerLocationField); + + providerPane.add(providerLocationPane); + + apiKeyPane.setLayout(new java.awt.GridLayout(0, 1)); + + jLayeredPane2.setLayout(new java.awt.GridLayout()); + + org.openide.awt.Mnemonics.setLocalizedText(apiKeyLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.apiKeyLabel.text")); // NOI18N + jLayeredPane2.add(apiKeyLabel); + + apiKeyInfo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + org.openide.awt.Mnemonics.setLocalizedText(apiKeyInfo, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.apiKeyInfo.text")); // NOI18N + jLayeredPane2.add(apiKeyInfo); + + apiKeyPane.add(jLayeredPane2); apiKeyField.setText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.apiKeyField.text")); // NOI18N - jLayeredPane6.add(apiKeyField); + apiKeyPane.add(apiKeyField); + + providerPane.add(apiKeyPane); - jLayeredPane13.add(jLayeredPane6); + jLayeredPane1.add(providerPane); - jLayeredPane16.add(jLayeredPane13); + modelPane.setLayout(new java.awt.GridLayout(2, 1)); - jLayeredPane5.setLayout(new java.awt.GridLayout(0, 1)); + jLayeredPane6.setLayout(new javax.swing.BoxLayout(jLayeredPane6, javax.swing.BoxLayout.LINE_AXIS)); org.openide.awt.Mnemonics.setLocalizedText(gptModelLabel, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.gptModelLabel.text")); // NOI18N - jLayeredPane5.add(gptModelLabel); + jLayeredPane6.add(gptModelLabel); + + gptModelHelp.setFont(new java.awt.Font("Segoe UI", 0, 10)); // NOI18N + gptModelHelp.setForeground(new java.awt.Color(100, 100, 100)); + gptModelHelp.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + org.openide.awt.Mnemonics.setLocalizedText(gptModelHelp, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.gptModelHelp.text")); // NOI18N + jLayeredPane6.add(gptModelHelp); + + modelPane.add(jLayeredPane6); + + jLayeredPane5.setLayout(new java.awt.GridLayout(1, 2)); modelComboBox.setEditable(true); modelComboBox.setModel(new javax.swing.DefaultComboBoxModel<>(getModelList((GenAIProvider)providerComboBox.getSelectedItem()).toArray(new String[0]))); @@ -154,16 +190,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); jLayeredPane5.add(modelComboBox); - jLayeredPane16.add(jLayeredPane5); - - jLayeredPane1.add(jLayeredPane16); + modelsInfo.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); + org.openide.awt.Mnemonics.setLocalizedText(modelsInfo, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.modelsInfo.text")); // NOI18N + jLayeredPane5.add(modelsInfo); - jLayeredPane17.setLayout(new java.awt.GridLayout(2, 1)); + modelPane.add(jLayeredPane5); - gptModelHelp.setFont(new java.awt.Font("Segoe UI", 0, 10)); // NOI18N - gptModelHelp.setForeground(new java.awt.Color(100, 100, 100)); - org.openide.awt.Mnemonics.setLocalizedText(gptModelHelp, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.gptModelHelp.text")); // NOI18N - jLayeredPane17.add(gptModelHelp); + jLayeredPane1.add(modelPane); jLayeredPane4.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); @@ -185,9 +218,7 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { }); jLayeredPane4.add(enableHintCheckBox); - jLayeredPane17.add(jLayeredPane4); - - jLayeredPane1.add(jLayeredPane17); + jLayeredPane1.add(jLayeredPane4); jLayeredPane9.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT)); @@ -208,15 +239,6 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { jLayeredPane3.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT)); - org.openide.awt.Mnemonics.setLocalizedText(resetKeyButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.resetKeyButton.text")); // NOI18N - resetKeyButton.setToolTipText(org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.resetKeyButton.toolTipText")); // NOI18N - resetKeyButton.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - resetKeyButtonActionPerformed(evt); - } - }); - jLayeredPane3.add(resetKeyButton); - org.openide.awt.Mnemonics.setLocalizedText(cleanDataButton, org.openide.util.NbBundle.getMessage(AIAssistancePanel.class, "AIAssistancePanel.cleanDataButton.text")); // NOI18N cleanDataButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { @@ -231,15 +253,11 @@ public void actionPerformed(java.awt.event.ActionEvent evt) { this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLayeredPane1)) + .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 518, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addContainerGap() - .addComponent(jLayeredPane1)) + .addComponent(jLayeredPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 320, Short.MAX_VALUE) ); }// //GEN-END:initComponents @@ -274,11 +292,6 @@ private void modelComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN } }//GEN-LAST:event_modelComboBoxActionPerformed - private void resetKeyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetKeyButtonActionPerformed - preferencesManager.clearApiKey(); - JOptionPane.showMessageDialog(this, "Your API key has been reset successfully!", "Information", JOptionPane.INFORMATION_MESSAGE); - }//GEN-LAST:event_resetKeyButtonActionPerformed - private void cleanDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cleanDataButtonActionPerformed ProjectClassScanner.clear(); JOptionPane.showMessageDialog(this, "Cache has been cleared successfully!", "Information", JOptionPane.INFORMATION_MESSAGE); @@ -290,33 +303,101 @@ private void showDescriptionCheckBoxActionPerformed(java.awt.event.ActionEvent e private void providerComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_providerComboBoxActionPerformed GenAIProvider selectedProvider = (GenAIProvider) providerComboBox.getSelectedItem(); - if (selectedProvider == GenAIProvider.GOOGLE + if (selectedProvider == GenAIProvider.DEEPINFRA + || selectedProvider == GenAIProvider.CUSTOM_OPEN_AI) { + apiKeyLabel.setVisible(true); + apiKeyField.setVisible(true); + apiKeyPane.setVisible(true); + providerLocationLabel.setVisible(true); + if (selectedProvider == GenAIProvider.DEEPINFRA) { + providerLocationField.setText(DEEPINFRA_URL); + } else { + providerLocationField.setText(""); + } + providerLocationField.setVisible(true); + providerLocationPane.setVisible(true); + } else if (selectedProvider == GenAIProvider.GOOGLE || selectedProvider == GenAIProvider.OPEN_AI - || selectedProvider == GenAIProvider.DEEPINFRA || selectedProvider == GenAIProvider.MISTRAL || selectedProvider == GenAIProvider.ANTHROPIC) { - providerKeyLabel.setText("API Key:"); + apiKeyLabel.setVisible(true); + apiKeyField.setVisible(true); + apiKeyPane.setVisible(true); + providerLocationLabel.setVisible(false); providerLocationField.setText(""); providerLocationField.setVisible(false); - apiKeyField.setVisible(true); - } else if (selectedProvider == GenAIProvider.OLLAMA) { - providerKeyLabel.setText("Location:"); - OllamaModelFetcher fetcher = new OllamaModelFetcher(); - providerLocationField.setText(fetcher.getAPIUrl()); - providerLocationField.setVisible(true); - apiKeyField.setVisible(false); - } else if (selectedProvider == GenAIProvider.LM_STUDIO) { - providerKeyLabel.setText("Location:"); - LMStudioModelFetcher fetcher = new LMStudioModelFetcher(); - providerLocationField.setText(fetcher.getAPIUrl()); - providerLocationField.setVisible(true); + providerLocationPane.setVisible(false); + } else { + apiKeyLabel.setVisible(false); apiKeyField.setVisible(false); - } else if (selectedProvider == GenAIProvider.GPT4ALL) { - providerKeyLabel.setText("Location:"); - GPT4AllModelFetcher fetcher = new GPT4AllModelFetcher(); - providerLocationField.setText(fetcher.getAPIUrl()); + apiKeyPane.setVisible(false); + providerLocationLabel.setVisible(true); providerLocationField.setVisible(true); - apiKeyField.setVisible(false); + providerLocationPane.setVisible(true); + + if (null != selectedProvider) { + switch (selectedProvider) { + case OLLAMA -> + providerLocationField.setText(new OllamaModelFetcher().getAPIUrl()); + case LM_STUDIO -> + providerLocationField.setText(new LMStudioModelFetcher().getAPIUrl()); + case GPT4ALL -> + providerLocationField.setText(new GPT4AllModelFetcher().getAPIUrl()); + } + } + } + if (apiKeyLabel.isVisible() + && selectedProvider != null + && !selectedProvider.getApiKeyUrl().isEmpty()) { + String apiKeyUrl = selectedProvider.getApiKeyUrl(); + apiKeyInfo.setText("" + apiKeyUrl + ""); + apiKeyInfo.setCursor(new Cursor(Cursor.HAND_CURSOR)); + apiKeyInfo.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + Desktop.getDesktop().browse(new URI(apiKeyUrl)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + apiKeyInfo.setText("" + apiKeyUrl + ""); + } + + @Override + public void mouseExited(MouseEvent e) { + apiKeyInfo.setText("" + apiKeyUrl + ""); + } + }); + } + if (selectedProvider != null + && !selectedProvider.getModelInfoUrl().isEmpty()) { + String modelInfoUrl = selectedProvider.getModelInfoUrl(); + modelsInfo.setText("" + modelInfoUrl + ""); + modelsInfo.setCursor(new Cursor(Cursor.HAND_CURSOR)); + modelsInfo.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + try { + Desktop.getDesktop().browse(new URI(modelInfoUrl)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public void mouseEntered(MouseEvent e) { + modelsInfo.setText("" + modelInfoUrl + ""); + } + + @Override + public void mouseExited(MouseEvent e) { + modelsInfo.setText("" + modelInfoUrl + ""); + } + }); } if (selectedProvider != null) { updateModelComboBox(selectedProvider); @@ -334,15 +415,15 @@ private void updateModelComboBox(GenAIProvider selectedProvider) { } private List getModelList(GenAIProvider selectedProvider) { - if (selectedProvider == GenAIProvider.OLLAMA + if (selectedProvider == GenAIProvider.OLLAMA && !providerLocationField.getText().isEmpty()) { OllamaModelFetcher fetcher = new OllamaModelFetcher(); return fetcher.fetchModelNames(providerLocationField.getText()); - } else if (selectedProvider == GenAIProvider.LM_STUDIO + } else if (selectedProvider == GenAIProvider.LM_STUDIO && !providerLocationField.getText().isEmpty()) { LMStudioModelFetcher fetcher = new LMStudioModelFetcher(); return fetcher.fetchModelNames(providerLocationField.getText()); - }else if (selectedProvider == GenAIProvider.GPT4ALL + } else if (selectedProvider == GenAIProvider.GPT4ALL && !providerLocationField.getText().isEmpty()) { GPT4AllModelFetcher fetcher = new GPT4AllModelFetcher(); return fetcher.fetchModelNames(providerLocationField.getText()); @@ -352,7 +433,7 @@ private List getModelList(GenAIProvider selectedProvider) { .map(GenAIModel::getName) .collect(Collectors.toList()); } - + private GenAIModel getModel(String modelName) { return MODELS.get(modelName); } @@ -377,9 +458,12 @@ void load() { modelComboBox.setSelectedItem(preferencesManager.getModel()); showDescriptionCheckBox.setSelected(preferencesManager.isDescriptionEnabled()); GenAIProvider selectedProvider = (GenAIProvider) providerComboBox.getSelectedItem(); - if (selectedProvider == GenAIProvider.GOOGLE + if (selectedProvider == GenAIProvider.CUSTOM_OPEN_AI + || selectedProvider == GenAIProvider.DEEPINFRA) { + apiKeyField.setText(preferencesManager.getApiKey(true)); + providerLocationField.setText(preferencesManager.getProviderLocation()); + } else if (selectedProvider == GenAIProvider.GOOGLE || selectedProvider == GenAIProvider.OPEN_AI - || selectedProvider == GenAIProvider.DEEPINFRA || selectedProvider == GenAIProvider.MISTRAL || selectedProvider == GenAIProvider.ANTHROPIC) { apiKeyField.setText(preferencesManager.getApiKey(true)); @@ -394,15 +478,18 @@ void store() { preferencesManager.setAiAssistantActivated(aiAssistantActivationCheckBox.isSelected()); preferencesManager.setClassContext((AIClassContext) classContextComboBox.getSelectedItem()); preferencesManager.setProvider((GenAIProvider) providerComboBox.getSelectedItem()); - preferencesManager.setModel((String)modelComboBox.getSelectedItem()); + preferencesManager.setModel((String) modelComboBox.getSelectedItem()); preferencesManager.setHintsEnabled(enableHintCheckBox.isSelected()); preferencesManager.setSmartCodeEnabled(enableSmartCodeCheckBox.isSelected()); preferencesManager.setDescriptionEnabled(showDescriptionCheckBox.isSelected()); - + GenAIProvider selectedProvider = (GenAIProvider) providerComboBox.getSelectedItem(); - if (selectedProvider == GenAIProvider.GOOGLE + if (selectedProvider == GenAIProvider.CUSTOM_OPEN_AI + || selectedProvider == GenAIProvider.DEEPINFRA) { + preferencesManager.setApiKey(new String(apiKeyField.getPassword())); + preferencesManager.setProviderLocation(providerLocationField.getText()); + } else if (selectedProvider == GenAIProvider.GOOGLE || selectedProvider == GenAIProvider.OPEN_AI - || selectedProvider == GenAIProvider.DEEPINFRA || selectedProvider == GenAIProvider.MISTRAL || selectedProvider == GenAIProvider.ANTHROPIC) { preferencesManager.setApiKey(new String(apiKeyField.getPassword())); @@ -420,18 +507,19 @@ boolean valid() { // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox aiAssistantActivationCheckBox; private javax.swing.JPasswordField apiKeyField; + private javax.swing.JLabel apiKeyInfo; + private javax.swing.JLabel apiKeyLabel; + private javax.swing.JLayeredPane apiKeyPane; private javax.swing.JComboBox classContextComboBox; private javax.swing.JLabel classContextHelp; private javax.swing.JLabel classContextLabel; + private javax.swing.JLayeredPane classContextPane; private javax.swing.JButton cleanDataButton; private javax.swing.JCheckBox enableHintCheckBox; private javax.swing.JCheckBox enableSmartCodeCheckBox; private javax.swing.JLabel gptModelHelp; private javax.swing.JLabel gptModelLabel; private javax.swing.JLayeredPane jLayeredPane1; - private javax.swing.JLayeredPane jLayeredPane13; - private javax.swing.JLayeredPane jLayeredPane16; - private javax.swing.JLayeredPane jLayeredPane17; private javax.swing.JLayeredPane jLayeredPane2; private javax.swing.JLayeredPane jLayeredPane3; private javax.swing.JLayeredPane jLayeredPane4; @@ -441,11 +529,14 @@ boolean valid() { private javax.swing.JLayeredPane jLayeredPane8; private javax.swing.JLayeredPane jLayeredPane9; private javax.swing.JComboBox modelComboBox; + private javax.swing.JLayeredPane modelPane; + private javax.swing.JLabel modelsInfo; private javax.swing.JComboBox providerComboBox; - private javax.swing.JLabel providerKeyLabel; private javax.swing.JLabel providerLabel; private javax.swing.JTextField providerLocationField; - private javax.swing.JButton resetKeyButton; + private javax.swing.JLabel providerLocationLabel; + private javax.swing.JLayeredPane providerLocationPane; + private javax.swing.JLayeredPane providerPane; private javax.swing.JCheckBox showDescriptionCheckBox; // End of variables declaration//GEN-END:variables } diff --git a/src/main/java/io/github/jeddict/ai/settings/GenAIProvider.java b/src/main/java/io/github/jeddict/ai/settings/GenAIProvider.java index ccfafb8..cf6d977 100644 --- a/src/main/java/io/github/jeddict/ai/settings/GenAIProvider.java +++ b/src/main/java/io/github/jeddict/ai/settings/GenAIProvider.java @@ -1,21 +1,3 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ package io.github.jeddict.ai.settings; /** @@ -23,13 +5,30 @@ * Author: Shiwani Gupta */ public enum GenAIProvider { - OPEN_AI, - GOOGLE, - DEEPINFRA, - MISTRAL, - OLLAMA, - ANTHROPIC, - LM_STUDIO, - GPT4ALL; + OPEN_AI("https://platform.openai.com/docs/models", "https://platform.openai.com/api-keys"), + CUSTOM_OPEN_AI("", ""), + GOOGLE("https://ai.google.dev/gemini-api/docs/models/gemini", "https://console.cloud.google.com/apis/credentials"), + DEEPINFRA("https://deepinfra.com/models", "https://deepinfra.com/dash/api_keys"), + MISTRAL("https://docs.mistral.ai/getting-started/models/models_overview/", "https://console.mistral.ai/api-keys/"), + OLLAMA("https://ollama.com/models", ""), + ANTHROPIC("https://docs.anthropic.com/en/docs/about-claude/models", "https://console.anthropic.com/settings/keys"), + LM_STUDIO("https://lmstudio.ai/models", ""), + GPT4ALL("https://docs.gpt4all.io/gpt4all_desktop/models.html", ""); + + private final String modelInfoUrl; + private final String apiKeyUrl; + + GenAIProvider(String modelInfoUrl, String apiKeyUrl) { + this.modelInfoUrl = modelInfoUrl; + this.apiKeyUrl = apiKeyUrl; + } + + public String getModelInfoUrl() { + return modelInfoUrl; + } + + public String getApiKeyUrl() { + return apiKeyUrl; + } } diff --git a/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties b/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties index 255976f..aeb9b4e 100644 --- a/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties +++ b/src/main/resources/io/github/jeddict/ai/settings/Bundle.properties @@ -9,12 +9,10 @@ AIAssistancePanel.classContextHelp.text= AIAssistancePanel.classContextLabel.text=Class Context Scope: AIAssistancePanel.cleanDataButton.text=Clean cache AIAssistancePanel.gptModelHelp.text= -AIAssistancePanel.resetKeyButton.text=Reset OpenAI API Key AIAssistancePanel.gptModelLabel.text=Model: AIAssistancePanel.enableHintCheckBox.text=Enable Hints AIAssistancePanel.aiAssistantActivationCheckBox.toolTipText=Enable or disable the AI assistant for smart code completion and suggestions. AIAssistancePanel.enableHintCheckBox.toolTipText=Enable this option to receive hints and suggestions as you work. -AIAssistancePanel.resetKeyButton.toolTipText=Click to reset the API key for AI assistant integration. AIAssistancePanel.enableSmartCodeCheckBox.toolTipText=Enable AI-powered smart code suggestions for improved development experience. AIAssistancePanel.enableSmartCodeCheckBox.text=Enable Smart Code Suggestion AIAssistancePanel.showDescriptionCheckBox.toolTipText=Enable AI-powered smart code suggestions for improved development experience. @@ -22,6 +20,9 @@ AIAssistancePanel.showDescriptionCheckBox.text=Show Snippet with Description AIAssistancePanel.providerComboBox.toolTipText=Choose the GPT model for AI assistance. Different models may offer varied levels of complexity and speed. AIAssistancePanel.modelComboBox.toolTipText=Choose the GPT model for AI assistance. Different models may offer varied levels of complexity and speed. AIAssistancePanel.providerLabel.text=Provider: -AIAssistancePanel.providerKeyLabel.text= AIAssistancePanel.providerLocationField.text= AIAssistancePanel.apiKeyField.text= +AIAssistancePanel.apiKeyLabel.text=API Key: +AIAssistancePanel.providerLocationLabel.text=Url: +AIAssistancePanel.modelsInfo.text= +AIAssistancePanel.apiKeyInfo.text=