Compare commits

..

11 Commits

Author SHA1 Message Date
amithkoujalgi
44bb35b168 [maven-release-plugin] prepare release v1.0.50 2024-02-10 05:13:09 +00:00
Amith Koujalgi
9832caf503 Update intg test class 2024-02-10 10:41:53 +05:30
amithkoujalgi
24674ea483 [maven-release-plugin] prepare for next development iteration 2024-02-09 18:19:37 +00:00
amithkoujalgi
5d3a975e4c [maven-release-plugin] prepare release v1.0.49 2024-02-09 18:19:36 +00:00
Amith Koujalgi
ad670c3c62 Merge pull request #22 from AgentSchmecker/bugfix/add_model_property_to_model_api
Adds model property to Model Type
2024-02-09 23:48:36 +05:30
Markus Klenke
5e2a07ad41 Adds model property to Model Type 2024-02-09 16:54:09 +00:00
amithkoujalgi
9636807819 [maven-release-plugin] prepare for next development iteration 2024-02-09 06:39:34 +00:00
amithkoujalgi
455251d1d4 [maven-release-plugin] prepare release v1.0.48 2024-02-09 06:39:33 +00:00
Amith Koujalgi
ec00ffae7f Merge pull request #21 from AgentSchmecker/main
Correction of Documentation for ask-async
2024-02-09 12:08:33 +05:30
Markus Klenke
d969c7ad46 Fixes currently not working code snippet for ask-async doc 2024-02-08 22:52:41 +00:00
amithkoujalgi
02bf769188 [maven-release-plugin] prepare for next development iteration 2024-02-01 14:39:21 +00:00
5 changed files with 46 additions and 30 deletions

View File

@@ -24,8 +24,8 @@ public class Main {
while (!callback.isComplete() || !callback.getStream().isEmpty()) { while (!callback.isComplete() || !callback.getStream().isEmpty()) {
// poll for data from the response stream // poll for data from the response stream
String result = callback.getStream().poll(); String result = callback.getStream().poll();
if (response != null) { if (result != null) {
System.out.print(result.getResponse()); System.out.print(result);
} }
Thread.sleep(100); Thread.sleep(100);
} }

View File

@@ -4,7 +4,7 @@
<groupId>io.github.amithkoujalgi</groupId> <groupId>io.github.amithkoujalgi</groupId>
<artifactId>ollama4j</artifactId> <artifactId>ollama4j</artifactId>
<version>1.0.47</version> <version>1.0.50</version>
<name>Ollama4j</name> <name>Ollama4j</name>
<description>Java library for interacting with Ollama API.</description> <description>Java library for interacting with Ollama API.</description>
@@ -39,7 +39,7 @@
<connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection> <connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection>
<developerConnection>scm:git:https://github.com/amithkoujalgi/ollama4j.git</developerConnection> <developerConnection>scm:git:https://github.com/amithkoujalgi/ollama4j.git</developerConnection>
<url>https://github.com/amithkoujalgi/ollama4j</url> <url>https://github.com/amithkoujalgi/ollama4j</url>
<tag>v1.0.47</tag> <tag>v1.0.50</tag>
</scm> </scm>
<build> <build>

View File

@@ -7,6 +7,7 @@ import lombok.Data;
public class Model { public class Model {
private String name; private String name;
private String model;
@JsonProperty("modified_at") @JsonProperty("modified_at")
private String modifiedAt; private String modifiedAt;
private String digest; private String digest;

View File

@@ -5,7 +5,6 @@ import static org.junit.jupiter.api.Assertions.*;
import io.github.amithkoujalgi.ollama4j.core.OllamaAPI; import io.github.amithkoujalgi.ollama4j.core.OllamaAPI;
import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException; import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException;
import io.github.amithkoujalgi.ollama4j.core.models.OllamaResult; 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 io.github.amithkoujalgi.ollama4j.core.utils.OptionsBuilder;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -16,26 +15,14 @@ import java.net.http.HttpConnectTimeoutException;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.Properties; import java.util.Properties;
import lombok.Data;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
class TestRealAPIs { class TestRealAPIs {
OllamaAPI ollamaAPI; OllamaAPI ollamaAPI;
Config config;
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);
}
}
private File getImageFileFromClasspath(String fileName) { private File getImageFileFromClasspath(String fileName) {
ClassLoader classLoader = getClass().getClassLoader(); ClassLoader classLoader = getClass().getClassLoader();
@@ -44,9 +31,9 @@ class TestRealAPIs {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
Properties properties = loadProperties(); config = new Config();
ollamaAPI = new OllamaAPI(properties.getProperty("ollama.api.url")); ollamaAPI = new OllamaAPI(config.getOllamaURL());
ollamaAPI.setRequestTimeoutSeconds(20); ollamaAPI.setRequestTimeoutSeconds(config.getRequestTimeoutSeconds());
} }
@Test @Test
@@ -85,10 +72,10 @@ class TestRealAPIs {
void testPullModel() { void testPullModel() {
testEndpointReachability(); testEndpointReachability();
try { try {
ollamaAPI.pullModel(OllamaModelType.LLAMA2); ollamaAPI.pullModel(config.getModel());
boolean found = boolean found =
ollamaAPI.listModels().stream() ollamaAPI.listModels().stream()
.anyMatch(model -> model.getModelName().equals(OllamaModelType.LLAMA2)); .anyMatch(model -> model.getModel().equalsIgnoreCase(config.getModel()));
assertTrue(found); assertTrue(found);
} catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) { } catch (IOException | OllamaBaseException | InterruptedException | URISyntaxException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
@@ -102,7 +89,7 @@ class TestRealAPIs {
try { try {
OllamaResult result = OllamaResult result =
ollamaAPI.generate( ollamaAPI.generate(
OllamaModelType.LLAMA2, config.getModel(),
"What is the capital of France? And what's France's connection with Mona Lisa?", "What is the capital of France? And what's France's connection with Mona Lisa?",
new OptionsBuilder().build()); new OptionsBuilder().build());
assertNotNull(result); assertNotNull(result);
@@ -120,7 +107,7 @@ class TestRealAPIs {
try { try {
OllamaResult result = OllamaResult result =
ollamaAPI.generate( ollamaAPI.generate(
OllamaModelType.LLAMA2, config.getModel(),
"What is the capital of France? And what's France's connection with Mona Lisa?", "What is the capital of France? And what's France's connection with Mona Lisa?",
new OptionsBuilder().setTemperature(0.9f).build()); new OptionsBuilder().setTemperature(0.9f).build());
assertNotNull(result); assertNotNull(result);
@@ -139,7 +126,7 @@ class TestRealAPIs {
try { try {
OllamaResult result = OllamaResult result =
ollamaAPI.generateWithImageFiles( ollamaAPI.generateWithImageFiles(
OllamaModelType.LLAVA, config.getImageModel(),
"What is in this image?", "What is in this image?",
List.of(imageFile), List.of(imageFile),
new OptionsBuilder().build()); new OptionsBuilder().build());
@@ -158,7 +145,7 @@ class TestRealAPIs {
try { try {
OllamaResult result = OllamaResult result =
ollamaAPI.generateWithImageURLs( ollamaAPI.generateWithImageURLs(
OllamaModelType.LLAVA, config.getImageModel(),
"What is in this image?", "What is in this image?",
List.of( List.of(
"https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg"), "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);
}
}
}

View File

@@ -1,2 +1,4 @@
ollama.api.url=http://192.168.29.223:11434 ollama.url=http://localhost:11434
ollama.model=llava ollama.model=qwen:0.5b
ollama.model.image=llava
ollama.request-timeout-seconds=120