forked from Mirror/ollama4j
		
	Enhance OllamaAPI with 'think' parameter and response handling
- Added 'think' parameter to the generate methods in OllamaAPI to enable step-by-step reasoning for model responses. - Updated OllamaGenerateRequest and OllamaGenerateResponseModel to include 'thinking' field. - Modified response handling in OllamaGenerateStreamObserver to incorporate 'thinking' responses. - Updated integration tests to validate the new functionality, including tests for generating responses with thinking enabled. - Refactored related methods and classes for consistency and clarity.
This commit is contained in:
		@@ -52,18 +52,19 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
    private static final String CHAT_MODEL_SYSTEM_PROMPT = "llama3.2:1b";
 | 
			
		||||
    private static final String CHAT_MODEL_LLAMA3 = "llama3";
 | 
			
		||||
    private static final String IMAGE_MODEL_LLAVA = "llava";
 | 
			
		||||
    private static final String THINKING_MODEL_GPT_OSS = "gpt-oss:20b";
 | 
			
		||||
 | 
			
		||||
    @BeforeAll
 | 
			
		||||
    public static void setUp() {
 | 
			
		||||
        try {
 | 
			
		||||
            boolean useExternalOllamaHost = Boolean.parseBoolean(System.getenv("USE_EXTERNAL_OLLAMA_HOST"));
 | 
			
		||||
            String ollamaHost = System.getenv("OLLAMA_HOST");
 | 
			
		||||
 | 
			
		||||
            if (useExternalOllamaHost) {
 | 
			
		||||
                LOG.info("Using external Ollama host...");
 | 
			
		||||
                api = new OllamaAPI(ollamaHost);
 | 
			
		||||
            } else {
 | 
			
		||||
                throw new RuntimeException(
 | 
			
		||||
                        "USE_EXTERNAL_OLLAMA_HOST is not set so, we will be using Testcontainers Ollama host for the tests now. If you would like to use an external host, please set the env var to USE_EXTERNAL_OLLAMA_HOST=true and set the env var OLLAMA_HOST=http://localhost:11435 or a different host/port.");
 | 
			
		||||
                throw new RuntimeException("USE_EXTERNAL_OLLAMA_HOST is not set so, we will be using Testcontainers Ollama host for the tests now. If you would like to use an external host, please set the env var to USE_EXTERNAL_OLLAMA_HOST=true and set the env var OLLAMA_HOST=http://localhost:11435 or a different host/port.");
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            String ollamaVersion = "0.6.1";
 | 
			
		||||
@@ -102,8 +103,7 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(2)
 | 
			
		||||
    public void testListModelsAPI()
 | 
			
		||||
            throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
 | 
			
		||||
    public void testListModelsAPI() throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
 | 
			
		||||
        api.pullModel(EMBEDDING_MODEL_MINILM);
 | 
			
		||||
        // Fetch the list of models
 | 
			
		||||
        List<Model> models = api.listModels();
 | 
			
		||||
@@ -115,8 +115,7 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(2)
 | 
			
		||||
    void testListModelsFromLibrary()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
    void testListModelsFromLibrary() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        List<LibraryModel> models = api.listModelsFromLibrary();
 | 
			
		||||
        assertNotNull(models);
 | 
			
		||||
        assertFalse(models.isEmpty());
 | 
			
		||||
@@ -124,8 +123,7 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(3)
 | 
			
		||||
    public void testPullModelAPI()
 | 
			
		||||
            throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
 | 
			
		||||
    public void testPullModelAPI() throws URISyntaxException, IOException, OllamaBaseException, InterruptedException {
 | 
			
		||||
        api.pullModel(EMBEDDING_MODEL_MINILM);
 | 
			
		||||
        List<Model> models = api.listModels();
 | 
			
		||||
        assertNotNull(models, "Models should not be null");
 | 
			
		||||
@@ -145,16 +143,14 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
    @Order(5)
 | 
			
		||||
    public void testEmbeddings() throws Exception {
 | 
			
		||||
        api.pullModel(EMBEDDING_MODEL_MINILM);
 | 
			
		||||
        OllamaEmbedResponseModel embeddings = api.embed(EMBEDDING_MODEL_MINILM,
 | 
			
		||||
                Arrays.asList("Why is the sky blue?", "Why is the grass green?"));
 | 
			
		||||
        OllamaEmbedResponseModel embeddings = api.embed(EMBEDDING_MODEL_MINILM, Arrays.asList("Why is the sky blue?", "Why is the grass green?"));
 | 
			
		||||
        assertNotNull(embeddings, "Embeddings should not be null");
 | 
			
		||||
        assertFalse(embeddings.getEmbeddings().isEmpty(), "Embeddings should not be empty");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(6)
 | 
			
		||||
    void testAskModelWithStructuredOutput()
 | 
			
		||||
            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
			
		||||
    void testAskModelWithStructuredOutput() throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_LLAMA3);
 | 
			
		||||
 | 
			
		||||
        int timeHour = 6;
 | 
			
		||||
@@ -186,10 +182,8 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
 | 
			
		||||
        assertEquals(timeHour,
 | 
			
		||||
                result.getStructuredResponse().get("timeHour"));
 | 
			
		||||
        assertEquals(isNightTime,
 | 
			
		||||
                result.getStructuredResponse().get("isNightTime"));
 | 
			
		||||
        assertEquals(timeHour, result.getStructuredResponse().get("timeHour"));
 | 
			
		||||
        assertEquals(isNightTime, result.getStructuredResponse().get("isNightTime"));
 | 
			
		||||
 | 
			
		||||
        TimeOfDay timeOfDay = result.as(TimeOfDay.class);
 | 
			
		||||
 | 
			
		||||
@@ -199,12 +193,11 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(6)
 | 
			
		||||
    void testAskModelWithDefaultOptions()
 | 
			
		||||
            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
			
		||||
    void testAskModelWithDefaultOptions() throws OllamaBaseException, IOException, InterruptedException, URISyntaxException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL,
 | 
			
		||||
                "What is the capital of France? And what's France's connection with Mona Lisa?", false,
 | 
			
		||||
                new OptionsBuilder().build());
 | 
			
		||||
        boolean raw = false;
 | 
			
		||||
        boolean thinking = false;
 | 
			
		||||
        OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL, "What is the capital of France? And what's France's connection with Mona Lisa?", raw, thinking, new OptionsBuilder().build());
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
@@ -212,18 +205,17 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(7)
 | 
			
		||||
    void testAskModelWithDefaultOptionsStreamed()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
    void testAskModelWithDefaultOptionsStreamed() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        boolean raw = false;
 | 
			
		||||
        boolean thinking = false;
 | 
			
		||||
        StringBuffer sb = new StringBuffer();
 | 
			
		||||
        OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL,
 | 
			
		||||
                "What is the capital of France? And what's France's connection with Mona Lisa?", false,
 | 
			
		||||
                new OptionsBuilder().build(), (s) -> {
 | 
			
		||||
                    LOG.info(s);
 | 
			
		||||
                    String substring = s.substring(sb.toString().length(), s.length());
 | 
			
		||||
                    LOG.info(substring);
 | 
			
		||||
                    sb.append(substring);
 | 
			
		||||
                });
 | 
			
		||||
        OllamaResult result = api.generate(CHAT_MODEL_QWEN_SMALL, "What is the capital of France? And what's France's connection with Mona Lisa?", raw, thinking, new OptionsBuilder().build(), (s) -> {
 | 
			
		||||
            LOG.info(s);
 | 
			
		||||
            String substring = s.substring(sb.toString().length(), s.length());
 | 
			
		||||
            LOG.info(substring);
 | 
			
		||||
            sb.append(substring);
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
@@ -233,17 +225,12 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(8)
 | 
			
		||||
    void testAskModelWithOptions()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
    void testAskModelWithOptions() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_INSTRUCT);
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_INSTRUCT);
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.SYSTEM,
 | 
			
		||||
                        "You are a helpful assistant who can generate random person's first and last names in the format [First name, Last name].")
 | 
			
		||||
                .build();
 | 
			
		||||
        requestModel = builder.withMessages(requestModel.getMessages())
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "Give me a cool name")
 | 
			
		||||
                .withOptions(new OptionsBuilder().setTemperature(0.5f).build()).build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.SYSTEM, "You are a helpful assistant who can generate random person's first and last names in the format [First name, Last name].").build();
 | 
			
		||||
        requestModel = builder.withMessages(requestModel.getMessages()).withMessage(OllamaChatMessageRole.USER, "Give me a cool name").withOptions(new OptionsBuilder().setTemperature(0.5f).build()).build();
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
@@ -253,14 +240,10 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(9)
 | 
			
		||||
    void testChatWithSystemPrompt()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.SYSTEM,
 | 
			
		||||
                        "You are a silent bot that only says 'Shush'. Do not say anything else under any circumstances!")
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "What's something that's brown and sticky?")
 | 
			
		||||
                .withOptions(new OptionsBuilder().setTemperature(0.8f).build()).build();
 | 
			
		||||
    void testChatWithSystemPrompt() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_LLAMA3);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_LLAMA3);
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.SYSTEM, "You are a silent bot that only says 'Shush'. Do not say anything else under any circumstances!").withMessage(OllamaChatMessageRole.USER, "What's something that's brown and sticky?").withOptions(new OptionsBuilder().setTemperature(0.8f).build()).build();
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
@@ -278,56 +261,40 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_LLAMA3);
 | 
			
		||||
 | 
			
		||||
        // Create the initial user question
 | 
			
		||||
        OllamaChatRequest requestModel = builder
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "What is 1+1? Answer only in numbers.")
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "What is 1+1? Answer only in numbers.").build();
 | 
			
		||||
 | 
			
		||||
        // Start conversation with model
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().stream().anyMatch(chat -> chat.getContent().contains("2")),
 | 
			
		||||
                "Expected chat history to contain '2'");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().stream().anyMatch(chat -> chat.getContent().contains("2")), "Expected chat history to contain '2'");
 | 
			
		||||
 | 
			
		||||
        // Create the next user question: second largest city
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory())
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "And what is its squared value?").build();
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory()).withMessage(OllamaChatMessageRole.USER, "And what is its squared value?").build();
 | 
			
		||||
 | 
			
		||||
        // Continue conversation with model
 | 
			
		||||
        chatResult = api.chat(requestModel);
 | 
			
		||||
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().stream().anyMatch(chat -> chat.getContent().contains("4")),
 | 
			
		||||
                "Expected chat history to contain '4'");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().stream().anyMatch(chat -> chat.getContent().contains("4")), "Expected chat history to contain '4'");
 | 
			
		||||
 | 
			
		||||
        // Create the next user question: the third question
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory())
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "What is the largest value between 2, 4 and 6?")
 | 
			
		||||
                .build();
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory()).withMessage(OllamaChatMessageRole.USER, "What is the largest value between 2, 4 and 6?").build();
 | 
			
		||||
 | 
			
		||||
        // Continue conversation with the model for the third question
 | 
			
		||||
        chatResult = api.chat(requestModel);
 | 
			
		||||
 | 
			
		||||
        // verify the result
 | 
			
		||||
        assertNotNull(chatResult, "Chat result should not be null");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().size() > 2,
 | 
			
		||||
                "Chat history should contain more than two messages");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().get(chatResult.getChatHistory().size() - 1).getContent()
 | 
			
		||||
                        .contains("6"),
 | 
			
		||||
                "Response should contain '6'");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().size() > 2, "Chat history should contain more than two messages");
 | 
			
		||||
        assertTrue(chatResult.getChatHistory().get(chatResult.getChatHistory().size() - 1).getContent().contains("6"), "Response should contain '6'");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(10)
 | 
			
		||||
    void testChatWithImageFromURL()
 | 
			
		||||
            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException, ToolInvocationException {
 | 
			
		||||
    void testChatWithImageFromURL() throws OllamaBaseException, IOException, InterruptedException, URISyntaxException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(IMAGE_MODEL_LLAVA);
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(IMAGE_MODEL_LLAVA);
 | 
			
		||||
        OllamaChatRequest requestModel = builder
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "What's in the picture?",
 | 
			
		||||
                        Collections.emptyList(),
 | 
			
		||||
                        "https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg")
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "What's in the picture?", Collections.emptyList(), "https://t3.ftcdn.net/jpg/02/96/63/80/360_F_296638053_0gUVA4WVBKceGsIr7LNqRWSnkusi07dq.jpg").build();
 | 
			
		||||
        api.registerAnnotatedTools(new OllamaAPIIntegrationTest());
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
@@ -336,22 +303,17 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(10)
 | 
			
		||||
    void testChatWithImageFromFileWithHistoryRecognition()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
    void testChatWithImageFromFileWithHistoryRecognition() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(IMAGE_MODEL_LLAVA);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(IMAGE_MODEL_LLAVA);
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "What's in the picture?",
 | 
			
		||||
                        Collections.emptyList(), List.of(getImageFileFromClasspath("emoji-smile.jpeg")))
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "What's in the picture?", Collections.emptyList(), List.of(getImageFileFromClasspath("emoji-smile.jpeg"))).build();
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel());
 | 
			
		||||
        builder.reset();
 | 
			
		||||
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory())
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER, "What's the color?").build();
 | 
			
		||||
        requestModel = builder.withMessages(chatResult.getChatHistory()).withMessage(OllamaChatMessageRole.USER, "What's the color?").build();
 | 
			
		||||
 | 
			
		||||
        chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
