Refactor imports and add fields to OllamaStructuredResult

Reorders and deduplicates import statements across multiple files for consistency and clarity. Adds additional fields to OllamaStructuredResult and ensures OllamaResult is populated with these fields. Updates tests and minor code style improvements throughout the codebase.
This commit is contained in:
amithkoujalgi
2025-08-31 16:46:32 +05:30
parent 4de3d98b79
commit b216d1b647
36 changed files with 136 additions and 136 deletions

View File

@@ -24,7 +24,6 @@ import java.io.FileWriter;
import java.io.IOException;
import java.net.URISyntaxException;
import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,9 +41,8 @@ public class WithAuth {
private static final String OLLAMA_VERSION = "0.6.1";
private static final String NGINX_VERSION = "nginx:1.23.4-alpine";
private static final String BEARER_AUTH_TOKEN = "secret-token";
private static final String GENERAL_PURPOSE_MODEL = "gemma3:270m";
private static final String THINKING_MODEL = "gpt-oss:20b";
// private static final String THINKING_MODEL = "gpt-oss:20b";
private static OllamaContainer ollama;
@@ -52,7 +50,7 @@ public class WithAuth {
private static OllamaAPI api;
@BeforeAll
public static void setUp() {
static void setUp() {
ollama = createOllamaContainer();
ollama.start();
@@ -135,14 +133,14 @@ public class WithAuth {
@Test
@Order(1)
void testOllamaBehindProxy() throws InterruptedException {
void testOllamaBehindProxy() {
api.setBearerAuth(BEARER_AUTH_TOKEN);
assertTrue(api.ping(), "Expected OllamaAPI to successfully ping through NGINX with valid auth token.");
}
@Test
@Order(1)
void testWithWrongToken() throws InterruptedException {
void testWithWrongToken() {
api.setBearerAuth("wrong-token");
assertFalse(api.ping(), "Expected OllamaAPI ping to fail through NGINX with an invalid auth token.");
}
@@ -152,8 +150,8 @@ public class WithAuth {
void testAskModelWithStructuredOutput()
throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
api.setBearerAuth(BEARER_AUTH_TOKEN);
api.pullModel(THINKING_MODEL);
String model = GENERAL_PURPOSE_MODEL;
api.pullModel(model);
String prompt = "The sun is shining brightly and is directly overhead at the zenith, casting my shadow over my foot, so it must be noon.";
@@ -170,7 +168,7 @@ public class WithAuth {
});
format.put("required", List.of("isNoon"));
OllamaResult result = api.generate(THINKING_MODEL, prompt, format);
OllamaResult result = api.generate(model, prompt, format);
assertNotNull(result);
assertNotNull(result.getResponse());

View File

@@ -21,7 +21,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.Mockito.*;
class TestMockedAPIs {

View File

@@ -1,11 +1,12 @@
package io.github.ollama4j.unittests.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.ollama4j.utils.Utils;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
public abstract class AbstractSerializationTest<T> {
protected ObjectMapper mapper = Utils.getObjectMapper();

View File

@@ -1,20 +1,19 @@
package io.github.ollama4j.unittests.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import io.github.ollama4j.models.chat.OllamaChatMessageRole;
import io.github.ollama4j.models.chat.OllamaChatRequest;
import io.github.ollama4j.models.chat.OllamaChatRequestBuilder;
import io.github.ollama4j.utils.OptionsBuilder;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.util.Collections;
import java.util.List;
import io.github.ollama4j.models.chat.OllamaChatRequest;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.github.ollama4j.models.chat.OllamaChatMessageRole;
import io.github.ollama4j.models.chat.OllamaChatRequestBuilder;
import io.github.ollama4j.utils.OptionsBuilder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
public class TestChatRequestSerialization extends AbstractSerializationTest<OllamaChatRequest> {

View File

@@ -1,12 +1,12 @@
package io.github.ollama4j.unittests.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import io.github.ollama4j.models.embeddings.OllamaEmbedRequestBuilder;
import io.github.ollama4j.models.embeddings.OllamaEmbedRequestModel;
import io.github.ollama4j.utils.OptionsBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.github.ollama4j.utils.OptionsBuilder;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestEmbedRequestSerialization extends AbstractSerializationTest<OllamaEmbedRequestModel> {

View File

@@ -1,15 +1,13 @@
package io.github.ollama4j.unittests.jackson;
import static org.junit.jupiter.api.Assertions.assertEquals;
import io.github.ollama4j.models.generate.OllamaGenerateRequest;
import io.github.ollama4j.models.generate.OllamaGenerateRequestBuilder;
import io.github.ollama4j.utils.OptionsBuilder;
import org.json.JSONObject;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import io.github.ollama4j.models.generate.OllamaGenerateRequestBuilder;
import io.github.ollama4j.utils.OptionsBuilder;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class TestGenerateRequestSerialization extends AbstractSerializationTest<OllamaGenerateRequest> {