mirror of
https://github.com/amithkoujalgi/ollama4j.git
synced 2025-05-15 03:47:13 +02:00
init
This commit is contained in:
parent
e7351359a3
commit
fd289fa39a
27
README.md
27
README.md
@ -7,7 +7,7 @@ Start Ollama Container:
|
||||
docker run -v ~/ollama:/root/.ollama -p 11434:11434 ollama/ollama
|
||||
```
|
||||
|
||||
Post a question to Ollama using Ollama4j:
|
||||
Pull a model:
|
||||
|
||||
```java
|
||||
public class Main {
|
||||
@ -15,6 +15,31 @@ public class Main {
|
||||
String host = "http://localhost:11434/";
|
||||
OllamaAPI ollamaAPI = new OllamaAPI(host);
|
||||
ollamaAPI.pullModel(OllamaModel.LLAMA2);
|
||||
}
|
||||
}
|
||||
```
|
||||
Post a question to Ollama using Ollama4j:
|
||||
|
||||
Using sync API:
|
||||
|
||||
```java
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String host = "http://localhost:11434/";
|
||||
OllamaAPI ollamaAPI = new OllamaAPI(host);
|
||||
String response = ollamaAPI.runSync(OllamaModel.LLAMA2, "Who are you?");
|
||||
System.out.println(response);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Using async API:
|
||||
|
||||
```java
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
String host = "http://localhost:11434/";
|
||||
OllamaAPI ollamaAPI = new OllamaAPI(host);
|
||||
OllamaAsyncResultCallback ollamaAsyncResultCallback = ollamaAPI.runAsync(OllamaModel.LLAMA2, "Who are you?");
|
||||
while (true) {
|
||||
if (ollamaAsyncResultCallback.isComplete()) {
|
||||
|
@ -5,14 +5,8 @@ public class Main {
|
||||
String host = "http://localhost:11434/";
|
||||
OllamaAPI ollamaAPI = new OllamaAPI(host);
|
||||
ollamaAPI.pullModel(OllamaModel.LLAMA2);
|
||||
OllamaAsyncResultCallback ollamaAsyncResultCallback = ollamaAPI.runAsync(OllamaModel.LLAMA2, "Who are you?");
|
||||
while (true) {
|
||||
if (ollamaAsyncResultCallback.isComplete()) {
|
||||
System.out.println(ollamaAsyncResultCallback.getResponse());
|
||||
break;
|
||||
}
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
String response = ollamaAPI.runSync(OllamaModel.LLAMA2, "Who are you?");
|
||||
System.out.println(response);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user