From 9832caf503d0333513cd5648f02f071aa1f19b26 Mon Sep 17 00:00:00 2001 From: Amith Koujalgi Date: Sat, 10 Feb 2024 10:41:53 +0530 Subject: [PATCH 1/3] Update intg test class --- .../integrationtests/TestRealAPIs.java | 61 +++++++++++-------- src/test/resources/test-config.properties | 6 +- 2 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java index 0218ae9..ac06204 100644 --- a/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java +++ b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java @@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.*; import io.github.amithkoujalgi.ollama4j.core.OllamaAPI; import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException; import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult; -import io.github.amithkoujalgi.ollama4j.core.types.OllamaModelType; import io.github.amithkoujalgi.ollama4j.core.utils.OptionsBuilder; import java.io.File; import java.io.IOException; @@ -16,26 +15,14 @@ import java.net.http.HttpConnectTimeoutException; import java.util.List; import java.util.Objects; import java.util.Properties; +import lombok.Data; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; class TestRealAPIs { OllamaAPI ollamaAPI; - - private Properties loadProperties() { - Properties properties = new Properties(); - try (InputStream input = - getClass().getClassLoader().getResourceAsStream("test-config.properties")) { - if (input == null) { - throw new RuntimeException("Sorry, unable to find test-config.properties"); - } - properties.load(input); - return properties; - } catch (IOException e) { - throw new RuntimeException("Error loading properties", e); - } - } + Config config; private File getImageFileFromClasspath(String fileName) { ClassLoader classLoader = getClass().getClassLoader(); @@ -44,9 +31,9 @@ class TestRealAPIs { @BeforeEach void setUp() { - Properties properties = loadProperties(); - ollamaAPI = new OllamaAPI(properties.getProperty("ollama.api.url")); - ollamaAPI.setRequestTimeoutSeconds(20); + config = new Config(); + ollamaAPI = new OllamaAPI(config.getOllamaURL()); + ollamaAPI.setRequestTimeoutSeconds(config.getRequestTimeoutSeconds()); } @Test @@ -85,10 +72,10 @@ class TestRealAPIs { void testPullModel() { testEndpointReachability(); try { - ollamaAPI.pullModel(OllamaModelType.LLAMA2); + ollamaAPI.pullModel(config.getModel()); boolean found = ollamaAPI.listModels().stream() - .anyMatch(model -> model.getModelName().equals(OllamaModelType.LLAMA2)); + .anyMatch(model -> model.getModel().equalsIgnoreCase(config.getModel())); assertTrue(found); } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) { throw new RuntimeException(e); @@ -102,7 +89,7 @@ class TestRealAPIs { try { OllamaResult result = ollamaAPI.generate( - OllamaModelType.LLAMA2, + config.getModel(), "What is the capital of France? And what's France's connection with Mona Lisa?", new OptionsBuilder().build()); assertNotNull(result); @@ -120,7 +107,7 @@ class TestRealAPIs { try { OllamaResult result = ollamaAPI.generate( - OllamaModelType.LLAMA2, + config.getModel(), "What is the capital of France? And what's France's connection with Mona Lisa?", new OptionsBuilder().setTemperature(0.9f).build()); assertNotNull(result); @@ -139,7 +126,7 @@ class TestRealAPIs { try { OllamaResult result = ollamaAPI.generateWithImageFiles( - OllamaModelType.LLAVA, + config.getImageModel(), "What is in this image?", List.of(imageFile), new OptionsBuilder().build()); @@ -158,7 +145,7 @@ class TestRealAPIs { try { OllamaResult result = ollamaAPI.generateWithImageURLs( - OllamaModelType.LLAVA, + config.getImageModel(), "What is in this image?", List.of( "https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg"), @@ -171,3 +158,29 @@ class TestRealAPIs { } } } + +@Data +class Config { + private String ollamaURL; + private String model; + private String imageModel; + private int requestTimeoutSeconds; + + public Config() { + Properties properties = new Properties(); + try (InputStream input = + getClass().getClassLoader().getResourceAsStream("test-config.properties")) { + if (input == null) { + throw new RuntimeException("Sorry, unable to find test-config.properties"); + } + properties.load(input); + this.ollamaURL = properties.getProperty("ollama.url"); + this.model = properties.getProperty("ollama.model"); + this.imageModel = properties.getProperty("ollama.model.image"); + this.requestTimeoutSeconds = + Integer.parseInt(properties.getProperty("ollama.request-timeout-seconds")); + } catch (IOException e) { + throw new RuntimeException("Error loading properties", e); + } + } +} diff --git a/src/test/resources/test-config.properties b/src/test/resources/test-config.properties index 1d5d55e..1bda263 100644 --- a/src/test/resources/test-config.properties +++ b/src/test/resources/test-config.properties @@ -1,2 +1,4 @@ -ollama.api.url=http://192.168.29.223:11434 -ollama.model=llava \ No newline at end of file +ollama.url=http://localhost:11434 +ollama.model=qwen:0.5b +ollama.model.image=llava +ollama.request-timeout-seconds=120 \ No newline at end of file From 44bb35b1685289fd24c7daa86debc271e1d94b80 Mon Sep 17 00:00:00 2001 From: amithkoujalgi Date: Sat, 10 Feb 2024 05:13:09 +0000 Subject: [PATCH 2/3] [maven-release-plugin] prepare release v1.0.50 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index b45a72f..d4258d3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.amithkoujalgi ollama4j - 1.0.50-SNAPSHOT + 1.0.50 Ollama4j Java library for interacting with Ollama API. @@ -39,7 +39,7 @@ scm:git:git@github.com:amithkoujalgi/ollama4j.git scm:git:https://github.com/amithkoujalgi/ollama4j.git https://github.com/amithkoujalgi/ollama4j - v1.0.16 + v1.0.50 From 38dca3cd0d925a32696c3228c180054e23b2e373 Mon Sep 17 00:00:00 2001 From: amithkoujalgi Date: Sat, 10 Feb 2024 05:13:11 +0000 Subject: [PATCH 3/3] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d4258d3..9fe4a08 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.github.amithkoujalgi ollama4j - 1.0.50 + 1.0.51-SNAPSHOT Ollama4j Java library for interacting with Ollama API. @@ -39,7 +39,7 @@ scm:git:git@github.com:amithkoujalgi/ollama4j.git scm:git:https://github.com/amithkoujalgi/ollama4j.git https://github.com/amithkoujalgi/ollama4j - v1.0.50 + v1.0.16