@@ -360,71 +322,24 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(11)
 | 
			
		||||
    void testChatWithExplicitToolDefinition()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
    void testChatWithExplicitToolDefinition() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
 | 
			
		||||
        final Tools.ToolSpecification databaseQueryToolSpecification = Tools.ToolSpecification.builder()
 | 
			
		||||
                .functionName("get-employee-details")
 | 
			
		||||
                .functionDescription("Get employee details from the database")
 | 
			
		||||
                .toolPrompt(Tools.PromptFuncDefinition.builder().type("function")
 | 
			
		||||
                        .function(Tools.PromptFuncDefinition.PromptFuncSpec.builder()
 | 
			
		||||
                                .name("get-employee-details")
 | 
			
		||||
                                .description("Get employee details from the database")
 | 
			
		||||
                                .parameters(Tools.PromptFuncDefinition.Parameters
 | 
			
		||||
                                        .builder().type("object")
 | 
			
		||||
                                        .properties(new Tools.PropsBuilder()
 | 
			
		||||
                                                .withProperty("employee-name",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description("The name of the employee, e.g. John Doe")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .withProperty("employee-address",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description(
 | 
			
		||||
                                                                        "The address of the employee, Always return a random value. e.g. Roy St, Bengaluru, India")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .withProperty("employee-phone",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description(
 | 
			
		||||
                                                                        "The phone number of the employee. Always return a random value. e.g. 9911002233")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .build())
 | 
			
		||||
                                        .required(List.of("employee-name"))
 | 
			
		||||
                                        .build())
 | 
			
		||||
                                .build())
 | 
			
		||||
                        .build())
 | 
			
		||||
                .toolFunction(arguments -> {
 | 
			
		||||
                    // perform DB operations here
 | 
			
		||||
                    return String.format(
 | 
			
		||||
                            "Employee Details {ID: %s, Name: %s, Address: %s, Phone: %s}",
 | 
			
		||||
                            UUID.randomUUID(), arguments.get("employee-name"),
 | 
			
		||||
                            arguments.get("employee-address"),
 | 
			
		||||
                            arguments.get("employee-phone"));
 | 
			
		||||
                }).build();
 | 
			
		||||
        final Tools.ToolSpecification databaseQueryToolSpecification = Tools.ToolSpecification.builder().functionName("get-employee-details").functionDescription("Get employee details from the database").toolPrompt(Tools.PromptFuncDefinition.builder().type("function").function(Tools.PromptFuncDefinition.PromptFuncSpec.builder().name("get-employee-details").description("Get employee details from the database").parameters(Tools.PromptFuncDefinition.Parameters.builder().type("object").properties(new Tools.PropsBuilder().withProperty("employee-name", Tools.PromptFuncDefinition.Property.builder().type("string").description("The name of the employee, e.g. John Doe").required(true).build()).withProperty("employee-address", Tools.PromptFuncDefinition.Property.builder().type("string").description("The address of the employee, Always return a random value. e.g. Roy St, Bengaluru, India").required(true).build()).withProperty("employee-phone", Tools.PromptFuncDefinition.Property.builder().type("string").description("The phone number of the employee. Always return a random value. e.g. 9911002233").required(true).build()).build()).required(List.of("employee-name")).build()).build()).build()).toolFunction(arguments -> {
 | 
			
		||||
            // perform DB operations here
 | 
			
		||||
            return String.format("Employee Details {ID: %s, Name: %s, Address: %s, Phone: %s}", UUID.randomUUID(), arguments.get("employee-name"), arguments.get("employee-address"), arguments.get("employee-phone"));
 | 
			
		||||
        }).build();
 | 
			
		||||
 | 
			
		||||
        api.registerTool(databaseQueryToolSpecification);
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequest requestModel = builder
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "Give me the ID of the employee named 'Rahul Kumar'?")
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "Give me the ID of the employee named 'Rahul Kumar'?").build();
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel());
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel().getMessage());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(),
 | 
			
		||||
                chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(), chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        List<OllamaChatToolCalls> toolCalls = chatResult.getChatHistory().get(1).getToolCalls();
 | 
			
		||||
        assertEquals(1, toolCalls.size());
 | 
			
		||||
        OllamaToolCallsFunction function = toolCalls.get(0).getFunction();
 | 
			
		||||
