Code refactoring. Plan for fixing QwQ.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 20 Mar 2025 22:42:24 +0000 (00:42 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Thu, 20 Mar 2025 22:42:24 +0000 (00:42 +0200)
doc/QwQ-32B Termination issue.odt [new file with mode: 0644]
pom.xml
src/main/java/eu/svjatoslav/alyverkko_cli/commands/WizardCommand.java

diff --git a/doc/QwQ-32B Termination issue.odt b/doc/QwQ-32B Termination issue.odt
new file mode 100644 (file)
index 0000000..c230de4
Binary files /dev/null and b/doc/QwQ-32B Termination issue.odt differ
diff --git a/pom.xml b/pom.xml
index d237d39..44b02f6 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -26,7 +26,7 @@
         <dependency>
             <groupId>eu.svjatoslav</groupId>
             <artifactId>cli-helper</artifactId>
-            <version>1.2</version>
+            <version>1.3-SNAPSHOT</version>
         </dependency>
         <dependency>
             <groupId>org.testng</groupId>
index 9f00a24..9ccbff6 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Scanner;
 import java.util.stream.Collectors;
 
 import static eu.svjatoslav.alyverkko_cli.configuration.Configuration.DEFAULT_CONFIG_FILE_PATH;
+import static eu.svjatoslav.commons.cli_helper.CLIHelper.*;
 
 public class WizardCommand implements Command {
 
@@ -82,7 +83,7 @@ public class WizardCommand implements Command {
         config.setLlamaCliPath(new File(llamaCliPath));
 
         // Default Temperature
-        float defaultTemp = getFloatInputWithDefault(
+        float defaultTemp = askFloat(
                 "\nEnter default temperature (0-2). A lower value makes the AI more deterministic, while a higher value makes it more creative.",
                 existingConfig != null ? existingConfig.getDefaultTemperature() : 0.7f,
                 0f, 2f
@@ -90,7 +91,7 @@ public class WizardCommand implements Command {
         config.setDefaultTemperature(defaultTemp);
 
         // Thread Counts
-        int threadCount = getIntInputWithDefault(
+        int threadCount = askInteger(
                 "\nEnter number of CPU threads for AI response generation. " +
                         "RAM data transfer speed is usually the bottleneck here. " +
                         "On a typical PC, while you might have 12 CPU cores, " +
@@ -102,7 +103,7 @@ public class WizardCommand implements Command {
         );
         config.setThreadCount(threadCount);
 
-        int batchThreadCount = getIntInputWithDefault(
+        int batchThreadCount = askInteger(
                 "\nEnter number of CPU threads for input prompt processing. " +
                         "CPU computing power is usually the bottleneck here (not the RAM bandwidth). " +
                         "So you can utilize all CPU cores that you have here.",
@@ -118,14 +119,13 @@ public class WizardCommand implements Command {
             models.addAll(existingConfig.getModels());
         }
 
-        String choice = getInput("Would you like to try to autodiscover available models ?", "Y");
-        if (choice.equalsIgnoreCase("Y")) {
+        if (askBoolean("Would you like to try to autodiscover available undefined models ?", true)) {
             discoverAndSuggestNewModels(config.getModelsDirectory(), models);
         }
 
         System.out.println("\nYou can now add models manually.");
         while (true) {
-            String alias = getInput("Enter desired model alias (leave empty to finish adding models): ");
+            String alias = askString("Enter desired model alias (leave empty to finish adding models): ");
             if (StringUtils.isBlank(alias)) break;
 
             String filePath = getInputWithDefault(
@@ -134,7 +134,7 @@ public class WizardCommand implements Command {
                     null
             );
 
-            int contextSize = getIntInputWithDefault(
+            int contextSize = askInteger(
                     "\nEnter context size in tokens. A higher value allows the model to remember more context.",
                     64000,
                     1024,
@@ -153,8 +153,7 @@ public class WizardCommand implements Command {
         // Write configuration
         Path configPath = Path.of(DEFAULT_CONFIG_FILE_PATH);
         if (Files.exists(configPath) && !forceOption.isPresent()) {
-            String confirm = getInput("Configuration file already exists. Overwrite? (y/N)", "N");
-            if (!confirm.equalsIgnoreCase("Y")) {
+            if (!askBoolean("Configuration file already exists. Overwrite?", false)) {
                 System.out.println("Configuration not saved. Run with --force to overwrite.");
                 return;
             }
@@ -185,42 +184,6 @@ public class WizardCommand implements Command {
         return input.isEmpty() ? defaultValue : input;
     }
 
-    private float getFloatInputWithDefault(String prompt, float defaultValue, float min, float max) {
-        while (true) {
-            String input = getInput(prompt, String.valueOf(defaultValue));
-            try {
-                float value = Float.parseFloat(input);
-                if (value >= min && value <= max) return value;
-                System.out.println("Value must be between " + min + " and " + max);
-            } catch (NumberFormatException e) {
-                System.out.println("Invalid number format. Try again.");
-            }
-        }
-    }
-
-    private int getIntInputWithDefault(String prompt, int defaultValue, Integer min, Integer max) {
-        while (true) {
-            String input = getInput(prompt, String.valueOf(defaultValue));
-            try {
-                int value = Integer.parseInt(input);
-
-                if (max != null && value > max) {
-                    System.out.println("Value must be less than or equal to " + max);
-                    continue;
-                }
-
-                if (min != null && value < min) {
-                    System.out.println("Value must be greater than or equal to " + min);
-                    continue;
-                }
-
-                return value;
-            } catch (NumberFormatException e) {
-                System.out.println("Invalid number format. Try again.");
-            }
-        }
-    }
-
     private void discoverAndSuggestNewModels(File modelsDir, List<ConfigurationModel> existingModels) {
         if (!modelsDir.exists()) {
             System.out.println("Models directory does not exist. Please create it first.");
@@ -256,13 +219,11 @@ public class WizardCommand implements Command {
         String alias = suggestAlias(relativePath);
         System.out.println("\nFound new model: " + relativePath);
         System.out.println("Suggested alias: " + alias);
-        String choice = getInput("Would you like to add this model? (y/N) ", "N");
-        if (choice.equalsIgnoreCase("Y")) {
+        if (askBoolean("Would you like to add this model? (y/N) ", false)) {
             ConfigurationModel model = new ConfigurationModel();
             model.setAlias(alias);
             model.setFilesystemPath(relativePath);
-            int contextSize = getIntInputWithDefault(
-                    "\nEnter context size in tokens. A higher value allows the model to remember more context.",
+            int contextSize = askInteger("\nEnter context size in tokens. A higher value allows the model to remember more context.",
                     64000,
                     1024,
                     null
@@ -279,14 +240,5 @@ public class WizardCommand implements Command {
         return alias.replaceAll("-+", "-").replaceAll("^-|-$", "");
     }
 
-    private String getInput(String prompt, String defaultValue) {
-        Scanner scanner = new Scanner(System.in);
-        System.out.print(prompt + (defaultValue != null ? " [" + defaultValue + "]" : "") + ": ");
-        String input = scanner.nextLine().trim();
-        return input.isEmpty() && defaultValue != null ? defaultValue : input;
-    }
 
-    private String getInput(String prompt) {
-        return getInput(prompt, null);
-    }
 }
\ No newline at end of file