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...
- 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.
✗
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories><dependency>
<groupId>com.github.Asedem</groupId>
<artifactId>OllamaJavaAPI</artifactId>
<version>master-SNAPSHOT</version>
</dependency>repositories {
maven { url 'https://jitpack.io' }
}dependencies {
implementation 'com.github.Asedem:OllamaJavaAPI:master-SNAPSHOT'
}These examples use poor error handling for simplicity, but you should handle errors properly in your code.
// By default, it will connect to localhost:11434Ollamaollama = Ollama.initDefault();
// For custom valuesOllamaollama = Ollama.init("http://localhost", 11434);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...
List<Model> models = ollama.listModels();Returns aListofModelobjects.
ModelInfomodelInfo = ollama.showInfo("llama2:latest");Returns aModelInfoobject.
booleansuccess = ollama.copy("llama2:latest", "llama2-backup");Returnstrueif the copy process was successfully.
booleansuccess = ollama.delete("llama2-backup");Returnstrueif the copy process was successfully.
Structure of the readme is inspired from Ollama Sharp and ollama-rs.
Icon and name were reused from the amazing Ollama project.