From a9f6d4671cfb70eb25957249a215e257b90393b5 Mon Sep 17 00:00:00 2001 From: amithkoujalgi Date: Sat, 20 Sep 2025 23:12:35 +0530 Subject: [PATCH] Set keepAlive to 0m in OllamaAPI requests Added keepAlive parameter with value '0m' to OllamaAPI requests for improved connection handling. Updated integration test to enable tool usage and commented out a test for raw mode and thinking with new model handling. --- .../java/io/github/ollama4j/OllamaAPI.java | 1 + .../OllamaAPIIntegrationTest.java | 61 ++++++++++--------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/github/ollama4j/OllamaAPI.java b/src/main/java/io/github/ollama4j/OllamaAPI.java index beed9b4..f619095 100644 --- a/src/main/java/io/github/ollama4j/OllamaAPI.java +++ b/src/main/java/io/github/ollama4j/OllamaAPI.java @@ -614,6 +614,7 @@ public class OllamaAPI { ollamaRequestModel.setRaw(raw); ollamaRequestModel.setThink(think); ollamaRequestModel.setOptions(options.getOptionsMap()); + ollamaRequestModel.setKeepAlive("0m"); // Based on 'think' flag, choose the appropriate stream handler(s) if (think) { diff --git a/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java b/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java index e0d66b1..ceae24b 100644 --- a/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java +++ b/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java @@ -667,7 +667,7 @@ class OllamaAPIIntegrationTest { OllamaChatMessageRole.USER, "Compute the most important constant in the world using 5 digits") .build(); - + requestModel.setUseTools(true); OllamaChatResult chatResult = api.chat(requestModel, null); assertNotNull(chatResult); assertNotNull(chatResult.getResponseModel()); @@ -1060,34 +1060,37 @@ class OllamaAPIIntegrationTest { assertFalse(result.getResponse().isEmpty()); } - /** - * Tests generate with raw=true and thinking enabled. - * - *

Scenario: Calls generate with raw=true and think=true combination. Usage: generate, - * raw=true, thinking enabled, no streaming. - */ - @Test - @Order(23) - void shouldGenerateWithRawModeAndThinking() - throws OllamaBaseException, IOException, URISyntaxException, InterruptedException { - api.pullModel(THINKING_TOOL_MODEL); - boolean raw = - true; // if true no formatting will be applied to the prompt. You may choose to use - // the raw parameter if you are specifying a full templated prompt in your - // request to the API - boolean thinking = true; - OllamaResult result = - api.generate( - THINKING_TOOL_MODEL, - "What is a catalyst?", - raw, - thinking, - new OptionsBuilder().build(), - new OllamaGenerateStreamObserver(null, null)); - assertNotNull(result); - assertNotNull(result.getResponse()); - assertNotNull(result.getThinking()); - } + // /** + // * Tests generate with raw=true and thinking enabled. + // * + // *

Scenario: Calls generate with raw=true and think=true combination. Usage: generate, + // * raw=true, thinking enabled, no streaming. + // */ + // @Test + // @Order(23) + // void shouldGenerateWithRawModeAndThinking() + // throws OllamaBaseException, IOException, URISyntaxException, InterruptedException + // { + // api.pullModel(THINKING_TOOL_MODEL_2); + // api.unloadModel(THINKING_TOOL_MODEL_2); + // boolean raw = + // true; // if true no formatting will be applied to the prompt. You may choose + // to use + // // the raw parameter if you are specifying a full templated prompt in your + // // request to the API + // boolean thinking = true; + // OllamaResult result = + // api.generate( + // THINKING_TOOL_MODEL_2, + // "Validate: 1+1=2", + // raw, + // thinking, + // new OptionsBuilder().build(), + // new OllamaGenerateStreamObserver(null, null)); + // assertNotNull(result); + // assertNotNull(result.getResponse()); + // assertNotNull(result.getThinking()); + // } /** * Tests generate with all parameters enabled: raw=true, thinking=true, and streaming.