mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-11-04 10:30:41 +01:00
Add Javadoc generation to Makefile and refactor model classes
- Introduced a new `javadoc` target in the Makefile to generate Javadocs. - Refactored model classes: renamed `ModelsProcessResponse` to `ModelProcessesResponse` and updated related references. - Updated `OllamaEmbedRequestModel` and `OllamaEmbedResponseModel` to `OllamaEmbedRequest` and `OllamaEmbedResponse`, respectively, across the codebase. - Added new classes for `OllamaEmbedRequest` and `OllamaEmbedResponse` to improve clarity and maintainability.
This commit is contained in:
@@ -15,8 +15,8 @@ import io.github.ollama4j.exceptions.OllamaException;
|
||||
import io.github.ollama4j.impl.ConsoleOutputChatTokenHandler;
|
||||
import io.github.ollama4j.impl.ConsoleOutputGenerateTokenHandler;
|
||||
import io.github.ollama4j.models.chat.*;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequestModel;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedResponseModel;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequest;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedResponse;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateRequest;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateRequestBuilder;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateStreamObserver;
|
||||
@@ -231,10 +231,10 @@ class OllamaAPIIntegrationTest {
|
||||
@Order(5)
|
||||
void shouldReturnEmbeddings() throws Exception {
|
||||
api.pullModel(EMBEDDING_MODEL);
|
||||
OllamaEmbedRequestModel m = new OllamaEmbedRequestModel();
|
||||
OllamaEmbedRequest m = new OllamaEmbedRequest();
|
||||
m.setModel(EMBEDDING_MODEL);
|
||||
m.setInput(Arrays.asList("Why is the sky blue?", "Why is the grass green?"));
|
||||
OllamaEmbedResponseModel embeddings = api.embed(m);
|
||||
OllamaEmbedResponse embeddings = api.embed(m);
|
||||
assertNotNull(embeddings, "Embeddings should not be null");
|
||||
assertFalse(embeddings.getEmbeddings().isEmpty(), "Embeddings should not be empty");
|
||||
}
|
||||
@@ -1328,12 +1328,12 @@ class OllamaAPIIntegrationTest {
|
||||
void shouldReturnEmbeddingsForSingleInput() throws Exception {
|
||||
api.pullModel(EMBEDDING_MODEL);
|
||||
|
||||
OllamaEmbedRequestModel requestModel = new OllamaEmbedRequestModel();
|
||||
OllamaEmbedRequest requestModel = new OllamaEmbedRequest();
|
||||
requestModel.setModel(EMBEDDING_MODEL);
|
||||
requestModel.setInput(
|
||||
Collections.singletonList("This is a single test sentence for embedding."));
|
||||
|
||||
OllamaEmbedResponseModel embeddings = api.embed(requestModel);
|
||||
OllamaEmbedResponse embeddings = api.embed(requestModel);
|
||||
|
||||
assertNotNull(embeddings);
|
||||
assertFalse(embeddings.getEmbeddings().isEmpty());
|
||||
|
||||
@@ -16,8 +16,8 @@ import io.github.ollama4j.OllamaAPI;
|
||||
import io.github.ollama4j.exceptions.OllamaException;
|
||||
import io.github.ollama4j.exceptions.RoleNotFoundException;
|
||||
import io.github.ollama4j.models.chat.OllamaChatMessageRole;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequestModel;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedResponseModel;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequest;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedResponse;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateRequest;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateRequestBuilder;
|
||||
import io.github.ollama4j.models.generate.OllamaGenerateStreamObserver;
|
||||
@@ -109,10 +109,10 @@ class TestMockedAPIs {
|
||||
String model = "llama2";
|
||||
String prompt = "some prompt text";
|
||||
try {
|
||||
OllamaEmbedRequestModel m = new OllamaEmbedRequestModel();
|
||||
OllamaEmbedRequest m = new OllamaEmbedRequest();
|
||||
m.setModel(model);
|
||||
m.setInput(List.of(prompt));
|
||||
when(ollamaAPI.embed(m)).thenReturn(new OllamaEmbedResponseModel());
|
||||
when(ollamaAPI.embed(m)).thenReturn(new OllamaEmbedResponse());
|
||||
ollamaAPI.embed(m);
|
||||
verify(ollamaAPI, times(1)).embed(m);
|
||||
} catch (OllamaException e) {
|
||||
@@ -126,8 +126,8 @@ class TestMockedAPIs {
|
||||
String model = "llama2";
|
||||
List<String> inputs = List.of("some prompt text");
|
||||
try {
|
||||
OllamaEmbedRequestModel m = new OllamaEmbedRequestModel(model, inputs);
|
||||
when(ollamaAPI.embed(m)).thenReturn(new OllamaEmbedResponseModel());
|
||||
OllamaEmbedRequest m = new OllamaEmbedRequest(model, inputs);
|
||||
when(ollamaAPI.embed(m)).thenReturn(new OllamaEmbedResponse());
|
||||
ollamaAPI.embed(m);
|
||||
verify(ollamaAPI, times(1)).embed(m);
|
||||
} catch (OllamaException e) {
|
||||
@@ -141,10 +141,10 @@ class TestMockedAPIs {
|
||||
String model = "llama2";
|
||||
List<String> inputs = List.of("some prompt text");
|
||||
try {
|
||||
when(ollamaAPI.embed(new OllamaEmbedRequestModel(model, inputs)))
|
||||
.thenReturn(new OllamaEmbedResponseModel());
|
||||
ollamaAPI.embed(new OllamaEmbedRequestModel(model, inputs));
|
||||
verify(ollamaAPI, times(1)).embed(new OllamaEmbedRequestModel(model, inputs));
|
||||
when(ollamaAPI.embed(new OllamaEmbedRequest(model, inputs)))
|
||||
.thenReturn(new OllamaEmbedResponse());
|
||||
ollamaAPI.embed(new OllamaEmbedRequest(model, inputs));
|
||||
verify(ollamaAPI, times(1)).embed(new OllamaEmbedRequest(model, inputs));
|
||||
} catch (OllamaException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,10 @@ class TestOptionsAndUtils {
|
||||
void testOptionsBuilderRejectsUnsupportedCustomType() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> new OptionsBuilder().setCustomOption("bad", new Object()));
|
||||
() -> {
|
||||
OptionsBuilder builder = new OptionsBuilder();
|
||||
builder.setCustomOption("bad", new Object());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -10,13 +10,13 @@ package io.github.ollama4j.unittests.jackson;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequest;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequestBuilder;
|
||||
import io.github.ollama4j.models.embed.OllamaEmbedRequestModel;
|
||||
import io.github.ollama4j.utils.OptionsBuilder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class TestEmbedRequestSerialization extends AbstractSerializationTest<OllamaEmbedRequestModel> {
|
||||
class TestEmbedRequestSerialization extends AbstractSerializationTest<OllamaEmbedRequest> {
|
||||
|
||||
private OllamaEmbedRequestBuilder builder;
|
||||
|
||||
@@ -27,20 +27,18 @@ class TestEmbedRequestSerialization extends AbstractSerializationTest<OllamaEmbe
|
||||
|
||||
@Test
|
||||
public void testRequestOnlyMandatoryFields() {
|
||||
OllamaEmbedRequestModel req = builder.build();
|
||||
OllamaEmbedRequest req = builder.build();
|
||||
String jsonRequest = serialize(req);
|
||||
assertEqualsAfterUnmarshalling(
|
||||
deserialize(jsonRequest, OllamaEmbedRequestModel.class), req);
|
||||
assertEqualsAfterUnmarshalling(deserialize(jsonRequest, OllamaEmbedRequest.class), req);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRequestWithOptions() {
|
||||
OptionsBuilder b = new OptionsBuilder();
|
||||
OllamaEmbedRequestModel req = builder.withOptions(b.setMirostat(1).build()).build();
|
||||
OllamaEmbedRequest req = builder.withOptions(b.setMirostat(1).build()).build();
|
||||
|
||||
String jsonRequest = serialize(req);
|
||||
OllamaEmbedRequestModel deserializeRequest =
|
||||
deserialize(jsonRequest, OllamaEmbedRequestModel.class);
|
||||
OllamaEmbedRequest deserializeRequest = deserialize(jsonRequest, OllamaEmbedRequest.class);
|
||||
assertEqualsAfterUnmarshalling(deserializeRequest, req);
|
||||
assertEquals(1, deserializeRequest.getOptions().get("mirostat"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user