Sort models
This commit is contained in:
BIN
lm-launcher.jar
BIN
lm-launcher.jar
Binary file not shown.
@@ -6,6 +6,7 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
@@ -47,6 +48,7 @@ public class Data {
|
||||
modelData.models.set(i, new Model(model.path(), model.contextSize(), model.contextSize(), model.gpuLayers(), model.threads(), Objects.requireNonNullElse(model.promptTemplate(), "")));
|
||||
}
|
||||
}
|
||||
sortModels();
|
||||
|
||||
try {
|
||||
appData = objectMapper.readValue(new File("apps.json"), AppData.class);
|
||||
@@ -69,6 +71,7 @@ public class Data {
|
||||
}
|
||||
|
||||
static void saveModels() {
|
||||
sortModels();
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
objectMapper.writeValue(new File("models.json"), modelData);
|
||||
@@ -78,6 +81,12 @@ public class Data {
|
||||
}
|
||||
}
|
||||
|
||||
static void sortModels() {
|
||||
modelData.models().sort(Comparator
|
||||
.comparing(Data::modelName, String.CASE_INSENSITIVE_ORDER)
|
||||
.thenComparing(Model::path));
|
||||
}
|
||||
|
||||
static void saveApps() {
|
||||
final ObjectMapper objectMapper = new ObjectMapper();
|
||||
try {
|
||||
@@ -88,6 +97,11 @@ public class Data {
|
||||
}
|
||||
}
|
||||
|
||||
private static String modelName(final Model model) {
|
||||
final Path fileName = Path.of(model.path()).getFileName();
|
||||
return fileName == null ? model.path() : fileName.toString();
|
||||
}
|
||||
|
||||
static List<String> scanModels() {
|
||||
final List<String> result = new ArrayList<>();
|
||||
try {
|
||||
|
||||
@@ -142,9 +142,6 @@ public class LaunchFrame extends JFrame {
|
||||
final SelectModelDialog smDialog = new SelectModelDialog(LaunchFrame.this, path -> {
|
||||
final ModelPropertiesDialog mpDialog = new ModelPropertiesDialog(LaunchFrame.this, path, null, model -> {
|
||||
Data.modelData.models().add(model);
|
||||
Data.modelData.models().sort((o1, o2) -> {
|
||||
return o1.path().compareTo(o2.path());
|
||||
});
|
||||
try {
|
||||
Data.saveModels();
|
||||
}
|
||||
@@ -554,6 +551,7 @@ public class LaunchFrame extends JFrame {
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
Data.sortModels();
|
||||
this.listModel.clear();
|
||||
Data.appData.apps()
|
||||
.stream()
|
||||
|
||||
Reference in New Issue
Block a user