Remove deprecated embedding and library model classes

Deleted deprecated classes related to embeddings and library models, including OllamaEmbeddingResponseModel, OllamaEmbeddingsRequestBuilder, OllamaEmbeddingsRequestModel, LibraryModel, LibraryModelDetail, LibraryModelTag, and OllamaModelType. Updated OllamaAPI to remove references to these classes and improve documentation, exception handling, and code clarity.
This commit is contained in:
amithkoujalgi
2025-09-17 19:47:07 +05:30
parent 2f83a5c98c
commit 4df4ea1930
11 changed files with 300 additions and 612 deletions

View File

@@ -148,18 +148,30 @@ public class WithAuth {
@Order(1)
void testOllamaBehindProxy() {
api.setBearerAuth(BEARER_AUTH_TOKEN);
assertTrue(
api.ping(),
"Expected OllamaAPI to successfully ping through NGINX with valid auth token.");
try {
assertTrue(
api.ping(),
"Expected OllamaAPI to successfully ping through NGINX with valid auth token.");
} catch (Exception e) {
fail("Exception occurred while pinging OllamaAPI through NGINX: " + e.getMessage(), e);
}
}
@Test
@Order(1)
void testWithWrongToken() {
api.setBearerAuth("wrong-token");
assertFalse(
api.ping(),
"Expected OllamaAPI ping to fail through NGINX with an invalid auth token.");
try {
assertFalse(
api.ping(),
"Expected OllamaAPI ping to fail through NGINX with an invalid auth token.");
} catch (Exception e) {
// If an exception is thrown, that's also an expected failure for a wrong token
// (e.g., OllamaBaseException or IOException)
// Optionally, you can assert the type/message of the exception if needed
// For now, we treat any exception as a pass for this negative test
return;
}
}
@Test

View File

@@ -22,7 +22,8 @@ import io.github.ollama4j.models.request.CustomModelRequest;
import io.github.ollama4j.models.response.ModelDetail;
import io.github.ollama4j.models.response.OllamaAsyncResultStreamer;
import io.github.ollama4j.models.response.OllamaResult;
import io.github.ollama4j.types.OllamaModelType;
import io.github.ollama4j.tools.Tools;
import io.github.ollama4j.tools.sampletools.WeatherTool;
import io.github.ollama4j.utils.OptionsBuilder;
import java.io.IOException;
import java.net.URISyntaxException;
@@ -36,7 +37,7 @@ class TestMockedAPIs {
@Test
void testPullModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
try {
doNothing().when(ollamaAPI).pullModel(model);
ollamaAPI.pullModel(model);
@@ -79,7 +80,7 @@ class TestMockedAPIs {
@Test
void testDeleteModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
try {
doNothing().when(ollamaAPI).deleteModel(model, true);
ollamaAPI.deleteModel(model, true);
@@ -89,10 +90,24 @@ class TestMockedAPIs {
}
}
@Test
void testRegisteredTools() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
doNothing().when(ollamaAPI).registerTools(Collections.emptyList());
ollamaAPI.registerTools(Collections.emptyList());
verify(ollamaAPI, times(1)).registerTools(Collections.emptyList());
List<Tools.ToolSpecification> toolSpecifications = new ArrayList<>();
toolSpecifications.add(new WeatherTool().getSpecification());
doNothing().when(ollamaAPI).registerTools(toolSpecifications);
ollamaAPI.registerTools(toolSpecifications);
verify(ollamaAPI, times(1)).registerTools(toolSpecifications);
}
@Test
void testGetModelDetails() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
try {
when(ollamaAPI.getModelDetails(model)).thenReturn(new ModelDetail());
ollamaAPI.getModelDetails(model);
@@ -105,7 +120,7 @@ class TestMockedAPIs {
@Test
void testGenerateEmbeddings() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
String prompt = "some prompt text";
try {
OllamaEmbedRequestModel m = new OllamaEmbedRequestModel();
@@ -122,7 +137,7 @@ class TestMockedAPIs {
@Test
void testEmbed() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
List<String> inputs = List.of("some prompt text");
try {
OllamaEmbedRequestModel m = new OllamaEmbedRequestModel(model, inputs);
@@ -137,7 +152,7 @@ class TestMockedAPIs {
@Test
void testEmbedWithEmbedRequestModel() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
List<String> inputs = List.of("some prompt text");
try {
when(ollamaAPI.embed(new OllamaEmbedRequestModel(model, inputs)))
@@ -152,7 +167,7 @@ class TestMockedAPIs {
@Test
void testAsk() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
String prompt = "some prompt text";
OptionsBuilder optionsBuilder = new OptionsBuilder();
try {
@@ -169,7 +184,7 @@ class TestMockedAPIs {
@Test
void testAskWithImageFiles() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
String prompt = "some prompt text";
try {
when(ollamaAPI.generateWithImages(
@@ -203,7 +218,7 @@ class TestMockedAPIs {
@Test
void testAskWithImageURLs() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
String prompt = "some prompt text";
try {
when(ollamaAPI.generateWithImages(
@@ -237,7 +252,7 @@ class TestMockedAPIs {
@Test
void testAskAsync() {
OllamaAPI ollamaAPI = Mockito.mock(OllamaAPI.class);
String model = OllamaModelType.LLAMA2;
String model = "llama2";
String prompt = "some prompt text";
when(ollamaAPI.generate(model, prompt, false, false))
.thenReturn(new OllamaAsyncResultStreamer(null, null, 3));