mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-09-16 03:39:05 +02:00
Enhance CI workflow and refactor integration tests
- Added setup step for Ollama installation in the GitHub Actions workflow. - Updated environment variables for integration tests to utilize an external Ollama host. - Refactored test method names in OllamaAPIIntegrationTest for clarity and consistency, changing 'testAskModel' to 'testGenerate'. - Introduced new tests for image processing from URLs and files, while removing outdated tests for improved test suite relevance.
This commit is contained in:
parent
c705432510
commit
0ec20d14b0
7
.github/workflows/run-tests.yml
vendored
7
.github/workflows/run-tests.yml
vendored
@ -20,6 +20,10 @@ jobs:
|
||||
with:
|
||||
ref: ${{ github.event.inputs.branch }}
|
||||
|
||||
- name: Set up Ollama
|
||||
run: |
|
||||
curl -fsSL https://ollama.com/install.sh | sh
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
@ -33,3 +37,6 @@ jobs:
|
||||
|
||||
- name: Run integration tests
|
||||
run: mvn clean verify -Pintegration-tests
|
||||
env:
|
||||
USE_EXTERNAL_OLLAMA_HOST: "true"
|
||||
OLLAMA_HOST: "http://localhost:11434"
|
@ -1,11 +1,13 @@
|
||||
package io.github.ollama4j.utils;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
@ -15,7 +17,7 @@ public class Utils {
|
||||
private static ObjectMapper objectMapper;
|
||||
|
||||
public static ObjectMapper getObjectMapper() {
|
||||
if(objectMapper == null) {
|
||||
if (objectMapper == null) {
|
||||
objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
}
|
||||
@ -35,4 +37,9 @@ public class Utils {
|
||||
return out.toByteArray();
|
||||
}
|
||||
}
|
||||
|
||||
public static File getFileFromClasspath(String fileName) {
|
||||
ClassLoader classLoader = Utils.class.getClassLoader();
|
||||
return new File(Objects.requireNonNull(classLoader.getResource(fileName)).getFile());
|
||||
}
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void testAskModelWithStructuredOutput()
|
||||
void testGenerateWithStructuredOutput()
|
||||
throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
|
||||
api.pullModel(GENERAL_PURPOSE_MODEL);
|
||||
|
||||
@ -184,7 +184,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(6)
|
||||
void testAskModelWithDefaultOptions()
|
||||
void testGennerateModelWithDefaultOptions()
|
||||
throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
|
||||
api.pullModel(GENERAL_PURPOSE_MODEL);
|
||||
boolean raw = false;
|
||||
@ -199,7 +199,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(7)
|
||||
void testAskModelWithDefaultOptionsStreamed()
|
||||
void testGenerateWithDefaultOptionsStreamed()
|
||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||
api.pullModel(GENERAL_PURPOSE_MODEL);
|
||||
boolean raw = false;
|
||||
@ -222,7 +222,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(8)
|
||||
void testAskModelWithOptions() throws OllamaBaseException, IOException, URISyntaxException,
|
||||
void testGenerateWithOptions() throws OllamaBaseException, IOException, URISyntaxException,
|
||||
InterruptedException, ToolInvocationException {
|
||||
api.pullModel(GENERAL_PURPOSE_MODEL);
|
||||
|
||||
@ -305,46 +305,6 @@ class OllamaAPIIntegrationTest {
|
||||
.contains("6"), "Response should contain '6'");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void testChatWithImageFromURL() throws OllamaBaseException, IOException, InterruptedException,
|
||||
URISyntaxException, ToolInvocationException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
|
||||
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(VISION_MODEL);
|
||||
OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
|
||||
"What's in the picture?", Collections.emptyList(),
|
||||
"https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg")
|
||||
.build();
|
||||
api.registerAnnotatedTools(new OllamaAPIIntegrationTest());
|
||||
|
||||
OllamaChatResult chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void testChatWithImageFromFileWithHistoryRecognition() throws OllamaBaseException, IOException,
|
||||
URISyntaxException, InterruptedException, ToolInvocationException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(VISION_MODEL);
|
||||
OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
|
||||
"What's in the picture?", Collections.emptyList(),
|
||||
List.of(getImageFileFromClasspath("emoji-smile.jpeg"))).build();
|
||||
|
||||
OllamaChatResult chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
assertNotNull(chatResult.getResponseModel());
|
||||
builder.reset();
|
||||
|
||||
requestModel = builder.withMessages(chatResult.getChatHistory())
|
||||
.withMessage(OllamaChatMessageRole.USER, "What's the color?").build();
|
||||
|
||||
chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
assertNotNull(chatResult.getResponseModel());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(11)
|
||||
void testChatWithExplicitToolDefinition() throws OllamaBaseException, IOException, URISyntaxException,
|
||||
@ -617,9 +577,49 @@ class OllamaAPIIntegrationTest {
|
||||
+ chatResult.getResponseModel().getMessage().getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void testChatWithImageFromURL() throws OllamaBaseException, IOException, InterruptedException,
|
||||
URISyntaxException, ToolInvocationException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
|
||||
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(VISION_MODEL);
|
||||
OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
|
||||
"What's in the picture?", Collections.emptyList(),
|
||||
"https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg")
|
||||
.build();
|
||||
api.registerAnnotatedTools(new OllamaAPIIntegrationTest());
|
||||
|
||||
OllamaChatResult chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void testChatWithImageFromFileWithHistoryRecognition() throws OllamaBaseException, IOException,
|
||||
URISyntaxException, InterruptedException, ToolInvocationException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(VISION_MODEL);
|
||||
OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
|
||||
"What's in the picture?", Collections.emptyList(),
|
||||
List.of(getImageFileFromClasspath("emoji-smile.jpeg"))).build();
|
||||
|
||||
OllamaChatResult chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
assertNotNull(chatResult.getResponseModel());
|
||||
builder.reset();
|
||||
|
||||
requestModel = builder.withMessages(chatResult.getChatHistory())
|
||||
.withMessage(OllamaChatMessageRole.USER, "What's the color?").build();
|
||||
|
||||
chatResult = api.chat(requestModel);
|
||||
assertNotNull(chatResult);
|
||||
assertNotNull(chatResult.getResponseModel());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(17)
|
||||
void testAskModelWithOptionsAndImageURLs()
|
||||
void testGenerateWithOptionsAndImageURLs()
|
||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
|
||||
@ -633,7 +633,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(18)
|
||||
void testAskModelWithOptionsAndImageFiles()
|
||||
void testGenerateWithOptionsAndImageFiles()
|
||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
File imageFile = getImageFileFromClasspath("roses.jpg");
|
||||
@ -650,7 +650,7 @@ class OllamaAPIIntegrationTest {
|
||||
|
||||
@Test
|
||||
@Order(20)
|
||||
void testAskModelWithOptionsAndImageFilesStreamed()
|
||||
void testGenerateWithOptionsAndImageFilesStreamed()
|
||||
throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
|
||||
api.pullModel(VISION_MODEL);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user