mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-10-28 15:10:40 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00288053bf | ||
|
|
6a7feb98bd | ||
|
|
770d511067 | ||
|
|
b57fc1f818 | ||
|
|
01c5a8f07f | ||
|
|
243b8a3747 |
4
.github/workflows/maven-publish.yml
vendored
4
.github/workflows/maven-publish.yml
vendored
@@ -49,6 +49,10 @@ jobs:
|
|||||||
${{ runner.os }}-maven-
|
${{ runner.os }}-maven-
|
||||||
- name: Build
|
- name: Build
|
||||||
run: mvn -B -ntp clean install
|
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
|
- name: Publish to GitHub Packages Apache Maven
|
||||||
# if: >
|
# if: >
|
||||||
# github.event_name != 'pull_request' &&
|
# github.event_name != 'pull_request' &&
|
||||||
|
|||||||
58
README.md
58
README.md
@@ -2,8 +2,33 @@
|
|||||||
|
|
||||||
<img src='https://raw.githubusercontent.com/amithkoujalgi/ollama4j/65a9d526150da8fcd98e2af6a164f055572bf722/ollama4j.jpeg' width='100' alt="ollama4j-icon">
|
<img src='https://raw.githubusercontent.com/amithkoujalgi/ollama4j/65a9d526150da8fcd98e2af6a164f055572bf722/ollama4j.jpeg' width='100' alt="ollama4j-icon">
|
||||||
|
|
||||||
A Java library (wrapper/binding)
|
A Java library (wrapper/binding) for [Ollama](https://ollama.ai/) server.
|
||||||
for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
|
|
||||||
|
Find more details on the [website](https://amithkoujalgi.github.io/ollama4j/).
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## 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
|
```mermaid
|
||||||
flowchart LR
|
flowchart LR
|
||||||
@@ -17,26 +42,6 @@ for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||

|
|
||||||
|
|
||||||
## 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
|
#### Requirements
|
||||||
|
|
||||||

|

|
||||||
@@ -64,7 +69,7 @@ In your Maven project, add this dependency:
|
|||||||
</dependency>
|
</dependency>
|
||||||
```
|
```
|
||||||
|
|
||||||
Latest release:
|
Latest release:
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -76,7 +81,7 @@ Latest release:
|
|||||||
|
|
||||||
#### API Spec
|
#### 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
|
#### Development
|
||||||
|
|
||||||
@@ -117,6 +122,7 @@ Actions CI workflow.
|
|||||||
- [x] Use lombok
|
- [x] Use lombok
|
||||||
- [x] Update request body creation with Java objects
|
- [x] Update request body creation with Java objects
|
||||||
- [ ] Async APIs for images
|
- [ ] Async APIs for images
|
||||||
|
- [ ] Add custom headers to requests
|
||||||
- [ ] Add additional params for `ask` APIs such as:
|
- [ ] Add additional params for `ask` APIs such as:
|
||||||
- `options`: additional model parameters for the Modelfile such as `temperature`
|
- `options`: additional model parameters for the Modelfile such as `temperature`
|
||||||
- `system`: system prompt to (overrides what is defined in the Modelfile)
|
- `system`: system prompt to (overrides what is defined in the Modelfile)
|
||||||
@@ -138,3 +144,7 @@ of contribution is much appreciated.
|
|||||||
|
|
||||||
The nomenclature and the icon have been adopted from the incredible [Ollama](https://ollama.ai/)
|
The nomenclature and the icon have been adopted from the incredible [Ollama](https://ollama.ai/)
|
||||||
project.
|
project.
|
||||||
|
|
||||||
|
### References
|
||||||
|
|
||||||
|
- [Ollama REST APIs](https://github.com/jmorganca/ollama/blob/main/docs/api.md)
|
||||||
6
pom.xml
6
pom.xml
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>io.github.amithkoujalgi</groupId>
|
<groupId>io.github.amithkoujalgi</groupId>
|
||||||
<artifactId>ollama4j</artifactId>
|
<artifactId>ollama4j</artifactId>
|
||||||
<version>1.0.32</version>
|
<version>1.0.34</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.32</tag>
|
<tag>v1.0.34</tag>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -154,7 +154,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>ch.qos.logback</groupId>
|
<groupId>ch.qos.logback</groupId>
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.3.11</version>
|
<version>1.4.12</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -331,12 +331,12 @@ public class OllamaAPI {
|
|||||||
* Ask a question to a model running on Ollama server. This is a sync/blocking call.
|
* 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 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
|
* @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 {
|
throws OllamaBaseException, IOException, InterruptedException {
|
||||||
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
|
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt);
|
||||||
return askSync(ollamaRequestModel);
|
return askSync(ollamaRequestModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,11 +346,11 @@ public class OllamaAPI {
|
|||||||
* async/non-blocking call.
|
* async/non-blocking call.
|
||||||
*
|
*
|
||||||
* @param model the ollama model to ask the question to
|
* @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
|
* @return the ollama async result callback handle
|
||||||
*/
|
*/
|
||||||
public OllamaAsyncResultCallback askAsync(String model, String promptText) {
|
public OllamaAsyncResultCallback askAsync(String model, String prompt) {
|
||||||
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText);
|
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt);
|
||||||
|
|
||||||
URI uri = URI.create(this.host + "/api/generate");
|
URI uri = URI.create(this.host + "/api/generate");
|
||||||
OllamaAsyncResultCallback ollamaAsyncResultCallback =
|
OllamaAsyncResultCallback ollamaAsyncResultCallback =
|
||||||
@@ -365,17 +365,17 @@ public class OllamaAPI {
|
|||||||
* sync/blocking call.
|
* sync/blocking call.
|
||||||
*
|
*
|
||||||
* @param model the ollama model to ask the question to
|
* @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
|
* @param imageFiles the list of image files to use for the question
|
||||||
* @return OllamaResult that includes response text and time taken for response
|
* @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 {
|
throws OllamaBaseException, IOException, InterruptedException {
|
||||||
List<String> images = new ArrayList<>();
|
List<String> images = new ArrayList<>();
|
||||||
for (File imageFile : imageFiles) {
|
for (File imageFile : imageFiles) {
|
||||||
images.add(encodeFileToBase64(imageFile));
|
images.add(encodeFileToBase64(imageFile));
|
||||||
}
|
}
|
||||||
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText, images);
|
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt, images);
|
||||||
return askSync(ollamaRequestModel);
|
return askSync(ollamaRequestModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,17 +384,17 @@ public class OllamaAPI {
|
|||||||
* sync/blocking call.
|
* sync/blocking call.
|
||||||
*
|
*
|
||||||
* @param model the ollama model to ask the question to
|
* @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
|
* @param imageURLs the list of image URLs to use for the question
|
||||||
* @return OllamaResult that includes response text and time taken for response
|
* @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 {
|
throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
|
||||||
List<String> images = new ArrayList<>();
|
List<String> images = new ArrayList<>();
|
||||||
for (String imageURL : imageURLs) {
|
for (String imageURL : imageURLs) {
|
||||||
images.add(encodeByteArrayToBase64(loadImageBytesFromUrl(imageURL)));
|
images.add(encodeByteArrayToBase64(loadImageBytesFromUrl(imageURL)));
|
||||||
}
|
}
|
||||||
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, promptText, images);
|
OllamaRequestModel ollamaRequestModel = new OllamaRequestModel(model, prompt, images);
|
||||||
return askSync(ollamaRequestModel);
|
return askSync(ollamaRequestModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user