Skip to content

Commit

Permalink
Merge pull request #317 from mydeveloperplanet/issue-311
Browse files Browse the repository at this point in the history
Fixes #311 Support reload language model without restart of IDEA
  • Loading branch information
mydeveloperplanet authored Oct 20, 2024
2 parents be83ea7 + ad13ae6 commit 3bbca0a
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ default List<LanguageModel> getModels(ModelProvider provider) {
default String getApiKey() {
return "";
}

/**
* Reset the list of local models
*/
default void resetModels() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,9 @@ public List<LanguageModel> getModels() {
}
return cachedModels;
}

@Override
public void resetModels() {
cachedModels = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,9 @@ public List<LanguageModel> getModels() {
}
return cachedModels;
}

@Override
public void resetModels() {
cachedModels = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ public List<LanguageModel> getModels() {
}
return cachedModels;
}

@Override
public void resetModels() {
cachedModels = null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.devoxx.genie.model.enumarations.ModelProvider;
import com.devoxx.genie.model.request.ChatMessageContext;
import com.devoxx.genie.service.*;
import com.devoxx.genie.ui.component.JHoverButton;
import com.devoxx.genie.ui.component.PromptInputArea;
import com.devoxx.genie.ui.listener.ConversationEventListener;
import com.devoxx.genie.ui.listener.CustomPromptChangeListener;
Expand All @@ -19,6 +20,7 @@
import com.devoxx.genie.ui.renderer.ModelInfoRenderer;
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
import com.devoxx.genie.ui.topic.AppTopics;
import com.devoxx.genie.ui.util.NotificationUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
Expand All @@ -38,10 +40,10 @@
import java.awt.event.ActionEvent;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.devoxx.genie.model.Constant.MESSAGES;
import static com.devoxx.genie.ui.util.DevoxxGenieIconsUtil.RefreshIcon;

/**
* The Devoxx Genie Tool Window Content.
Expand Down Expand Up @@ -79,6 +81,8 @@ public class DevoxxGenieToolWindowContent implements SettingsChangeListener,
private final ChatService chatService;
private final ConversationStorageService storageService = ConversationStorageService.getInstance();

private final JButton refreshButton = new JHoverButton(RefreshIcon, true);

/**
* The Devoxx Genie Tool Window Content constructor.
*
Expand Down Expand Up @@ -296,9 +300,43 @@ private void addModelProvidersToComboBox() {
private @NotNull JPanel createProviderPanel() {
JPanel providerPanel = new JPanel(new BorderLayout());
providerPanel.add(modelProviderComboBox, BorderLayout.CENTER);

refreshButton.setToolTipText("Refresh models");
refreshButton.addActionListener(e -> refreshModels());

providerPanel.add(refreshButton, BorderLayout.EAST);
return providerPanel;
}

/**
* Refresh the list of local models
*/
private void refreshModels() {
ModelProvider selectedProvider = (ModelProvider) modelProviderComboBox.getSelectedItem();
if (selectedProvider == null) {
return;
}

if (selectedProvider == ModelProvider.LMStudio || selectedProvider == ModelProvider.Ollama || selectedProvider == ModelProvider.Jan) {
SwingUtilities.invokeLater(() -> {
refreshButton.setEnabled(false);

ChatModelFactory factory = ChatModelFactoryProvider.getFactoryByProvider(selectedProvider.name())
.orElseThrow(() -> new IllegalArgumentException("No factory for provider: " + selectedProvider));
factory.resetModels();

updateModelNamesComboBox(selectedProvider.getName());
modelNameComboBox.setRenderer(new ModelInfoRenderer());
modelNameComboBox.revalidate();
modelNameComboBox.repaint();
refreshButton.setEnabled(true);

});
} else {
NotificationUtil.sendNotification(project, "Model refresh is only available for LMStudio, Ollama and Jan providers.");
}
}

/**
* Create the Submit panel.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public final class DevoxxGenieIconsUtil {
public static final Icon CodeSnippetIcon = load("/icons/codeSnippet.svg");
public static final Icon CopyIcon = load("/icons/copy.svg");
public static final Icon InsertCodeIcon = load("/icons/insertCode.svg");
public static final Icon RefreshIcon = load("/icons/refresh.svg");

private DevoxxGenieIconsUtil() {
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
<h2>v0.2.24</h2>
<UL>
<LI>Feat #206 : Support for JLama using REST API</LI>
<LI>Feat #311 : Support reload language model without restart of IDEA</LI>
</UL>
<h2>v0.2.23</h2>
<UL>
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/icons/refresh.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/main/resources/icons/refresh_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3bbca0a

Please sign in to comment.