Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

27 Commits

Repository files navigation

OllamaJavaAPI

OllamaJavaAPI is a Java binding for the Ollama API, making it easy to interact with Ollama using you favourite Java variation.

This API is by far not finished and many features are missing by now...

1 Features

  • Intuitive API client: Set up and interact with Ollama in just a few lines of code.
  • Support for various Ollama operations: Including streaming completions (chatting), listing local models, pulling new models, show model information, creating new models, copying models, deleting models, pushing models, and generating embeddings.
  • Real-time streaming: Stream responses directly to your application.
  • Progress reporting: Get real-time progress feedback on tasks like model pulling.

2 Installation

Maven

Repository

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>

Dependency

<dependency>
<groupId>com.github.Asedem</groupId>
<artifactId>OllamaJavaAPI</artifactId>
<version>master-SNAPSHOT</version>
</dependency>

Gradle

Repository

repositories {
maven { url 'https://jitpack.io' }
}

Dependency

dependencies {
implementation 'com.github.Asedem:OllamaJavaAPI:master-SNAPSHOT'
}

3 Usage

These examples use poor error handling for simplicity, but you should handle errors properly in your code.

2.1 Initialize Ollama

// By default, it will connect to localhost:11434Ollamaollama = Ollama.initDefault();
// For custom valuesOllamaollama = Ollama.init("http://localhost", 11434);

2.2 Completion generation

Stringmodel = "llama2:latest";
Stringprompt = "Why is the sky blue?";
GenerationResponseresponse = ollama.generate(newGenerationRequest(model, prompt));
System.out.
println(response.response());

OUTPUTS: The sky appears blue because of a phenomenon called Rayleigh scattering...

2.3 List local models

List<Model> models = ollama.listModels();

Returns aListofModelobjects.

2.4 Show model information

ModelInfomodelInfo = ollama.showInfo("llama2:latest");

Returns aModelInfoobject.

2.5 Copy a model

booleansuccess = ollama.copy("llama2:latest", "llama2-backup");

Returnstrueif the copy process was successfully.

2.6 Delete a model

booleansuccess = ollama.delete("llama2-backup");

Returnstrueif the copy process was successfully.

4 Credits

Structure of the readme is inspired from Ollama Sharp and ollama-rs.

Icon and name were reused from the amazing Ollama project.

About

A Java API for Ollama LLM's

Topics

Resources

Stars

7 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages