import java.util.*;
import java.util.stream.Collectors;
+import static eu.svjatoslav.alyverkko_cli.Utils.printRedMessageToConsole;
import static eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper.getConfigurationFile;
import static eu.svjatoslav.alyverkko_cli.configuration.ConfigurationHelper.loadConfiguration;
-import static eu.svjatoslav.commons.cli_helper.CLIHelper.askBoolean;
-import static eu.svjatoslav.commons.cli_helper.CLIHelper.askFloat;
-import static eu.svjatoslav.commons.cli_helper.CLIHelper.askInteger;
+import static eu.svjatoslav.commons.cli_helper.CLIHelper.*;
import static java.lang.Boolean.TRUE;
/**
if (modelsDir == null || !modelsDir.isDirectory() || !modelsDir.exists()) {
System.out.println("Models directory is missing or invalid.");
String defaultVal = (modelsDir == null) ? "~/.config/alyverkko-cli/models" : modelsDir.getPath();
- String userInput = CLIHelper.askString(
+ String userInput = askString(
"Enter the models directory path (where your .gguf files are located)",
defaultVal
);
if (!modelsDir.exists()) {
boolean created = modelsDir.mkdirs();
if (!created) {
- Utils.printRedMessageToConsole("Failed to create models directory. Check permissions?");
+ printRedMessageToConsole("Failed to create models directory. Check permissions?");
}
}
} else {
if (promptsDir == null || !promptsDir.isDirectory() || !promptsDir.exists()) {
System.out.println("Prompts directory is missing or invalid.");
String defaultVal = (promptsDir == null) ? "~/.config/alyverkko-cli/prompts" : promptsDir.getPath();
- String userInput = CLIHelper.askString(
+ String userInput = askString(
"Enter the prompts directory path",
defaultVal
);
if (!promptsDir.exists()) {
boolean created = promptsDir.mkdirs();
if (!created) {
- Utils.printRedMessageToConsole("Failed to create prompts directory. Check permissions?");
+ printRedMessageToConsole("Failed to create prompts directory. Check permissions?");
}
}
} else {
if (!valid) {
System.out.println("The 'llama-cli' executable path is missing or invalid.");
String defaultVal = (llamaCli == null) ? "/usr/local/bin/llama-cli" : llamaCli.getPath();
- String userInput = CLIHelper.askString(
+ String userInput = askString(
"Enter the path to the llama-cli executable",
defaultVal
);
config.setBatchThreadCount(newBatchCount);
}
+ /**
+ * Checks if the mail directory is defined and it exists.
+ * If not, prompts the user to define and optionally create it.
+ */
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");
+ "It should be a directory that you can write to.\n\nCurrent mail directory is: " + describeValue(config.getMailDirectory()));
// 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();
+ if (mailDir == null) {
+ String userInput = askString(
+ "Enter the desired mail directory path",
+ null, null, null, false);
+ mailDir = new File(userInput);
+ } else {
String userInput = CLIHelper.askString(
- "Enter the mail directory path (will create if it doesn't exist)",
- defaultVal
- );
+ "Enter the desired mail directory path or press ENTER to keep the current one",
+ mailDir.toString()
+ , null, null, false);
mailDir = new File(userInput);
- config.setMailDirectory(mailDir);
+ }
+ config.setMailDirectory(mailDir);
- // Attempt to create if not exist
- if (!mailDir.exists()) {
+ // Attempt to create if not exist
+ if (!mailDir.exists()) {
+ if (CLIHelper.askBoolean("Specified mail directory does not exist. Create it?", true)) {
boolean created = mailDir.mkdirs();
if (!created) {
- Utils.printRedMessageToConsole("Failed to create mail directory. Check permissions?");
+ printRedMessageToConsole("Failed to create mail directory. Check permissions?");
+ } else {
+ System.out.println("Mail directory created at: " + mailDir.getAbsolutePath());
+ return;
}
}
} 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
+ return;
}
}
}
if (askBoolean("Would you like to add this model?", false)) {
ConfigurationModel cm = new ConfigurationModel();
- cm.setAlias(CLIHelper.askString("Enter alias for this model", guessAlias));
+ cm.setAlias(askString("Enter alias for this model", guessAlias));
cm.setFilesystemPath(relativePath);
int ctxSize = askInteger(
"Enter context size in tokens (e.g. 64000).",
private void addModelsManually() {
System.out.println("\nNow you can add models manually, if you wish.");
while (true) {
- String alias = CLIHelper.askString("Enter model alias (leave empty to finish adding models): ");
+ String alias = askString("Enter model alias (leave empty to finish adding models): ");
if (StringUtils.isBlank(alias)) {
break;
}
- String filePath = CLIHelper.askString("Enter filesystem path relative to models directory: ");
+ String filePath = askString("Enter filesystem path relative to models directory: ");
if (StringUtils.isBlank(filePath)) {
System.out.println("Skipping because no path given.");
continue;
boolean alreadyExists = config.getModels().stream()
.anyMatch(m -> m.getAlias().equals(alias));
if (alreadyExists) {
- Utils.printRedMessageToConsole("Model with alias '" + alias + "' already exists! Skipping.");
+ printRedMessageToConsole("Model with alias '" + alias + "' already exists! Skipping.");
continue;
}
}
System.out.println("\nConfiguration saved to: " + configFile.toPath());
} catch (IOException e) {
- Utils.printRedMessageToConsole("Error saving configuration: " + e.getMessage());
+ printRedMessageToConsole("Error saving configuration: " + e.getMessage());
}
}
return alias.replaceAll("-+", "-").replaceAll("^-|-$", "");
}
+ public String describeValue(Object value){
+ if (value == null ) {
+ return "<undefined>";
+ }
+
+ return value.toString();
+ }
+
}