This commit is contained in:
Amith Koujalgi 2023-10-27 12:06:44 +05:30
parent a3fa018fcc
commit e7351359a3
9 changed files with 44 additions and 21 deletions

View File

@ -10,19 +10,20 @@ docker run -v ~/ollama:/root/.ollama -p 11434:11434 ollama/ollama
Post a question to Ollama using Ollama4j: Post a question to Ollama using Ollama4j:
```java ```java
String host = "http://localhost:11434/"; public class Main {
public static void main(String[] args) throws Exception {
OllamaAPI ollamaAPI = new OllamaAPI(host); String host = "http://localhost:11434/";
OllamaAPI ollamaAPI = new OllamaAPI(host);
ollamaAPI.pullModel(OllamaModel.LLAMA2); ollamaAPI.pullModel(OllamaModel.LLAMA2);
OllamaAsyncResultCallback ollamaAsyncResultCallback = ollamaAPI.runAsync(OllamaModel.LLAMA2, "Who are you?");
OllamaAsyncResultCallback ollamaAsyncResultCallback = ollamaAPI.runAsync(OllamaModel.LLAMA2, "Who are you?"); while (true) {
while (true) {
if (ollamaAsyncResultCallback.isComplete()) { if (ollamaAsyncResultCallback.isComplete()) {
System.out.println(ollamaAsyncResultCallback.getResponse()); System.out.println(ollamaAsyncResultCallback.getResponse());
break; break;
} }
Thread.sleep(1000); Thread.sleep(1000);
}
}
} }
``` ```

25
pom.xml
View File

@ -4,7 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.ollama4j</groupId> <groupId>io.github.amithkoujalgi</groupId>
<artifactId>ollama4j</artifactId> <artifactId>ollama4j</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
@ -14,6 +14,29 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<developers>
<developer>
<name>Amith Koujalgi</name>
<email>koujalgi.amith@gmail.com</email>
<organization>Sonatype</organization>
<organizationUrl>http://www.sonatype.com</organizationUrl>
</developer>
</developers>
<licenses>
<license>
<name>MIT License</name>
<url>https://raw.githubusercontent.com/amithkoujalgi/ollama4j/main/LICENSE</url>
</license>
</licenses>
<scm>
<connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection>
<developerConnection>scm:git:ssh://github.com:amithkoujalgi/ollama4j.git</developerConnection>
<url>https://github.com/amithkoujalgi/ollama4j/tree/main</url>
</scm>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
public class Main { public class Main {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -1,7 +1,6 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.hc.client5.http.HttpResponseException;
import org.apache.hc.client5.http.classic.methods.HttpPost; import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
import com.google.gson.Gson; import com.google.gson.Gson;

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
public class OllamaBaseException extends Exception { public class OllamaBaseException extends Exception {

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
public enum OllamaModel { public enum OllamaModel {
LLAMA2("llama2"), MISTRAL("mistral"), MEDLLAMA2("medllama2"); LLAMA2("llama2"), MISTRAL("mistral"), MEDLLAMA2("medllama2");

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
import com.google.gson.Gson; import com.google.gson.Gson;

View File

@ -1,4 +1,4 @@
package org.ollama4j; package io.github.amithkoujalgi.ollama4j;
import java.util.List; import java.util.List;