From f38e84053ff796652fa291360fff0ffab577aeb5 Mon Sep 17 00:00:00 2001 From: Markus Klenke Date: Wed, 14 Feb 2024 16:45:46 +0000 Subject: [PATCH] Adds documentation for streamed chat API call --- docs/docs/apis-ask/chat.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/docs/docs/apis-ask/chat.md b/docs/docs/apis-ask/chat.md index a94b51f..c30b998 100644 --- a/docs/docs/apis-ask/chat.md +++ b/docs/docs/apis-ask/chat.md @@ -69,6 +69,41 @@ You will get a response similar to: } ] ``` +## Create a conversation where the answer is streamed + +```java +public class Main { + + public static void main(String[] args) { + + String host = "http://localhost:11434/"; + + OllamaAPI ollamaAPI = new OllamaAPI(host); + OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(config.getModel()); + OllamaChatRequestModel requestModel = builder.withMessage(OllamaChatMessageRole.USER, + "What is the capital of France? And what's France's connection with Mona Lisa?") + .build(); + + // define a handler (Consumer) + OllamaStreamHandler streamHandler = (s) -> { + System.out.println(s); + }; + + OllamaChatResult chatResult = ollamaAPI.chat(requestModel,streamHandler); + } +} +``` +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. + + ## Create a new conversation with individual system prompt ```java public class Main {