Compare commits

...

17 Commits

Author SHA1 Message Date
amithkoujalgi
1d6af26857 [maven-release-plugin] prepare release v1.0.37 2023-12-30 08:48:45 +00:00
Amith Koujalgi
14d18d731f Fixed javadoc 2023-12-30 14:17:36 +05:30
amithkoujalgi
c8d7cbbc2c [maven-release-plugin] prepare for next development iteration 2023-12-30 08:34:44 +00:00
amithkoujalgi
ef4303fbbb [maven-release-plugin] prepare release v1.0.36 2023-12-30 08:34:42 +00:00
Amith Koujalgi
2df9a9c69b Merge remote-tracking branch 'origin/main' 2023-12-30 14:03:41 +05:30
Amith Koujalgi
6bb5d9f644 Added CodeCov setup 2023-12-30 14:03:34 +05:30
amithkoujalgi
94b221248a [maven-release-plugin] prepare for next development iteration 2023-12-30 08:29:50 +00:00
amithkoujalgi
2a887f5015 [maven-release-plugin] prepare release v1.0.35 2023-12-30 08:29:49 +00:00
Amith Koujalgi
7e3dddf1bb Merge remote-tracking branch 'origin/main'
# Conflicts:
#	pom.xml
2023-12-30 13:58:38 +05:30
Amith Koujalgi
fe95a7df2a Added CodeCov setup 2023-12-30 13:56:35 +05:30
amithkoujalgi
98f6a30c6b [maven-release-plugin] prepare for next development iteration 2023-12-30 08:12:45 +00:00
amithkoujalgi
00288053bf [maven-release-plugin] prepare release v1.0.34 2023-12-30 08:12:43 +00:00
Amith Koujalgi
6a7feb98bd Added CodeCov setup 2023-12-30 13:41:33 +05:30
amithkoujalgi
770d511067 [maven-release-plugin] prepare for next development iteration 2023-12-30 06:54:50 +00:00
amithkoujalgi
b57fc1f818 [maven-release-plugin] prepare release v1.0.33 2023-12-30 06:54:48 +00:00
Amith Koujalgi
01c5a8f07f updated readme 2023-12-30 12:23:42 +05:30
amithkoujalgi
243b8a3747 [maven-release-plugin] prepare for next development iteration 2023-12-29 04:56:21 +00:00
6 changed files with 331 additions and 272 deletions

View File

@@ -49,6 +49,10 @@ jobs:
${{ runner.os }}-maven-
- name: Build
run: mvn -B -ntp clean install
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
- name: Publish to GitHub Packages Apache Maven
# if: >
# github.event_name != 'pull_request' &&

View File

