A Java library (wrapper/binding) for Ollama server.
Find more details on the website.
flowchart LR
o4j[Ollama4j]
o[Ollama Server]
o4j -->|Communicates with| o;
m[Models]
subgraph Ollama Deployment
direction TB
o -->|Manages| m
end
Note
We have migrated the package repository from Maven Central to GitHub package repository due to technical issues with publishing. Please update your repository settings to get latest version of Ollama4j.
Track the releases here and update the dependency version according to your requirements.
Using JitPack
- Add
jitpack.io
repository to your project'spom.xml
or yoursettings.xml
:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
- In your Maven project, add this dependency:
<dependency>
<groupId>io.github.amithkoujalgi</groupId>
<artifactId>ollama4j</artifactId>
<version>1.0.74</version>
</dependency>
- Add
GitHub Maven Packages
repository to your project'spom.xml
or yoursettings.xml
:
<repositories>
<repository>
<id>github</id>
<name>GitHub Apache Maven Packages</name>
<url>https://maven.pkg.github.com/amithkoujalgi/ollama4j</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
- Add
GitHub
server to settings.xml. (Usually available at ~/.m2/settings.xml)
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>github</id>
<username>YOUR-USERNAME</username>
<password>YOUR-TOKEN</password>
</server>
</servers>
</settings>
- In your Maven project, add this dependency:
<dependency>
<groupId>io.github.amithkoujalgi</groupId>
<artifactId>ollama4j</artifactId>
<version>1.0.74</version>
</dependency>
- Add the
JitPack
repository to your build file
Add it in your root build.gradle
at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
- Add the dependency
dependencies {
implementation 'com.github.amithkoujalgi:ollama4j:Tag'
}
Tip
Find the full API specifications on the website.
Build:
make build
Run unit tests:
make ut
Run integration tests:
make it
Newer artifacts are published via GitHub Actions CI workflow when a new release is created from main
branch.
Datafaker
: a library to generate fake dataVaadin Web UI
: UI-Tester for Interactions with Ollama via ollama4jollama-translator
: Minecraft 1.20.6 spigot plugin allows to easily break language barriers by using ollama on the server to translate all messages into a specfic target language.
- Use Java-naming conventions for attributes in the request/response models instead of the
snake-case conventions. (
possibly with Jackson-mapper's
@JsonProperty
) - Fix deprecated HTTP client code
- Setup logging
- Use lombok
- Update request body creation with Java objects
- Async APIs for images
- Support for function calling with models like Mistral
- generate in sync mode
- generate in async mode
- Add custom headers to requests
- Add additional params for
ask
APIs such as:-
options
: additional model parameters for the Modelfile such astemperature
- Supported params. -
system
: system prompt to (overrides what is defined in the Modelfile) -
template
: the full prompt or prompt template (overrides what is defined in the Modelfile) -
context
: the context parameter returned from a previous request, which can be used to keep a short conversational memory -
stream
: Add support for streaming responses from the model
-
- Add test cases
- Handle exceptions better (maybe throw more appropriate exceptions)
Contributions are most welcome! Whether it's reporting a bug, proposing an enhancement, or helping with code - any sort of contribution is much appreciated.
The nomenclature and the icon have been adopted from the incredible Ollama project.
Thanks to the amazing contributors