Skip to content

Commit

Permalink
Fix: Return empty list when local LLM is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanj committed May 21, 2024
1 parent b589e61 commit 004c6d1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public List<String> getModelNames() {
}
} catch (IOException e) {
NotificationUtil.sendNotification(ProjectManager.getInstance().getDefaultProject(),
"Jan is not running or model not installed.");
"Jan is not running, please start it.");
return List.of();
}
return modelNames;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public List<String> getModelNames() {
} catch (IOException e) {
NotificationUtil.sendNotification(ProjectManager.getInstance().getDefaultProject(),
"Ollama is not running, please start it.");
return List.of();
}
return modelNames;
}
Expand Down
35 changes: 24 additions & 11 deletions src/main/java/com/devoxx/genie/ui/DevoxxGenieToolWindowContent.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.devoxx.genie.ui;

import com.devoxx.genie.chatmodel.ChatModelFactory;
import com.devoxx.genie.chatmodel.ChatModelFactoryProvider;
import com.devoxx.genie.chatmodel.ChatModelProvider;
import com.devoxx.genie.model.enumarations.ModelProvider;
Expand Down Expand Up @@ -486,23 +487,35 @@ private void handleModelProviderSelectionChange(@NotNull ActionEvent e) {
* @param provider the model provider
*/
private void updateModelNamesComboBox(ModelProvider provider) {
if (provider == null) {
return;
}

modelNameComboBox.setVisible(true);
modelNameComboBox.removeAllItems();

ChatModelFactoryProvider
.getFactoryByProvider(provider)
.ifPresentOrElse(
chatModelFactory ->
chatModelFactory.getModelNames()
.stream()
.sorted()
.forEach(modelNameComboBox::addItem),
() -> modelNameComboBox.setVisible(false)
);

if (settingsState.getLastSelectedModel() != null) {
String lastSelectedModel = settingsState.getLastSelectedModel();
.ifPresentOrElse(this::populateModelNames, this::hideModelNameComboBox);

String lastSelectedModel = settingsState.getLastSelectedModel();
if (lastSelectedModel != null) {
modelNameComboBox.setSelectedItem(lastSelectedModel);
}
}

private void populateModelNames(@NotNull ChatModelFactory chatModelFactory) {
List<String> modelNames = chatModelFactory.getModelNames();
if (modelNames.isEmpty()) {
hideModelNameComboBox();
} else {
modelNames.stream()
.sorted()
.forEach(modelNameComboBox::addItem);
}
}

private void hideModelNameComboBox() {
modelNameComboBox.setVisible(false);
}
}

0 comments on commit 004c6d1

Please sign in to comment.