mirror of
				https://github.com/amithkoujalgi/ollama4j.git
				synced 2025-10-31 08:30:41 +01:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | 660a1b937a | ||
|   | fd961d7037 | ||
|   | b48f9550c3 | ||
|   | 363969a275 | ||
|   | 992625cf86 | ||
|   | bbebd26d07 | ||
|   | 3aa0fc77cb | 
| @@ -221,7 +221,7 @@ In your Maven project, add this dependency: | ||||
|  | ||||
| ```groovy | ||||
| dependencies { | ||||
|     implementation 'com.github.ollama4j:ollama4j:1.0.79' | ||||
|     implementation 'io.github.ollama4j:ollama4j:1.0.79' | ||||
| } | ||||
| ``` | ||||
|  | ||||
| @@ -277,8 +277,12 @@ Newer artifacts are published via GitHub Actions CI workflow when a new release | ||||
| - `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 | ||||
|     - https://www.reddit.com/r/fabricmc/comments/1e65x5s/comment/ldr2vcf/ | ||||
| - `Ollama4j Web UI`: A web UI for Ollama written in Java using Spring Boot and Vaadin framework and | ||||
|   Ollama4j. https://github.com/ollama4j/ollama4j-web-ui | ||||
|   Ollama4j. | ||||
|     - https://github.com/ollama4j/ollama4j-web-ui | ||||
| - `JnsCLI`: A command-line tool for Jenkins that manages jobs, builds, and configurations directly from the terminal while offering AI-powered error analysis for quick troubleshooting. | ||||
|     -  https://github.com/mirum8/jnscli | ||||
|  | ||||
| #### Traction | ||||
|  | ||||
|   | ||||
| @@ -82,6 +82,33 @@ You will get a response similar to: | ||||
| ] | ||||
| ``` | ||||
|  | ||||
| ## Conversational loop | ||||
|  | ||||
| ```java | ||||
| public class Main { | ||||
|  | ||||
|     public static void main(String[] args) { | ||||
|  | ||||
|         OllamaAPI ollamaAPI = new OllamaAPI(); | ||||
|         ollamaAPI.setRequestTimeoutSeconds(60); | ||||
|  | ||||
|         OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance("<your-model>"); | ||||
|  | ||||
|         OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "<your-first-message>").build(); | ||||
|         OllamaChatResult initialChatResult = ollamaAPI.chat(requestModel); | ||||
|         System.out.println(initialChatResult.getResponse()); | ||||
|  | ||||
|         List<OllamaChatMessage> history = initialChatResult.getChatHistory(); | ||||
|  | ||||
|         while (true) { | ||||
|             OllamaChatResult chatResult = ollamaAPI.chat(builder.withMessages(history).withMessage(OllamaChatMessageRole.USER, "<your-new-message").build()); | ||||
|             System.out.println(chatResult.getResponse()); | ||||
|             history = chatResult.getChatHistory(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| ``` | ||||
|  | ||||
| ## Create a conversation where the answer is streamed | ||||
|  | ||||
| ```java | ||||
|   | ||||
							
								
								
									
										41
									
								
								docs/src/components/BuyMeACoffee/index.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								docs/src/components/BuyMeACoffee/index.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| import React from "react"; | ||||
|  | ||||
| class BuyMeACoffee extends React.Component { | ||||
|   constructor(props) { | ||||
|     super(props) | ||||
|     let script = document.createElement("script"); | ||||
|     script.src = 'https://cdnjs.buymeacoffee.com/1.0.0/widget.prod.min.js'; | ||||
|     script.dataset.name = 'BMC-Widget'; | ||||
|     script.dataset.cfasync = 'false'; | ||||
|     script.dataset.id = 'amithkoujalgi'; | ||||
|     script.dataset.description = 'Support me on Buy me a coffee!'; | ||||
|     script.dataset.message = 'If you like my work and want to say thanks, or encourage me to do more, you can buy me a coffee! 😊'; | ||||
|     script.dataset.color = '#2e8555'; | ||||
|     script.dataset.position = 'Right'; | ||||
|     script.dataset.x_margin = '18'; | ||||
|     script.dataset.y_margin = '18'; | ||||
|     script.async = true | ||||
|  | ||||
|     script.onload = function () { | ||||
|       let evt = document.createEvent('Event'); | ||||
|       evt.initEvent('DOMContentLoaded', false, false); | ||||
|       window.dispatchEvent(evt); | ||||
|     } | ||||
|     this.script = script | ||||
|   } | ||||
|  | ||||
|   componentDidMount() { | ||||
|     document.head.appendChild(this.script) | ||||
|   } | ||||
|  | ||||
|   // componentWillUnmount() { | ||||
|   //   document.head.removeChild(this.script); | ||||
|   //   document.body.removeChild(document.getElementById("bmc-wbtn")) | ||||
|   // } | ||||
|  | ||||
|   render() { | ||||
|     return null | ||||
|   } | ||||
| } | ||||
|  | ||||
| export default BuyMeACoffee; | ||||
| @@ -38,3 +38,11 @@ header > h1, | ||||
| h2 > a { | ||||
|     font-size: 2rem !important; | ||||
| } | ||||
|  | ||||
| #bmc-wbtn{ | ||||
|     bottom: 15px; | ||||
| } | ||||
|  | ||||
| #bmc-wbtn + div{ | ||||
|     bottom:15px; | ||||
| } | ||||
| @@ -3,7 +3,7 @@ import Link from '@docusaurus/Link'; | ||||
| import useDocusaurusContext from '@docusaurus/useDocusaurusContext'; | ||||
| import Layout from '@theme/Layout'; | ||||
| import HomepageFeatures from '@site/src/components/HomepageFeatures'; | ||||
|  | ||||
| import BuyMeACoffee from '@site/src/components/BuyMeACoffee'; | ||||
| import Heading from '@theme/Heading'; | ||||
| import styles from './index.module.css'; | ||||
|  | ||||
| @@ -14,7 +14,8 @@ function HomepageHeader() { | ||||
|       <Heading as="h1" className="hero__title"> | ||||
|         {siteConfig.title} | ||||
|       </Heading> | ||||
|             <img src="img/logo.svg" alt="Ollama4j Logo" className={styles.logo} style={{maxWidth: '20vh'}}/> | ||||
|       <img src="img/logo.svg" alt="Ollama4j Logo" className={styles.logo} | ||||
|            style={{maxWidth: '20vh'}}/> | ||||
|       <p className="hero__subtitle">{siteConfig.tagline}</p> | ||||
|       <div className={styles.buttons}> | ||||
|         <Link | ||||
| @@ -35,6 +36,7 @@ export default function Home() { | ||||
|     <HomepageHeader/> | ||||
|     <main> | ||||
|       <HomepageFeatures/> | ||||
|       <BuyMeACoffee/> | ||||
|     </main> | ||||
|   </Layout>); | ||||
| } | ||||
| @@ -1,5 +1,10 @@ | ||||
| package io.github.ollama4j.models.chat; | ||||
|  | ||||
| import io.github.ollama4j.utils.Options; | ||||
| import io.github.ollama4j.utils.Utils; | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.net.URISyntaxException; | ||||
| @@ -8,12 +13,6 @@ import java.util.ArrayList; | ||||
| import java.util.List; | ||||
| import java.util.stream.Collectors; | ||||
|  | ||||
| import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | ||||
|  | ||||
| import io.github.ollama4j.utils.Options; | ||||
| import io.github.ollama4j.utils.Utils; | ||||
|  | ||||
| /** | ||||
|  * Helper class for creating {@link OllamaChatRequest} objects using the builder-pattern. | ||||
|  */ | ||||
| @@ -63,11 +62,9 @@ public class OllamaChatRequestBuilder { | ||||
|             for (String imageUrl : imageUrls) { | ||||
|                 try { | ||||
|                     binaryImages.add(Utils.loadImageBytesFromUrl(imageUrl)); | ||||
|                 } | ||||
|                     catch (URISyntaxException e){ | ||||
|                 } catch (URISyntaxException e) { | ||||
|                     LOG.warn(String.format("URL '%s' could not be accessed, will not add to message!", imageUrl), e); | ||||
|                 } | ||||
|                 catch (IOException e){ | ||||
|                 } catch (IOException e) { | ||||
|                     LOG.warn(String.format("Content of URL '%s' could not be read, will not add to message!", imageUrl), e); | ||||
|                 } | ||||
|             } | ||||
| @@ -78,8 +75,7 @@ public class OllamaChatRequestBuilder { | ||||
|     } | ||||
|  | ||||
|     public OllamaChatRequestBuilder withMessages(List<OllamaChatMessage> messages) { | ||||
|         this.request.getMessages().addAll(messages); | ||||
|         return this; | ||||
|         return new OllamaChatRequestBuilder(request.getModel(), messages); | ||||
|     } | ||||
|  | ||||
|     public OllamaChatRequestBuilder withOptions(Options options) { | ||||
|   | ||||
| @@ -14,6 +14,8 @@ public class OllamaModelType { | ||||
|  | ||||
|     public static final String LLAMA2 = "llama2"; | ||||
|     public static final String LLAMA3 = "llama3"; | ||||
|     public static final String LLAMA3_1 = "llama3.1"; | ||||
|  | ||||
|     public static final String MISTRAL = "mistral"; | ||||
|     public static final String MIXTRAL = "mixtral"; | ||||
|     public static final String LLAVA = "llava"; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user