From: Svjatoslav Agejenko Date: Sun, 11 Jan 2026 03:55:25 +0000 (+0200) Subject: Refactor codebase to replace `ConfigurationModel` with `Model` for model representation. X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=HEAD;p=alyverkko-cli.git Refactor codebase to replace `ConfigurationModel` with `Model` for model representation. --- diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java index 56ce403..5056ecb 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import eu.svjatoslav.alyverkko_cli.Command; import eu.svjatoslav.alyverkko_cli.configuration.Configuration; import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper; -import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationModel; +import eu.svjatoslav.alyverkko_cli.configuration.Model; import eu.svjatoslav.commons.cli_helper.parameter_parser.Parser; import eu.svjatoslav.commons.cli_helper.parameter_parser.parameter.FileOption; @@ -382,7 +382,7 @@ public class WizardCommand implements Command { return; } - List existingModels = configuration.getModels(); + List existingModels = configuration.getModels(); if (existingModels == null) { existingModels = new ArrayList<>(); configuration.setModels(existingModels); @@ -440,16 +440,16 @@ public class WizardCommand implements Command { } private void addNewModel(String relativePath) { - ConfigurationModel newModel = getNewModel(relativePath); + Model newModel = getNewModel(relativePath); configuration.getModels().add(newModel); System.out.println("Added new model: " + newModel.getAlias() + " (" + newModel.getFilesystemPath() + ")"); configurationUpdated = true; modelsUpdated = true; } - private ConfigurationModel getNewModel(String relativePath) { + private Model getNewModel(String relativePath) { String suggestedAlias = suggestAlias(relativePath); - ConfigurationModel newModel = new ConfigurationModel(); + Model newModel = new Model(); newModel.setAlias(suggestedAlias + "-new"); newModel.setFilesystemPath(relativePath); newModel.setContextSizeTokens(32768); // Default context size @@ -459,7 +459,7 @@ public class WizardCommand implements Command { private void annotateMissingModels() { // Process existing models to add/remove -missing suffix - for (ConfigurationModel model : configuration.getModels()) { + for (Model model : configuration.getModels()) { File modelFile = new File(configuration.getModelsDirectory(), model.getFilesystemPath()); if (!modelFile.exists()) { if (!model.getAlias().endsWith("-missing")) { diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/Task.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/Task.java index 1fed2e4..2e80c53 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/Task.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/Task.java @@ -1,6 +1,6 @@ package eu.svjatoslav.alyverkko_cli.commands.task_processor; -import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationModel; +import eu.svjatoslav.alyverkko_cli.configuration.Model; import eu.svjatoslav.alyverkko_cli.configuration.SkillConfig; import static eu.svjatoslav.alyverkko_cli.Main.configuration; @@ -35,7 +35,7 @@ public class Task { /** * The AI model to be used for processing this query. */ - public ConfigurationModel model; + public Model model; /** * The start time of the query (milliseconds since epoch). diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/TaskProcessorCommand.java b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/TaskProcessorCommand.java index 4f095d2..c811509 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/TaskProcessorCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/task_processor/TaskProcessorCommand.java @@ -2,7 +2,7 @@ package eu.svjatoslav.alyverkko_cli.commands.task_processor; import eu.svjatoslav.alyverkko_cli.*; import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper; -import eu.svjatoslav.alyverkko_cli.configuration.ConfigurationModel; +import eu.svjatoslav.alyverkko_cli.configuration.Model; import eu.svjatoslav.alyverkko_cli.configuration.SkillConfig; import eu.svjatoslav.alyverkko_cli.configuration.ModelLibrary; import eu.svjatoslav.commons.cli_helper.parameter_parser.Parser; @@ -337,7 +337,7 @@ public class TaskProcessorCommand implements Command { // Set AI model using hierarchy: TOCOMPUTE > skill config > default String modelAlias = fileProcessingSettings.getOrDefault("model", skill.getModelAlias() != null ? skill.getModelAlias() : "default"); - Optional modelOptional = modelLibrary.findModelByAlias(modelAlias); + Optional modelOptional = modelLibrary.findModelByAlias(modelAlias); if (!modelOptional.isPresent()) { throw new IllegalArgumentException("Model with alias '" + modelAlias + "' not found."); } diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java index 5d47c96..abe5b33 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Configuration.java @@ -98,7 +98,7 @@ public class Configuration { /** * The list of models defined in this configuration. */ - private List models; + private List models; /** diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ConfigurationModel.java b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ConfigurationModel.java deleted file mode 100644 index 5accc73..0000000 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ConfigurationModel.java +++ /dev/null @@ -1,88 +0,0 @@ -package eu.svjatoslav.alyverkko_cli.configuration; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.Data; - - -/** - * Represents a single AI model configuration entry, including alias, - * path to the model file, token context size, and an optional - * end-of-text marker. - */ -@Data -public class ConfigurationModel { - - /** - * A short name for the model, e.g., "default" or "mistral". - */ - private String alias; - - /** - * Model-specific temperature value overriding global default. - */ - private Float temperature; - - /** - * Model-specific top-p value overriding global default. - */ - @JsonProperty("top_p") - private Float topP; - - @JsonProperty("min_p") - private Float minP; - - @JsonProperty("top_k") - private Float topK; - - /** - * Model-specific repeat penalty value overriding global default. - */ - @JsonProperty("repeat_penalty") - private Float repeatPenalty; - - /** - * The path to the model file (GGUF, etc.), relative to - * {@link Configuration#getModelsDirectory()} or fully qualified. - */ - @JsonProperty("filesystem_path") - private String filesystemPath; - - /** - * The maximum context size the model supports, in tokens. - */ - @JsonProperty("context_size_tokens") - private int contextSizeTokens; - - /** - * Optional text marker signifying the end of text for this model. - * If non-null, it will be used to strip trailing tokens from the AI response. - */ - @JsonProperty("end_of_text_marker") - private String endOfTextMarker; - - /** - * Optional string that indicates the start of the final answer in the model's output. - * When specified, the response is split into ASSISTANT and FINAL ANSWER sections based on this indicator. - */ - @JsonProperty("final_answer_indicator") - private String finalAnswerIndicator; - - /** - *

Prints the model's metadata to standard output in a consistent format. This includes the model's alias, - * filesystem path, and context token capacity. The output format is designed to be both human-readable and - * machine-parsable when needed. - *

Typical output: - *

-     * Model: default
-     *   Path: /path/to/model.gguf
-     *   Context size: 32768
-     * 
- */ - public void printModelDetails() { - System.out.println("Model: " + alias); - System.out.println(" Path: " + filesystemPath); - System.out.println(" Context size: " + contextSizeTokens); - } - -} diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Model.java b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Model.java new file mode 100644 index 0000000..26f4406 --- /dev/null +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/Model.java @@ -0,0 +1,87 @@ +package eu.svjatoslav.alyverkko_cli.configuration; + +import com.fasterxml.jackson.annotation.JsonProperty; +import lombok.Data; + + +/** + * Represents a single AI model configuration entry, including alias, + * path to the model file, token context size, and an optional + * end-of-text marker. + */ +@Data +public class Model { + + /** + * A short name for the model, e.g., "default" or "mistral". + */ + private String alias; + + /** + * Model-specific temperature value overriding global default. + */ + private Float temperature; + + /** + * Model-specific top-p value overriding global default. + */ + @JsonProperty("top_p") + private Float topP; + + @JsonProperty("min_p") + private Float minP; + + @JsonProperty("top_k") + private Float topK; + + /** + * Model-specific repeat penalty value overriding global default. + */ + @JsonProperty("repeat_penalty") + private Float repeatPenalty; + + /** + * The path to the model file (GGUF, etc.), relative to + * {@link Configuration#getModelsDirectory()} or fully qualified. + */ + @JsonProperty("filesystem_path") + private String filesystemPath; + + /** + * The maximum context size the model supports, in tokens. + */ + @JsonProperty("context_size_tokens") + private int contextSizeTokens; + + /** + * Optional text marker signifying the end of text for this model. + * If non-null, it will be used to strip trailing tokens from the AI response. + */ + @JsonProperty("end_of_text_marker") + private String endOfTextMarker; + + /** + * Optional string that indicates the start of the final answer in the model's output. + * When specified, the response is split into ASSISTANT and FINAL ANSWER sections based on this indicator. + */ + @JsonProperty("final_answer_indicator") + private String finalAnswerIndicator; + + /** + *

Prints the model's metadata to standard output in a consistent format. This includes the model's alias, + * filesystem path, and context token capacity. The output format is designed to be both human-readable and + * machine-parsable when needed. + *

Typical output: + *

+     * Model: default
+     *   Path: /path/to/model.gguf
+     *   Context size: 32768
+     * 
+ */ + public void printModelDetails() { + System.out.println("Model: " + alias); + System.out.println(" Path: " + filesystemPath); + System.out.println(" Context size: " + contextSizeTokens); + } + +} diff --git a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ModelLibrary.java b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ModelLibrary.java index a676bee..68c5ece 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ModelLibrary.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/configuration/ModelLibrary.java @@ -14,13 +14,13 @@ public class ModelLibrary { /** * The list of all successfully loaded models in this library. */ - private final List models; + private final List models; /** * The default model for this library (e.g., the first successfully * loaded model in the list). */ - private static ConfigurationModel defaultModel; + private static Model defaultModel; /** * Base directory containing the model files. @@ -29,16 +29,16 @@ public class ModelLibrary { /** * Constructs a library of AI models from the provided list of - * {@link ConfigurationModel}s, ignoring those whose paths do not exist. + * {@link Model}s, ignoring those whose paths do not exist. * * @param modelsBaseDirectory the root directory where model files are stored. * @param configModels a list of model configurations. */ - public ModelLibrary(File modelsBaseDirectory, List configModels) { + public ModelLibrary(File modelsBaseDirectory, List configModels) { this.modelsBaseDirectory = modelsBaseDirectory; this.models = new ArrayList<>(); - for (ConfigurationModel configModel : configModels) { + for (Model configModel : configModels) { addModel(configModel); } @@ -57,7 +57,7 @@ public class ModelLibrary { * @param model the model to add. * @throws RuntimeException if a model with the same alias already exists. */ - public void addModel(ConfigurationModel model) { + public void addModel(Model model) { if (findModelByAlias(model.getAlias()).isPresent()) { throw new RuntimeException("Model with alias \"" + model.getAlias() + "\" already exists!"); } @@ -67,7 +67,7 @@ public class ModelLibrary { /** * @return the list of loaded models in this library. */ - public List getModels() { + public List getModels() { return models; } @@ -77,7 +77,7 @@ public class ModelLibrary { * @param alias the model alias to look for. * @return an {@link Optional} describing the found model, or empty if none match. */ - public Optional findModelByAlias(String alias) { + public Optional findModelByAlias(String alias) { return models.stream() .filter(model -> model.getAlias().equals(alias)) .findFirst(); @@ -86,7 +86,7 @@ public class ModelLibrary { /** * @return the default model (first loaded model). */ - public ConfigurationModel getDefaultModel() { + public Model getDefaultModel() { return defaultModel; } @@ -95,13 +95,13 @@ public class ModelLibrary { */ public void printModels() { System.out.println("Available models:\n"); - for (ConfigurationModel model : models) { + for (Model model : models) { model.printModelDetails(); System.out.println(); } } - public String getModelFullFilesystemPath(ConfigurationModel model) { + public String getModelFullFilesystemPath(Model model) { return new File(modelsBaseDirectory, model.getFilesystemPath()).getAbsolutePath(); }