diff --git a/lm-launcher.properties b/lm-launcher.properties index 9987859..2658b5a 100644 --- a/lm-launcher.properties +++ b/lm-launcher.properties @@ -1,2 +1,2 @@ -models=/home/sb/lm/models/ +models=/mnt/data/data/lm/models/gguf/ console=/usr/bin/konsole -e CMD diff --git a/src/de/extio/lm_launcher/Data.java b/src/de/extio/lm_launcher/Data.java index ee9c093..75e58b2 100644 --- a/src/de/extio/lm_launcher/Data.java +++ b/src/de/extio/lm_launcher/Data.java @@ -91,13 +91,15 @@ public class Data { static List scanModels() { final List result = new ArrayList<>(); try { - Files - .list(Path.of(props.getProperty("models"))) - .filter(p -> p.getFileName().toString().endsWith(".gguf")) - .map(Path::toAbsolutePath) - .map(Path::toString) - .sorted() - .forEach(result::add); + try (var paths = Files.walk(Path.of(props.getProperty("models")))) { + paths + .filter(Files::isRegularFile) + .filter(p -> p.getFileName().toString().endsWith(".gguf")) + .map(Path::toAbsolutePath) + .map(Path::toString) + .sorted() + .forEach(result::add); + } } catch (final IOException e) { e.printStackTrace(); diff --git a/src/de/extio/lm_launcher/SelectModelDialog.java b/src/de/extio/lm_launcher/SelectModelDialog.java index 0edbeda..af91049 100644 --- a/src/de/extio/lm_launcher/SelectModelDialog.java +++ b/src/de/extio/lm_launcher/SelectModelDialog.java @@ -5,6 +5,9 @@ import java.awt.FlowLayout; import java.awt.Frame; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; import javax.swing.DefaultListModel; @@ -30,6 +33,8 @@ public class SelectModelDialog extends JDialog { DefaultListModel listModel; + List modelPaths; + /** * Create the dialog. */ @@ -70,7 +75,7 @@ public class SelectModelDialog extends JDialog { return; } SelectModelDialog.this.setVisible(false); - modelPathConsumer.accept(SelectModelDialog.this.listModel.getElementAt(SelectModelDialog.this.list.getSelectedIndex())); + modelPathConsumer.accept(SelectModelDialog.this.modelPaths.get(SelectModelDialog.this.list.getSelectedIndex())); SelectModelDialog.this.dispose(); } }); @@ -98,10 +103,19 @@ public class SelectModelDialog extends JDialog { } private void initialize() { + final Path modelsRoot = Path.of(Data.props.getProperty("models")).toAbsolutePath().normalize(); + this.modelPaths = new ArrayList<>(); Data.scanModels() .stream() .filter(p -> Data.modelData.models().stream().noneMatch(m -> m.path().equals(p))) - .forEach(this.listModel::addElement); + .forEach(absolutePath -> { + final Path modelPath = Path.of(absolutePath).toAbsolutePath().normalize(); + final String displayPath = modelPath.startsWith(modelsRoot) + ? modelsRoot.relativize(modelPath).toString() + : modelPath.toString(); + this.modelPaths.add(modelPath.toString()); + this.listModel.addElement(displayPath.isEmpty() ? modelPath.getFileName().toString() : displayPath); + }); } } \ No newline at end of file