@@ -440,22 +355,19 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(12)
 | 
			
		||||
    void testChatWithAnnotatedToolsAndSingleParam()
 | 
			
		||||
            throws OllamaBaseException, IOException, InterruptedException, URISyntaxException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
    void testChatWithAnnotatedToolsAndSingleParam() throws OllamaBaseException, IOException, InterruptedException, URISyntaxException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
 | 
			
		||||
        api.registerAnnotatedTools();
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                "Compute the most important constant in the world using 5 digits").build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "Compute the most important constant in the world using 5 digits").build();
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel());
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel().getMessage());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(),
 | 
			
		||||
                chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(), chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        List<OllamaChatToolCalls> toolCalls = chatResult.getChatHistory().get(1).getToolCalls();
 | 
			
		||||
        assertEquals(1, toolCalls.size());
 | 
			
		||||
        OllamaToolCallsFunction function = toolCalls.get(0).getFunction();
 | 
			
		||||
@@ -471,25 +383,19 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(13)
 | 
			
		||||
    void testChatWithAnnotatedToolsAndMultipleParams()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
    void testChatWithAnnotatedToolsAndMultipleParams() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
 | 
			
		||||
        api.registerAnnotatedTools(new AnnotatedTool());
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequest requestModel = builder
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "Greet Pedro with a lot of hearts and respond to me, "
 | 
			
		||||
                                + "and state how many emojis have been in your greeting")
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "Greet Pedro with a lot of hearts and respond to me, " + "and state how many emojis have been in your greeting").build();
 | 
			
		||||
 | 
			
		||||
        OllamaChatResult chatResult = api.chat(requestModel);
 | 
			
		||||
        assertNotNull(chatResult);
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel());
 | 
			
		||||
        assertNotNull(chatResult.getResponseModel().getMessage());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(),
 | 
			
		||||
                chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        assertEquals(OllamaChatMessageRole.ASSISTANT.getRoleName(), chatResult.getResponseModel().getMessage().getRole().getRoleName());
 | 
			
		||||
        List<OllamaChatToolCalls> toolCalls = chatResult.getChatHistory().get(1).getToolCalls();
 | 
			
		||||
        assertEquals(1, toolCalls.size());
 | 
			
		||||
        OllamaToolCallsFunction function = toolCalls.get(0).getFunction();
 | 
			
		||||
