This commit is contained in:
Amith Koujalgi 2023-11-08 13:34:08 +05:30
parent 639ffd5459
commit e2b3070677

View File

@ -2,13 +2,19 @@
<img src='https://raw.githubusercontent.com/amithkoujalgi/ollama4j/163e88bc82b4beb4a52e4d99f9b5d9ef1255ec06/ollama4j.png' width='100' alt="ollama4j-icon">
A Java wrapper for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
A Java library (wrapper) for [Ollama](https://github.com/jmorganca/ollama/blob/main/docs/api.md) APIs.
![Build Status](https://github.com/amithkoujalgi/ollama4j/actions/workflows/maven-publish.yml/badge.svg)
Install:
#### Requirements
From [Maven Central](https://s01.oss.sonatype.org/#nexus-search;quick~ollama4j):
- Ollama (Either [natively](https://ollama.ai/download) setup or via [Docker](https://hub.docker.com/r/ollama/ollama))
- Java 8 or above
#### Install
In your Maven project, add this dependency available in
the [Central Repository](https://s01.oss.sonatype.org/#nexus-search;quick~ollama4j):
```xml
@ -31,21 +37,31 @@ You might want to include the Maven repository to pull the ollama4j library from
</repositories>
```
Verify if the ollama4j dependencies have been resolved by running:
#### Build:
Build your project to resolve the dependencies:
```bash
mvn clean install
```
Start Ollama Container:
You can then use the Ollama Java APIs by importing `ollama4j`:
```java
import io.github.amithkoujalgi.ollama4j.core.OllamaAPI;
```
### Try out the APIs
For simplest way to get started, I prefer to use the Ollama docker setup.
Start the Ollama docker container:
```
docker run -v ~/ollama:/root/.ollama -p 11434:11434 ollama/ollama
```
Find the full `Javadoc` (API specifications) [here](https://amithkoujalgi.github.io/ollama4j/).
Pull a model:
#### Pull a model:
```java
public class Main {
@ -57,9 +73,11 @@ public class Main {
}
```
Post a question to Ollama using Ollama4j:
_Find the list of available models from Ollama [here](https://ollama.ai/library)._
Using sync API:
#### Ask a question to the model with ollama4j
##### Using sync API:
```java
public class Main {
@ -72,7 +90,7 @@ public class Main {
}
```
Using async API:
##### Using async API:
```java
public class Main {
@ -92,11 +110,15 @@ public class Main {
}
```
You'd then get a response from Ollama:
You'd then get a response from the model:
```
I am LLaMA, an AI assistant developed by Meta AI that can understand and respond to human input in a conversational manner. I am trained on a massive dataset of text from the internet and can generate human-like responses to a wide range of topics and questions. I can be used to create chatbots, virtual assistants, and other applications that require natural language understanding and generation capabilities.
```
> I am LLaMA, an AI assistant developed by Meta AI that can understand and respond to human input in a conversational
> manner. I am trained on a massive dataset of text from the internet and can generate human-like responses to a wide
> range of topics and questions. I can be used to create chatbots, virtual assistants, and other applications that
> require
> natural language understanding and generation capabilities.
Find the full `Javadoc` (API specifications) [here](https://amithkoujalgi.github.io/ollama4j/).
#### Get Involved