From 9b506779415f10ff037b1d9e54e64dff39119e8b Mon Sep 17 00:00:00 2001 From: Svjatoslav Agejenko Date: Thu, 3 Apr 2025 00:26:58 +0300 Subject: [PATCH] Redesigning wizard. WIP --- .../alyverkko_cli/commands/WizardCommand.java | 113 +++++++++++------- 1 file changed, 68 insertions(+), 45 deletions(-) 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 3994ef7..b1da8c8 100644 --- a/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java +++ b/src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java @@ -69,17 +69,7 @@ public class WizardCommand implements Command { // 1. Load existing config if possible - File configFile = getConfigurationFile(configFileOption); - - if (configFile.exists() && configFile.isFile()) { - System.out.println("Found existing configuration at " + configFile.getAbsolutePath()); - System.out.println("I will check whether everything is valid, and if not, allow you to fix it.\n"); - config = loadConfiguration(configFile); - } else { - // If no config found, create a fresh one - System.out.println("No existing configuration found. Let's create one!\n"); - config = new Configuration(); - } + File configFile = loadOrCreateConfiguration(); // 2. Validate and fix each parameter checkAndFixAllParameters(); @@ -103,39 +93,26 @@ public class WizardCommand implements Command { } } + private File loadOrCreateConfiguration() throws IOException { + File configFile = getConfigurationFile(configFileOption); + + if (configFile.exists() && configFile.isFile()) { + System.out.println("Found existing configuration at " + configFile.getAbsolutePath()); + System.out.println("I will check whether everything is valid, and if not, allow you to fix it.\n"); + config = loadConfiguration(configFile); + } else { + // If no config found, create a fresh one + System.out.println("No existing configuration found. Let's create one!\n"); + config = new Configuration(); + } + return configFile; + } + /** * Step-by-step checking (and possibly fixing) of each main config parameter. */ private void checkAndFixAllParameters() { - // 2.1 mail_directory - while (true) { - File mailDir = config.getMailDirectory(); - if (mailDir == null || !mailDir.isDirectory() || !mailDir.exists()) { - System.out.println("Mail directory is missing or invalid."); - String defaultVal = (mailDir == null) ? "~/.config/alyverkko-cli/mail" : mailDir.getPath(); - String userInput = CLIHelper.askString( - "Enter the mail directory path (will create if it doesn't exist)", - defaultVal - ); - mailDir = new File(userInput); - config.setMailDirectory(mailDir); - - // Attempt to create if not exist - if (!mailDir.exists()) { - boolean created = mailDir.mkdirs(); - if (!created) { - Utils.printRedMessageToConsole("Failed to create mail directory. Check permissions?"); - } - } - } else { - // If valid, confirm or let user fix - if (askBoolean("Mail directory is: " + mailDir.getAbsolutePath() + " . Is this OK?", TRUE)) { - break; - } - // Otherwise loop around to let them reenter - config.setMailDirectory(null); // Force re-check - } - } + checkMailDirectory(); // 2.2 models_directory while (true) { @@ -222,8 +199,10 @@ public class WizardCommand implements Command { float newTemp = askFloat( "\nEnter default temperature (0-3). Lower => more deterministic, higher => more creative.", oldTemp, - 0f, 3f + 0f, 3f, false ); + + config.setDefaultTemperature(newTemp); // 2.6 thread_count @@ -234,7 +213,7 @@ public class WizardCommand implements Command { int newThreadCount = askInteger( "\nEnter number of CPU threads for AI generation. Typically 6 for a 12-core CPU, for example.", oldThreadCount, - 1, null + 1, null, false ); config.setThreadCount(newThreadCount); @@ -246,11 +225,55 @@ public class WizardCommand implements Command { int newBatchCount = askInteger( "\nEnter number of CPU threads for input prompt processing (all cores is often fine).", oldBatchThreadCount, - 1, null + 1, null, false ); config.setBatchThreadCount(newBatchCount); } + private void checkMailDirectory() { + System.out.println("Älyverkko-cli uses a 'mail' directory to store and discover tasks that it has to solve. " + + "AI generated solutions are appended at the end of the task file. " + + "Tt should be a directory that you can write to. Current mail directory is: "); + + System.out.println(config.getMailDirectory() + "\n"); + + // 2.1 mail_directory + while (true) { + File mailDir = config.getMailDirectory(); + if (mailDir == null || !mailDir.isDirectory() || !mailDir.exists()) { + System.out.println("Mail directory is missing or invalid."); + String defaultVal = (mailDir == null) ? "~/.config/alyverkko-cli/mail" : mailDir.getPath(); + String userInput = CLIHelper.askString( + "Enter the mail directory path (will create if it doesn't exist)", + defaultVal + ); + mailDir = new File(userInput); + config.setMailDirectory(mailDir); + + // Attempt to create if not exist + if (!mailDir.exists()) { + boolean created = mailDir.mkdirs(); + if (!created) { + Utils.printRedMessageToConsole("Failed to create mail directory. Check permissions?"); + } + } + } else { + + System.out.println("Mail directory is: " + mailDir.getAbsolutePath()); + + + System.out.println(" If you want to change it, please enter a new path."); + + // If valid, confirm or let user fix + if (askBoolean("Mail directory is: " + mailDir.getAbsolutePath() + " . Is this OK?", TRUE)) { + break; + } + // Otherwise loop around to let them reenter + config.setMailDirectory(null); // Force re-check + } + } + } + /** * Offer to remove model references in config if the file does not exist. * Then autodiscover new .gguf files and offer to add them. @@ -330,7 +353,7 @@ public class WizardCommand implements Command { cm.setFilesystemPath(relativePath); int ctxSize = askInteger( "Enter context size in tokens (e.g. 64000).", - 64000, 1024, 128000 + 64000, 1024, 128000, false ); cm.setContextSizeTokens(ctxSize); cm.setEndOfTextMarker(null); @@ -361,7 +384,7 @@ public class WizardCommand implements Command { } int contextSize = askInteger( "Enter context size in tokens (e.g. 64000).", - 64000, 1024, 128000 + 64000, 1024, 128000, false ); // Check for duplicates -- 2.20.1