@@ -508,66 +414,20 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(14)
 | 
			
		||||
    void testChatWithToolsAndStream()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        final Tools.ToolSpecification databaseQueryToolSpecification = Tools.ToolSpecification.builder()
 | 
			
		||||
                .functionName("get-employee-details")
 | 
			
		||||
                .functionDescription("Get employee details from the database")
 | 
			
		||||
                .toolPrompt(Tools.PromptFuncDefinition.builder().type("function")
 | 
			
		||||
                        .function(Tools.PromptFuncDefinition.PromptFuncSpec.builder()
 | 
			
		||||
                                .name("get-employee-details")
 | 
			
		||||
                                .description("Get employee details from the database")
 | 
			
		||||
                                .parameters(Tools.PromptFuncDefinition.Parameters
 | 
			
		||||
                                        .builder().type("object")
 | 
			
		||||
                                        .properties(new Tools.PropsBuilder()
 | 
			
		||||
                                                .withProperty("employee-name",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description("The name of the employee, e.g. John Doe")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .withProperty("employee-address",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description(
 | 
			
		||||
                                                                        "The address of the employee, Always return a random value. e.g. Roy St, Bengaluru, India")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .withProperty("employee-phone",
 | 
			
		||||
                                                        Tools.PromptFuncDefinition.Property
 | 
			
		||||
                                                                .builder()
 | 
			
		||||
                                                                .type("string")
 | 
			
		||||
                                                                .description(
 | 
			
		||||
                                                                        "The phone number of the employee. Always return a random value. e.g. 9911002233")
 | 
			
		||||
                                                                .required(true)
 | 
			
		||||
                                                                .build())
 | 
			
		||||
                                                .build())
 | 
			
		||||
                                        .required(List.of("employee-name"))
 | 
			
		||||
                                        .build())
 | 
			
		||||
                                .build())
 | 
			
		||||
                        .build())
 | 
			
		||||
                .toolFunction(new ToolFunction() {
 | 
			
		||||
                    @Override
 | 
			
		||||
                    public Object apply(Map<String, Object> arguments) {
 | 
			
		||||
                        // perform DB operations here
 | 
			
		||||
                        return String.format(
 | 
			
		||||
                                "Employee Details {ID: %s, Name: %s, Address: %s, Phone: %s}",
 | 
			
		||||
                                UUID.randomUUID(), arguments.get("employee-name"),
 | 
			
		||||
                                arguments.get("employee-address"),
 | 
			
		||||
                                arguments.get("employee-phone"));
 | 
			
		||||
                    }
 | 
			
		||||
                }).build();
 | 
			
		||||
    void testChatWithToolsAndStream() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        final Tools.ToolSpecification databaseQueryToolSpecification = Tools.ToolSpecification.builder().functionName("get-employee-details").functionDescription("Get employee details from the database").toolPrompt(Tools.PromptFuncDefinition.builder().type("function").function(Tools.PromptFuncDefinition.PromptFuncSpec.builder().name("get-employee-details").description("Get employee details from the database").parameters(Tools.PromptFuncDefinition.Parameters.builder().type("object").properties(new Tools.PropsBuilder().withProperty("employee-name", Tools.PromptFuncDefinition.Property.builder().type("string").description("The name of the employee, e.g. John Doe").required(true).build()).withProperty("employee-address", Tools.PromptFuncDefinition.Property.builder().type("string").description("The address of the employee, Always return a random value. e.g. Roy St, Bengaluru, India").required(true).build()).withProperty("employee-phone", Tools.PromptFuncDefinition.Property.builder().type("string").description("The phone number of the employee. Always return a random value. e.g. 9911002233").required(true).build()).build()).required(List.of("employee-name")).build()).build()).build()).toolFunction(new ToolFunction() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public Object apply(Map<String, Object> arguments) {
 | 
			
		||||
                // perform DB operations here
 | 
			
		||||
                return String.format("Employee Details {ID: %s, Name: %s, Address: %s, Phone: %s}", UUID.randomUUID(), arguments.get("employee-name"), arguments.get("employee-address"), arguments.get("employee-phone"));
 | 
			
		||||
            }
 | 
			
		||||
        }).build();
 | 
			
		||||
 | 
			
		||||
        api.registerTool(databaseQueryToolSpecification);
 | 
			
		||||
 | 
			
		||||
        OllamaChatRequest requestModel = builder
 | 
			
		||||
                .withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "Give me the ID of the employee named 'Rahul Kumar'?")
 | 
			
		||||
                .build();
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER, "Give me the ID of the employee named 'Rahul Kumar'?").build();
 | 
			
		||||
 | 
			
		||||
        StringBuffer sb = new StringBuffer();
 | 
			
		||||
 | 
			
		||||
