From e9621f054dc56007a08a84faed7be243d4e8c4c5 Mon Sep 17 00:00:00 2001 From: Markus Klenke Date: Tue, 13 Feb 2024 18:11:59 +0000 Subject: [PATCH] Adds integration test for chat streaming API --- .../integrationtests/TestRealAPIs.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java index ed5c862..870e17f 100644 --- a/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java +++ b/src/test/java/io/github/amithkoujalgi/ollama4j/integrationtests/TestRealAPIs.java @@ -23,8 +23,13 @@ import lombok.Data; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; class TestRealAPIs { + + private static final Logger LOG = LoggerFactory.getLogger(TestRealAPIs.class); + OllamaAPI ollamaAPI; Config config; @@ -164,6 +169,31 @@ class TestRealAPIs { } } + @Test + @Order(3) + void testChatWithStream() { + testEndpointReachability(); + try { + 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(); + + StringBuffer sb = new StringBuffer(""); + + OllamaChatResult chatResult = ollamaAPI.chat(requestModel,(s) -> { + LOG.info(s); + String substring = s.substring(sb.toString().length(), s.length()-1); + LOG.info(substring); + sb.append(substring); + }); + assertNotNull(chatResult); + assertEquals(sb.toString().trim(), chatResult.getResponse().trim()); + } catch (IOException | OllamaBaseException | InterruptedException e) { + throw new RuntimeException(e); + } + } + @Test @Order(3) void testChatWithImageFromFileWithHistoryRecognition() {