mirror of
				https://github.com/amithkoujalgi/ollama4j.git
				synced 2025-10-31 16:40:41 +01:00 
			
		
		
		
	Compare commits
	
		
			15 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | e1b9d42771 | ||
|   | 1a086c37c0 | ||
|   | 3ed3187ba9 | ||
|   | b7cd81a7f5 | ||
|   | e750c2d7f9 | ||
|   | 62f16131f3 | ||
|   | 2cbaf12d7c | ||
|   | e2d555d404 | ||
|   | c296b34174 | ||
|   | e8f99f28ec | ||
|   | 250b1abc79 | ||
|   | 42b15ad93f | ||
|   | 6f7a714bae | ||
|   | 92618e5084 | ||
|   | 391a9242c3 | 
							
								
								
									
										10
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								README.md
									
									
									
									
									
								
							| @@ -110,6 +110,16 @@ make it | |||||||
| Releases (newer artifact versions) are done automatically on pushing the code to the `main` branch through GitHub | Releases (newer artifact versions) are done automatically on pushing the code to the `main` branch through GitHub | ||||||
| Actions CI workflow. | Actions CI workflow. | ||||||
|  |  | ||||||
|  | #### Who's using Ollama4j? | ||||||
|  |  | ||||||
|  | - `Datafaker`: a library to generate fake data | ||||||
|  |     - https://github.com/datafaker-net/datafaker-experimental/tree/main/ollama-api | ||||||
|  | - `Vaadin Web UI`: UI-Tester for Interactions with Ollama via ollama4j | ||||||
|  |     - https://github.com/TEAMPB/ollama4j-vaadin-ui | ||||||
|  | - `ollama-translator`: Minecraft 1.20.6 spigot plugin allows to easily break language barriers by using ollama on the | ||||||
|  |   server to translate all messages into a specfic target language. | ||||||
|  |     - https://github.com/liebki/ollama-translator | ||||||
|  |  | ||||||
| #### Traction | #### Traction | ||||||
|  |  | ||||||
| [](https://star-history.com/#amithkoujalgi/ollama4j&Date) | [](https://star-history.com/#amithkoujalgi/ollama4j&Date) | ||||||
|   | |||||||
							
								
								
									
										11
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -4,7 +4,7 @@ | |||||||
|  |  | ||||||
|     <groupId>io.github.amithkoujalgi</groupId> |     <groupId>io.github.amithkoujalgi</groupId> | ||||||
|     <artifactId>ollama4j</artifactId> |     <artifactId>ollama4j</artifactId> | ||||||
|     <version>1.0.66</version> |     <version>1.0.70</version> | ||||||
|  |  | ||||||
|     <name>Ollama4j</name> |     <name>Ollama4j</name> | ||||||
|     <description>Java library for interacting with Ollama API.</description> |     <description>Java library for interacting with Ollama API.</description> | ||||||
| @@ -39,7 +39,7 @@ | |||||||
|         <connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection> |         <connection>scm:git:git@github.com:amithkoujalgi/ollama4j.git</connection> | ||||||
|         <developerConnection>scm:git:https://github.com/amithkoujalgi/ollama4j.git</developerConnection> |         <developerConnection>scm:git:https://github.com/amithkoujalgi/ollama4j.git</developerConnection> | ||||||
|         <url>https://github.com/amithkoujalgi/ollama4j</url> |         <url>https://github.com/amithkoujalgi/ollama4j</url> | ||||||
|         <tag>v1.0.66</tag> |         <tag>v1.0.70</tag> | ||||||
|     </scm> |     </scm> | ||||||
|  |  | ||||||
|     <build> |     <build> | ||||||
| @@ -149,7 +149,12 @@ | |||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>com.fasterxml.jackson.core</groupId> |             <groupId>com.fasterxml.jackson.core</groupId> | ||||||
|             <artifactId>jackson-databind</artifactId> |             <artifactId>jackson-databind</artifactId> | ||||||
|             <version>2.15.3</version> |             <version>2.17.1</version> | ||||||
|  |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>com.fasterxml.jackson.datatype</groupId> | ||||||
|  |             <artifactId>jackson-datatype-jsr310</artifactId> | ||||||
|  |             <version>2.17.1</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>ch.qos.logback</groupId> |             <groupId>ch.qos.logback</groupId> | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| package io.github.amithkoujalgi.ollama4j.core.models; | package io.github.amithkoujalgi.ollama4j.core.models; | ||||||
|  |  | ||||||
|  | import java.time.LocalDateTime; | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.annotation.JsonProperty; | import com.fasterxml.jackson.annotation.JsonProperty; | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
| import io.github.amithkoujalgi.ollama4j.core.utils.Utils; | import io.github.amithkoujalgi.ollama4j.core.utils.Utils; | ||||||
| @@ -11,7 +13,9 @@ public class Model { | |||||||
|   private String name; |   private String name; | ||||||
|   private String model; |   private String model; | ||||||
|   @JsonProperty("modified_at") |   @JsonProperty("modified_at") | ||||||
|   private String modifiedAt; |   private LocalDateTime modifiedAt; | ||||||
|  |   @JsonProperty("expires_at") | ||||||
|  |   private LocalDateTime expiresAt; | ||||||
|   private String digest; |   private String digest; | ||||||
|   private long size; |   private long size; | ||||||
|   @JsonProperty("details") |   @JsonProperty("details") | ||||||
|   | |||||||
| @@ -1,14 +1,15 @@ | |||||||
| package io.github.amithkoujalgi.ollama4j.core.models.chat; | package io.github.amithkoujalgi.ollama4j.core.models.chat; | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.annotation.JsonProperty; | import com.fasterxml.jackson.annotation.JsonProperty; | ||||||
|  | import lombok.Data; | ||||||
|  |  | ||||||
| import java.util.List; | import java.util.List; | ||||||
| import lombok.Data; |  | ||||||
|  |  | ||||||
| @Data | @Data | ||||||
| public class OllamaChatResponseModel { | public class OllamaChatResponseModel { | ||||||
|     private String model; |     private String model; | ||||||
|     private @JsonProperty("created_at") String createdAt; |     private @JsonProperty("created_at") String createdAt; | ||||||
|  |     private @JsonProperty("done_reason") String doneReason; | ||||||
|     private OllamaChatMessage message; |     private OllamaChatMessage message; | ||||||
|     private boolean done; |     private boolean done; | ||||||
|     private String error; |     private String error; | ||||||
|   | |||||||
| @@ -1,12 +1,6 @@ | |||||||
| package io.github.amithkoujalgi.ollama4j.core.models.request; | package io.github.amithkoujalgi.ollama4j.core.models.request; | ||||||
|  |  | ||||||
| import java.io.IOException; |  | ||||||
|  |  | ||||||
| import org.slf4j.Logger; |  | ||||||
| import org.slf4j.LoggerFactory; |  | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.core.JsonProcessingException; | import com.fasterxml.jackson.core.JsonProcessingException; | ||||||
|  |  | ||||||
| import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler; | import io.github.amithkoujalgi.ollama4j.core.OllamaStreamHandler; | ||||||
| import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException; | import io.github.amithkoujalgi.ollama4j.core.exceptions.OllamaBaseException; | ||||||
| import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth; | import io.github.amithkoujalgi.ollama4j.core.models.BasicAuth; | ||||||
| @@ -15,11 +9,15 @@ import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatResponseModel | |||||||
| import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatStreamObserver; | import io.github.amithkoujalgi.ollama4j.core.models.chat.OllamaChatStreamObserver; | ||||||
| import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody; | import io.github.amithkoujalgi.ollama4j.core.utils.OllamaRequestBody; | ||||||
| import io.github.amithkoujalgi.ollama4j.core.utils.Utils; | import io.github.amithkoujalgi.ollama4j.core.utils.Utils; | ||||||
|  | import org.slf4j.Logger; | ||||||
|  | import org.slf4j.LoggerFactory; | ||||||
|  |  | ||||||
|  | import java.io.IOException; | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Specialization class for requests |  * Specialization class for requests | ||||||
|  */ |  */ | ||||||
| public class OllamaChatEndpointCaller extends OllamaEndpointCaller{ | public class OllamaChatEndpointCaller extends OllamaEndpointCaller { | ||||||
|  |  | ||||||
|     private static final Logger LOG = LoggerFactory.getLogger(OllamaChatEndpointCaller.class); |     private static final Logger LOG = LoggerFactory.getLogger(OllamaChatEndpointCaller.class); | ||||||
|  |  | ||||||
| @@ -39,12 +37,12 @@ public class OllamaChatEndpointCaller extends OllamaEndpointCaller{ | |||||||
|         try { |         try { | ||||||
|             OllamaChatResponseModel ollamaResponseModel = Utils.getObjectMapper().readValue(line, OllamaChatResponseModel.class); |             OllamaChatResponseModel ollamaResponseModel = Utils.getObjectMapper().readValue(line, OllamaChatResponseModel.class); | ||||||
|             responseBuffer.append(ollamaResponseModel.getMessage().getContent()); |             responseBuffer.append(ollamaResponseModel.getMessage().getContent()); | ||||||
|             if(streamObserver != null) { |             if (streamObserver != null) { | ||||||
|                 streamObserver.notify(ollamaResponseModel); |                 streamObserver.notify(ollamaResponseModel); | ||||||
|             } |             } | ||||||
|             return ollamaResponseModel.isDone(); |             return ollamaResponseModel.isDone(); | ||||||
|         } catch (JsonProcessingException e) { |         } catch (JsonProcessingException e) { | ||||||
|             LOG.error("Error parsing the Ollama chat response!",e); |             LOG.error("Error parsing the Ollama chat response!", e); | ||||||
|             return true; |             return true; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| @@ -54,7 +52,4 @@ public class OllamaChatEndpointCaller extends OllamaEndpointCaller{ | |||||||
|         streamObserver = new OllamaChatStreamObserver(streamHandler); |         streamObserver = new OllamaChatStreamObserver(streamHandler); | ||||||
|         return super.callSync(body); |         return super.callSync(body); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|      |  | ||||||
|   |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,10 +8,18 @@ import java.net.URISyntaxException; | |||||||
| import java.net.URL; | import java.net.URL; | ||||||
|  |  | ||||||
| import com.fasterxml.jackson.databind.ObjectMapper; | import com.fasterxml.jackson.databind.ObjectMapper; | ||||||
|  | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||||||
|  |  | ||||||
| public class Utils { | public class Utils { | ||||||
|  |  | ||||||
|  |   private static ObjectMapper objectMapper; | ||||||
|  |  | ||||||
|   public static ObjectMapper getObjectMapper() { |   public static ObjectMapper getObjectMapper() { | ||||||
|     return new ObjectMapper(); |     if(objectMapper == null) { | ||||||
|  |       objectMapper = new ObjectMapper(); | ||||||
|  |       objectMapper.registerModule(new JavaTimeModule()); | ||||||
|  |     } | ||||||
|  |     return objectMapper; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   public static byte[] loadImageBytesFromUrl(String imageUrl) |   public static byte[] loadImageBytesFromUrl(String imageUrl) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user