@@ -2,8 +2,35 @@
<img src='https://raw.githubusercontent.com/amithkoujalgi/ollama4j/65a9d526150da8fcd98e2af6a164f055572bf722/ollama4j.jpeg' width='100' alt="ollama4j-icon">
A Java library (wrapper/binding)
for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
A Java library (wrapper/binding) for [Ollama](https://ollama.ai/) server.
Find more details on the [website](https://amithkoujalgi.github.io/ollama4j/).
![GitHub stars](https://img.shields.io/github/stars/amithkoujalgi/ollama4j)
![GitHub forks](https://img.shields.io/github/forks/amithkoujalgi/ollama4j)
![GitHub watchers](https://img.shields.io/github/watchers/amithkoujalgi/ollama4j)
![GitHub repo size](https://img.shields.io/github/repo-size/amithkoujalgi/ollama4j)
![GitHub language count](https://img.shields.io/github/languages/count/amithkoujalgi/ollama4j)
![GitHub top language](https://img.shields.io/github/languages/top/amithkoujalgi/ollama4j)
![GitHub last commit](https://img.shields.io/github/last-commit/amithkoujalgi/ollama4j?color=green)
![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Famithkoujalgi%2Follama4j&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)
[![codecov](https://codecov.io/gh/amithkoujalgi/ollama4j/graph/badge.svg?token=U0TE7BGP8L)](https://codecov.io/gh/amithkoujalgi/ollama4j)
![Build Status](https://github.com/amithkoujalgi/ollama4j/actions/workflows/maven-publish.yml/badge.svg)
## Table of Contents
- [How does it work?](#how-does-it-work)
- [Requirements](#requirements)
- [Installation](#installation)
- [API Spec](#api-spec)
- [Demo APIs](#try-out-the-apis-with-ollama-server)
- [Development](#development)
- [Contributions](#get-involved)
- [References](#references)
#### How does it work?
```mermaid
flowchart LR
@@ -17,26 +44,6 @@ for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
end
```
![Build Status](https://github.com/amithkoujalgi/ollama4j/actions/workflows/maven-publish.yml/badge.svg)
![GitHub stars](https://img.shields.io/github/stars/amithkoujalgi/ollama4j?style=social)
![GitHub forks](https://img.shields.io/github/forks/amithkoujalgi/ollama4j?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/amithkoujalgi/ollama4j?style=social)
![GitHub repo size](https://img.shields.io/github/repo-size/amithkoujalgi/ollama4j?style=plastic)
![GitHub language count](https://img.shields.io/github/languages/count/amithkoujalgi/ollama4j?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/amithkoujalgi/ollama4j?style=plastic)
![GitHub last commit](https://img.shields.io/github/last-commit/amithkoujalgi/ollama4j?color=red&style=plastic)
![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Famithkoujalgi%2Follama4j&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)
## Table of Contents
- [Requirements](#requirements)
- [Installation](#installation)
- [API Spec](#api-spec)
- [Demo APIs](#try-out-the-apis-with-ollama-server)
- [Development](#development)
- [Contributions](#get-involved)
#### Requirements
![Java](https://img.shields.io/badge/Java-11_+-green.svg?style=just-the-message&labelColor=gray)
@@ -76,7 +83,7 @@ Latest release:
#### API Spec
Find the full `Javadoc` (API specifications) [here](https://amithkoujalgi.github.io/ollama4j/).
Find the full API specifications on the [website](https://amithkoujalgi.github.io/ollama4j/).
#### Development
@@ -117,6 +124,7 @@ Actions CI workflow.
- [x] Use lombok
- [x] Update request body creation with Java objects
- [ ] Async APIs for images
- [ ] Add custom headers to requests
- [ ] Add additional params for `ask` APIs such as:
- `options`: additional model parameters for the Modelfile such as `temperature`
- `system`: system prompt to (overrides what is defined in the Modelfile)
@@ -138,3 +146,7 @@ of contribution is much appreciated.
The nomenclature and the icon have been adopted from the incredible [Ollama](https://ollama.ai/)
project.
### References
- [Ollama REST APIs](https://github.com/jmorganca/ollama/blob/main/docs/api.md)

49
pom.xml
View File

@@ -4,7 +4,7 @@
<groupId>io.github.amithkoujalgi</groupId>
<artifactId>ollama4j</artifactId>
<version>1.0.32</version>
<version>1.0.37</version>
<name>Ollama4j</name>
<description>Java library for interacting with Ollama API.</description>
@@ -39,7 +39,7 @@
<connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection>
<developerConnection>scm:git:https://github.com/amithkoujalgi/ollama4j.git</developerConnection>
<url>https://github.com/amithkoujalgi/ollama4j</url>
<tag>v1.0.32</tag>
<tag>v1.0.37</tag>
</scm>
<build>
@@ -154,7 +154,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.3.11</version>
<version>1.4.12</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -198,6 +198,29 @@
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>integration-tests</id>
@@ -249,6 +272,26 @@
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

View File

@@ -331,12 +331,12 @@ public class OllamaAPI {
* Ask a question to a model running on Ollama server. This is a sync/blocking call.
*
* @param model the ollama model to ask the question to
* @param promptText the prompt/question text
* @param prompt the prompt/question text
* @return OllamaResult that includes response text and time taken for response
*/
public OllamaResult ask(String model, String promptText)
public OllamaResult ask(String model, String prompt)
throws OllamaBaseException, IOException, InterruptedException {
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt);
return askSync(ollamaRequestModel);
}
@@ -346,11 +346,11 @@ public class OllamaAPI {
* async/non-blocking call.
*
* @param model the ollama model to ask the question to
* @param promptText the prompt/question text
* @param prompt the prompt/question text
* @return the ollama async result callback handle
*/
public OllamaAsyncResultCallback askAsync(String model, String promptText) {
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
public OllamaAsyncResultCallback askAsync(String model, String prompt) {
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt);
URI uri = URI.create(this.host + "/api/generate");
OllamaAsyncResultCallback ollamaAsyncResultCallback =
@@ -365,17 +365,17 @@ public class OllamaAPI {
* sync/blocking call.
*
* @param model the ollama model to ask the question to
* @param promptText the prompt/question text
* @param prompt the prompt/question text
* @param imageFiles the list of image files to use for the question
* @return OllamaResult that includes response text and time taken for response
*/
public OllamaResult askWithImageFiles(String model, String promptText, List<File> imageFiles)
public OllamaResult askWithImageFiles(String model, String prompt, List<File> imageFiles)
throws OllamaBaseException, IOException, InterruptedException {
List<String> images = new ArrayList<>();
for (File imageFile : imageFiles) {
images.add(encodeFileToBase64(imageFile));
}
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText, images);
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt, images);
return askSync(ollamaRequestModel);
}
@@ -384,17 +384,17 @@ public class OllamaAPI {
* sync/blocking call.
*
* @param model the ollama model to ask the question to
* @param promptText the prompt/question text
* @param prompt the prompt/question text
* @param imageURLs the list of image URLs to use for the question
* @return OllamaResult that includes response text and time taken for response
*/
public OllamaResult askWithImageURLs(String model, String promptText, List<String> imageURLs)
public OllamaResult askWithImageURLs(String model, String prompt, List<String> imageURLs)
throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
List<String> images = new ArrayList<>();
for (String imageURL : imageURLs) {
images.add(encodeByteArrayToBase64(loadImageBytesFromUrl(imageURL)));
}
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText, images);
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt, images);
return askSync(ollamaRequestModel);
}

View File

@@ -123,9 +123,9 @@ public class OllamaAsyncResultCallback extends Thread {
}
/**
* Returns the final response when the execution completes. Does not return intermediate results.
* Returns the final completion/response when the execution completes. Does not return intermediate results.
*
* @return String - response text
* @return String completion/response text
*/
public String getResponse() {
return result;

View File

@@ -13,9 +13,9 @@ import lombok.Getter;
public class OllamaResult {
/**
* -- GETTER --
* Get the response text
* Get the completion/response text
*
* @return String - response text
* @return String completion/response text
*/
private final String response;