Skip to content

Commit

Permalink
other: Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Livila committed Feb 25, 2024
1 parent 5a3d7c7 commit 36a5316
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ dependencies {

tasks.test {
useJUnitPlatform()
}
}
11 changes: 8 additions & 3 deletions src/main/java/CodeCheck/LLM.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.hexadevlabs.gpt4all.LLModel;

import java.nio.file.Path;

import java.nio.file.Files;
import java.util.List;
import java.util.Map;
Expand All @@ -19,7 +21,7 @@ public void initModel() {
startTime = System.currentTimeMillis();

runIfConfig(() -> {
java.nio.file.Path modelPath = java.nio.file.Path.of(Util.checkIfHomePath(
Path modelPath = Path.of(Util.checkIfHomePath(
ConfigInterface.conf.getString("LLM_FILE")));

if (Files.isDirectory(modelPath)) {
Expand Down Expand Up @@ -49,8 +51,9 @@ public void cleanModel() {
try {
model.close();
} catch (Exception e) {
Log.error("LLM is not closing...");
throw new RuntimeException("LLM is not closing...", e);
String errorMessage = "LLM is not closing...";
Log.error(errorMessage);
throw new RuntimeException(errorMessage, e);
}
return true;
});
Expand All @@ -66,7 +69,9 @@ public String getAnswer(String question) {

return runIfConfig(() -> {
String answer = model.chatCompletion(createMessage(question), config).choices.toString();

Log.debug("Answer: " + answer);

return answer;
}).orElse("LLM has not been configured.");
}
Expand Down
19 changes: 3 additions & 16 deletions src/main/java/CodeCheck/Log.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void trace(String msg) {
static void log(String msg, ConfigInterface.Config.LoggingLevel lvl) {
ConfigInterface.Config.LoggingLevel logLvl = ConfigInterface.conf.getLogLvl();
if (logLvl.logOn(lvl)) {
logReduced("%s [%s] %s%n".formatted(
logReduced("%s [%s] %s".formatted(
LocalDateTime.now(),
lvl.name(),
msg),
Expand All @@ -67,7 +67,7 @@ static void log(String msg, Color color) {
);
}

static void logReduced(String msg, ConfigInterface.Config.LoggingLevel level, boolean newLine) {
static private void logReduced(String msg, ConfigInterface.Config.LoggingLevel level) {
Color colorLevel = switch (level) {
case NONE, N, OFF, O -> Color.NONE; // No change in color.
case ERROR, ERR, E -> Color.RED;
Expand All @@ -77,19 +77,6 @@ static void logReduced(String msg, ConfigInterface.Config.LoggingLevel level, bo
case TRACE, T -> Color.BLUE;
};

if (newLine) System.out.println(colorLevel + msg + Color.RESET);
else System.out.print(colorLevel + msg + Color.RESET);
}

static void logReduced(String msg, ConfigInterface.Config.LoggingLevel level) {
logReduced(msg, level, false);
}

static void logReduced(String msg) {
logReduced(msg, ConfigInterface.Config.LoggingLevel.INFO, false);
}

static void logReduced(String msg, Object... formatting) {
logReduced(String.format(msg, formatting), ConfigInterface.Config.LoggingLevel.INFO, false);
System.out.println(colorLevel + msg + Color.RESET);
}
}
3 changes: 0 additions & 3 deletions src/test/java/CheckDirectoryTest.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import CodeCheck.CheckDirectory;
import CodeCheck.Log;
import CodeCheck.ManyFunctions;
import CodeCheck.Util;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.nio.file.FileSystems;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class CheckDirectoryTest {
@Test
Expand Down

0 comments on commit 36a5316

Please sign in to comment.