From 1e66bdb07ff8cad48c800d5123d4d8c2d53e8648 Mon Sep 17 00:00:00 2001 From: Markus Klenke Date: Sun, 18 Feb 2024 21:41:35 +0000 Subject: [PATCH] Adds documentation for streamed generate API call --- docs/docs/apis-ask/ask.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/docs/apis-ask/ask.md b/docs/docs/apis-ask/ask.md index f62437c..6d1cf66 100644 --- a/docs/docs/apis-ask/ask.md +++ b/docs/docs/apis-ask/ask.md @@ -41,6 +41,41 @@ You will get a response similar to: > require > natural language understanding and generation capabilities. +## Try asking a question, receiving the answer streamed + +```java +public class Main { + + public static void main(String[] args) { + + String host = "http://localhost:11434/"; + + OllamaAPI ollamaAPI = new OllamaAPI(host); + // define a stream handler (Consumer) + OllamaStreamHandler streamHandler = (s) -> { + System.out.println(s); + }; + + // Should be called using seperate thread to gain non blocking streaming effect. + OllamaResult result = ollamaAPI.generate(config.getModel(), + "What is the capital of France? And what's France's connection with Mona Lisa?", + new OptionsBuilder().build(), streamHandler); + + System.out.println("Full response: " +result.getResponse()); + } +} +``` +You will get a response similar to: + +> The +> The capital +> The capital of +> The capital of France +> The capital of France is +> The capital of France is Paris +> The capital of France is Paris. +> Full response: The capital of France is Paris. + ## Try asking a question from general topics. ```java