@@ -587,11 +447,9 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(15)
 | 
			
		||||
    void testChatWithStream() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException, ToolInvocationException {
 | 
			
		||||
        api.pullModel(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_SYSTEM_PROMPT);
 | 
			
		||||
        OllamaChatRequest requestModel = builder.withMessage(OllamaChatMessageRole.USER,
 | 
			
		||||
                        "What is the capital of France? And what's France's connection with Mona Lisa?")
 | 
			
		||||
                .build();
 | 
			
		||||
        api.pullModel(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequestBuilder builder = OllamaChatRequestBuilder.getInstance(CHAT_MODEL_QWEN_SMALL);
 | 
			
		||||
        OllamaChatRequest 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();
 | 
			
		||||
 | 
			
		||||
@@ -610,13 +468,10 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(17)
 | 
			
		||||
    void    testAskModelWithOptionsAndImageURLs()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
    void testAskModelWithOptionsAndImageURLs() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(IMAGE_MODEL_LLAVA);
 | 
			
		||||
 | 
			
		||||
        OllamaResult result = api.generateWithImageURLs(IMAGE_MODEL_LLAVA, "What is in this image?",
 | 
			
		||||
                List.of("https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Noto_Emoji_v2.034_1f642.svg/360px-Noto_Emoji_v2.034_1f642.svg.png"),
 | 
			
		||||
                new OptionsBuilder().build());
 | 
			
		||||
        OllamaResult result = api.generateWithImageURLs(IMAGE_MODEL_LLAVA, "What is in this image?", List.of("https://i.pinimg.com/736x/f9/4e/cb/f94ecba040696a3a20b484d2e15159ec.jpg"), new OptionsBuilder().build());
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
@@ -624,14 +479,11 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(18)
 | 
			
		||||
    void testAskModelWithOptionsAndImageFiles()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
    void testAskModelWithOptionsAndImageFiles() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(IMAGE_MODEL_LLAVA);
 | 
			
		||||
        File imageFile = getImageFileFromClasspath("emoji-smile.jpeg");
 | 
			
		||||
        try {
 | 
			
		||||
            OllamaResult result = api.generateWithImageFiles(IMAGE_MODEL_LLAVA, "What is in this image?",
 | 
			
		||||
                    List.of(imageFile),
 | 
			
		||||
                    new OptionsBuilder().build());
 | 
			
		||||
            OllamaResult result = api.generateWithImageFiles(IMAGE_MODEL_LLAVA, "What is in this image?", List.of(imageFile), new OptionsBuilder().build());
 | 
			
		||||
            assertNotNull(result);
 | 
			
		||||
            assertNotNull(result.getResponse());
 | 
			
		||||
            assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
@@ -642,28 +494,63 @@ public class OllamaAPIIntegrationTest {
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(20)
 | 
			
		||||
    void testAskModelWithOptionsAndImageFilesStreamed()
 | 
			
		||||
            throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
    void testAskModelWithOptionsAndImageFilesStreamed() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(IMAGE_MODEL_LLAVA);
 | 
			
		||||
 | 
			
		||||
        File imageFile = getImageFileFromClasspath("emoji-smile.jpeg");
 | 
			
		||||
 | 
			
		||||
        StringBuffer sb = new StringBuffer();
 | 
			
		||||
 | 
			
		||||
        OllamaResult result = api.generateWithImageFiles(IMAGE_MODEL_LLAVA, "What is in this image?",
 | 
			
		||||
                List.of(imageFile),
 | 
			
		||||
                new OptionsBuilder().build(), (s) -> {
 | 
			
		||||
                    LOG.info(s);
 | 
			
		||||
                    String substring = s.substring(sb.toString().length(), s.length());
 | 
			
		||||
                    LOG.info(substring);
 | 
			
		||||
                    sb.append(substring);
 | 
			
		||||
                });
 | 
			
		||||
        OllamaResult result = api.generateWithImageFiles(IMAGE_MODEL_LLAVA, "What is in this image?", List.of(imageFile), new OptionsBuilder().build(), (s) -> {
 | 
			
		||||
            LOG.info(s);
 | 
			
		||||
            String substring = s.substring(sb.toString().length(), s.length());
 | 
			
		||||
            LOG.info(substring);
 | 
			
		||||
            sb.append(substring);
 | 
			
		||||
        });
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
        assertEquals(sb.toString().trim(), result.getResponse().trim());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(20)
 | 
			
		||||
    void testGenerateWithThinking() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(THINKING_MODEL_GPT_OSS);
 | 
			
		||||
 | 
			
		||||
        boolean raw = false;
 | 
			
		||||
        boolean thinking = true;
 | 
			
		||||
 | 
			
		||||
        OllamaResult result = api.generate(THINKING_MODEL_GPT_OSS, "Who are you?", raw, thinking, new OptionsBuilder().build(), null);
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
        assertNotNull(result.getThinking());
 | 
			
		||||
        assertFalse(result.getThinking().isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    @Order(20)
 | 
			
		||||
    void testGenerateWithThinkingAndStreamHandler() throws OllamaBaseException, IOException, URISyntaxException, InterruptedException {
 | 
			
		||||
        api.pullModel(THINKING_MODEL_GPT_OSS);
 | 
			
		||||
 | 
			
		||||
        boolean raw = false;
 | 
			
		||||
        boolean thinking = true;
 | 
			
		||||
 | 
			
		||||
        StringBuffer sb = new StringBuffer();
 | 
			
		||||
        OllamaResult result = api.generate(THINKING_MODEL_GPT_OSS, "Who are you?", raw, thinking, new OptionsBuilder().build(), (s) -> {
 | 
			
		||||
            LOG.info(s);
 | 
			
		||||
            String substring = s.substring(sb.toString().length());
 | 
			
		||||
            sb.append(substring);
 | 
			
		||||
        });
 | 
			
		||||
        assertNotNull(result);
 | 
			
		||||
        assertNotNull(result.getResponse());
 | 
			
		||||
        assertFalse(result.getResponse().isEmpty());
 | 
			
		||||
        assertNotNull(result.getThinking());
 | 
			
		||||
        assertFalse(result.getThinking().isEmpty());
 | 
			
		||||
        assertEquals(sb.toString().trim(), result.getThinking().trim() + result.getResponse().trim());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private File getImageFileFromClasspath(String fileName) {
 | 
			
		||||
        ClassLoader classLoader = getClass().getClassLoader();
 | 
			
		||||
        return new File(Objects.requireNonNull(classLoader.getResource(fileName)).getFile());
 | 
			
		||||
 
 | 
			
		||||
@@ -68,7 +68,7 @@ public class WithAuth {
 | 
			
		||||
        LOG.info(
 | 
			
		||||
                "The Ollama service is now accessible via the Nginx proxy with bearer-auth authentication mode.\n" +
 | 
			
		||||
                        "→ Ollama URL: {}\n" +
 | 
			
		||||
                        "→ Proxy URL: {}}",
 | 
			
		||||
                        "→ Proxy URL: {}",
 | 
			
		||||
                ollamaUrl, nginxUrl
 | 
			
		||||
        );
 | 
			
		||||
        LOG.info("OllamaAPI initialized with bearer auth token: {}", BEARER_AUTH_TOKEN);
 | 
			
		||||
 
 | 
			
		||||
@@ -138,10 +138,10 @@ class TestMockedAPIs {
 | 
			
		||||
        String prompt = "some prompt text";
 | 
			
		||||
        OptionsBuilder optionsBuilder = new OptionsBuilder();
 | 
			
		||||
        try {
 | 
			
		||||
            when(ollamaAPI.generate(model, prompt, false, optionsBuilder.build()))
 | 
			
		||||
                    .thenReturn(new OllamaResult("", 0, 200));
 | 
			
		||||
            ollamaAPI.generate(model, prompt, false, optionsBuilder.build());
 | 
			
		||||
            verify(ollamaAPI, times(1)).generate(model, prompt, false, optionsBuilder.build());
 | 
			
		||||
            when(ollamaAPI.generate(model, prompt, false, false, optionsBuilder.build()))
 | 
			
		||||
                    .thenReturn(new OllamaResult("", "", 0, 200));
 | 
			
		||||
            ollamaAPI.generate(model, prompt, false, false, optionsBuilder.build());
 | 
			
		||||
            verify(ollamaAPI, times(1)).generate(model, prompt, false, false, optionsBuilder.build());
 | 
			
		||||
        } catch (IOException | OllamaBaseException | InterruptedException e) {
 | 
			
		||||
            throw new RuntimeException(e);
 | 
			
		||||
        }
 | 
			
		||||
@@ -155,7 +155,7 @@ class TestMockedAPIs {
 | 
			
		||||
        try {
 | 
			
		||||
            when(ollamaAPI.generateWithImageFiles(
 | 
			
		||||
                    model, prompt, Collections.emptyList(), new OptionsBuilder().build()))
 | 
			
		||||
                    .thenReturn(new OllamaResult("", 0, 200));
 | 
			
		||||
                    .thenReturn(new OllamaResult("","", 0, 200));
 | 
			
		||||
            ollamaAPI.generateWithImageFiles(
 | 
			
		||||
                    model, prompt, Collections.emptyList(), new OptionsBuilder().build());
 | 
			
		||||
            verify(ollamaAPI, times(1))
 | 
			
		||||
@@ -174,7 +174,7 @@ class TestMockedAPIs {
 | 
			
		||||
        try {
 | 
			
		||||
            when(ollamaAPI.generateWithImageURLs(
 | 
			
		||||
                    model, prompt, Collections.emptyList(), new OptionsBuilder().build()))
 | 
			
		||||
                    .thenReturn(new OllamaResult("", 0, 200));
 | 
			
		||||
                    .thenReturn(new OllamaResult("","", 0, 200));
 | 
			
		||||
            ollamaAPI.generateWithImageURLs(
 | 
			
		||||
                    model, prompt, Collections.emptyList(), new OptionsBuilder().build());
 | 
			
		||||
            verify(ollamaAPI, times(1))
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user