Specify llama.cpp project directory instead of executable path.
mail_directory: "/home/user/AI/mail"
models_directory: "/home/user/AI/models"
default_temperature: 0.7
- llama_cpp_executable_path: "/home/user/AI/llama.cpp/main"
+ llama_cpp_dir_path: "/home/user/AI/llama.cpp/"
batch_thread_count: 10
thread_count: 6
models:
creative or random.
- Default value: 0.7
-- llama_cpp_executable_path :: Specifies the file path to the
- *llama.cpp* *main* executable.
- - Example Value: /home/user/AI/llama.cpp/main
+- llama_cpp_dir_path :: Specifies the filesystem path to the cloned
+ and compiled *llama.cpp* directory.
+ - Example Value: /home/user/AI/llama.cpp/
- This option is mandatory.
- batch_thread_count :: Specifies the number of threads to use for
in-progress computation. Unix process stop and continue signals
could possibly be used.
-- Add support for speculative decoding to speed up inference.
-
- Explain how to monitor system performance and resource usage during
AI processing tasks.
package eu.svjatoslav.alyverkko_cli;
import eu.svjatoslav.alyverkko_cli.commands.MailQuery;
-import eu.svjatoslav.alyverkko_cli.model.Model;
import java.io.*;
import java.nio.file.Files;
public static final String AI_RESPONSE_MARKER = "ASSISTANT:";
private static final String LLAMA_CPP_META_INFO_MARKER = "llm_load_print_meta: ";
- private final Model model;
+ MailQuery mailQuery;
private final Float temperature;
- private final String systemPrompt;
- private final String userPrompt;
File inputFile;
/**
* Creates a new AI task.
*/
public AiTask(MailQuery mailQuery) {
- this.model = mailQuery.model;
+ this.mailQuery = mailQuery;
this.temperature = configuration.getDefaultTemperature();
- this.systemPrompt = mailQuery.systemPrompt;
- this.userPrompt = mailQuery.userPrompt;
}
private String buildAiQuery() {
StringBuilder sb = new StringBuilder();
- sb.append("SYSTEM:\n").append(systemPrompt).append("\n");
+ sb.append("SYSTEM:\n").append(mailQuery.systemPrompt).append("\n");
- String filteredUserPrompt = filterParticipantsInUserInput(userPrompt);
+ String filteredUserPrompt = filterParticipantsInUserInput(mailQuery.userPrompt);
if (!filteredUserPrompt.startsWith("USER:")) sb.append("USER:\n");
sb.append(filteredUserPrompt).append("\n");
int niceValue = 10; // Set the desired niceness level (10 is a common value for background tasks)
+ String executablePath = configuration.getLlamaCppDirPath().getAbsolutePath();
+ if (!executablePath.endsWith("/")) executablePath += "/";
+
+ executablePath += "main";
+
return join(" ",
"nice", "-n", Integer.toString(niceValue),
- configuration.getLlamaCppExecutablePath().getAbsolutePath(),
- "--model " + model.filesystemPath,
+ executablePath,
+ "--model " + mailQuery.model.filesystemPath,
"--threads " + configuration.getThreadCount(),
"--threads-batch " + configuration.getBatchThreadCount(),
"--mirostat 2",
"--log-disable",
"--temp " + temperature,
- "--ctx-size " + model.contextSizeTokens,
+ "--ctx-size " + mailQuery.model.contextSizeTokens,
"--batch-size 8",
"-n -1",
"--repeat_penalty 1.1",
}
// remove text after end of text marker, if it exists
- if (model.endOfTextMarker != null) {
- int endOfTextMarkerIndex = result.indexOf(model.endOfTextMarker);
+ if (mailQuery.model.endOfTextMarker != null) {
+ int endOfTextMarkerIndex = result.indexOf(mailQuery.model.endOfTextMarker);
if (endOfTextMarkerIndex != -1) {
result = result.substring(0, endOfTextMarkerIndex);
}
}
+
return result + "\n";
}
// Parse TOCOMPUTE line for inference settings
String firstLine = inputFileContent.substring(0, firstNewLineIndex);
Map<String, String> settings = parseSettings(firstLine);
- String systemPromptAlias = settings.getOrDefault("prompt", "default");
- String modelAlias = settings.getOrDefault("model", "default");
- mailQuery.systemPrompt = configuration.getPromptByAlias(systemPromptAlias);
- Optional<Model> modelOptional = modelLibrary.findModelByAlias(modelAlias);
- if (!modelOptional.isPresent()) {
- throw new IllegalArgumentException("Model with alias '" + modelAlias + "' not found.");
+ mailQuery.systemPrompt = configuration.getPromptByAlias(settings.getOrDefault("prompt", "default"));
+
+ { // resolve model
+ String modelAlias = settings.getOrDefault("model", "default");
+ Optional<Model> modelOptional = modelLibrary.findModelByAlias(modelAlias);
+ if (!modelOptional.isPresent())
+ throw new IllegalArgumentException("Model with alias '" + modelAlias + "' not found.");
+ mailQuery.model = modelOptional.get();
}
- mailQuery.model = modelOptional.get();
+
return mailQuery;
}
}
// Validate llama.cpp executable path
- if (!Main.configuration.getLlamaCppExecutablePath().exists() || !Main.configuration.getLlamaCppExecutablePath().isFile()) {
- System.err.println("llama.cpp executable not found at: " + Main.configuration.getLlamaCppExecutablePath());
+ if (!Main.configuration.getLlamaCppDirPath().exists() || !Main.configuration.getLlamaCppDirPath().isDirectory()) {
+ System.err.println("llama.cpp project directory not found at: " + Main.configuration.getLlamaCppDirPath());
return;
}
import java.io.*;
import java.util.List;
-import java.util.Map;
public class Configuration {
@JsonProperty("default_temperature")
private float defaultTemperature;
- @JsonProperty("llama_cpp_executable_path")
- private File llamaCppExecutablePath;
+ @JsonProperty("llama_cpp_dir_path")
+ private File llamaCppDirPath;
@JsonProperty("batch_thread_count")
private int batchThreadCount;
this.defaultTemperature = defaultTemperature;
}
- public File getLlamaCppExecutablePath() {
- return llamaCppExecutablePath;
+ public File getLlamaCppDirPath() {
+ return llamaCppDirPath;
}
- public void setLlamaCppExecutablePath(File llamaCppExecutablePath) {
- this.llamaCppExecutablePath = llamaCppExecutablePath;
+ public void setLlamaCppDirPath(File llamaCppDirPath) {
+ this.llamaCppDirPath = llamaCppDirPath;
}
public int getBatchThreadCount() {
public void setEndOfTextMarker(String endOfTextMarker) {
this.endOfTextMarker = endOfTextMarker;
}
+
}
models = new ArrayList<>();
- for (ConfigurationModel configModel : configModels) {
- addModelFromConfig(configModel);
- }
+ for (ConfigurationModel configModel : configModels) addModelFromConfig(configModel);
if (models.isEmpty())
throw new RuntimeException("No models are defined!");