Refactor JSON logging and utility methods

Replaced manual pretty-printing of JSON in OllamaAPI with a new Utils.toJSON method for cleaner logging. Added private constructors to utility classes to prevent instantiation. Updated test and sample code for improved clarity and randomness.
This commit is contained in:
amithkoujalgi
2025-09-17 20:05:18 +05:30
parent 4df4ea1930
commit b1d3ee54a5
6 changed files with 16 additions and 12 deletions

View File

@@ -114,8 +114,7 @@ class OllamaAPIIntegrationTest {
@Test
@Order(1)
void testPing()
throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
void testPing() throws OllamaBaseException {
boolean pingResponse = api.ping();
assertTrue(pingResponse, "Ping should return true");
}

View File

@@ -11,6 +11,7 @@ package io.github.ollama4j.samples;
import io.github.ollama4j.tools.annotations.ToolProperty;
import io.github.ollama4j.tools.annotations.ToolSpec;
import java.math.BigDecimal;
import java.util.Random;
public class AnnotatedTool {
@@ -18,7 +19,8 @@ public class AnnotatedTool {
public String computeImportantConstant(
@ToolProperty(name = "noOfDigits", desc = "Number of digits that shall be returned")
Integer noOfDigits) {
return BigDecimal.valueOf((long) (Math.random() * 1000000L), noOfDigits).toString();
return BigDecimal.valueOf((long) (new Random().nextLong() * 1000000L), noOfDigits)
.toString();
}
@ToolSpec(desc = "Says hello to a friend!")