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 {
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
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, " +
);
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.",
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(
null
);
- int contextSize = getIntInputWithDefault(
+ int contextSize = askInteger(
"\nEnter context size in tokens. A higher value allows the model to remember more context.",
64000,
1024,
// 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;
}
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.");
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
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