From 7a2a307a0aa529abcc716e759852c2a4392173b3 Mon Sep 17 00:00:00 2001 From: amithkoujalgi Date: Sat, 20 Sep 2025 15:40:02 +0530 Subject: [PATCH] Add local format-code hook to pre-commit config Introduces a new local hook 'format-code' that runs 'make apply-formatting' to ensure code formatting is applied automatically during pre-commit. The hook is set to always run. --- .pre-commit-config.yaml | 8 ++ .../java/io/github/ollama4j/OllamaAPI.java | 2 +- .../models/chat/OllamaChatRequest.java | 2 +- .../models/chat/OllamaChatRequestBuilder.java | 6 +- .../OllamaAPIIntegrationTest.java | 87 ++++++++++--------- 5 files changed, 56 insertions(+), 49 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 94a13b9..94d3f75 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,6 +26,14 @@ repos: - id: commitizen stages: [commit-msg] + - repo: local + hooks: + - id: format-code + name: Format Code + entry: make apply-formatting + language: system + always_run: true + # # for java code quality # - repo: https://github.com/gherynos/pre-commit-java # rev: v0.6.10 diff --git a/src/main/java/io/github/ollama4j/OllamaAPI.java b/src/main/java/io/github/ollama4j/OllamaAPI.java index 110e3b2..985eaf0 100644 --- a/src/main/java/io/github/ollama4j/OllamaAPI.java +++ b/src/main/java/io/github/ollama4j/OllamaAPI.java @@ -5,7 +5,7 @@ * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. * - */ +*/ package io.github.ollama4j; import com.fasterxml.jackson.core.JsonParseException; diff --git a/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequest.java b/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequest.java index e5c21a1..a208ecb 100644 --- a/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequest.java +++ b/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequest.java @@ -5,7 +5,7 @@ * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. * - */ +*/ package io.github.ollama4j.models.chat; import com.fasterxml.jackson.annotation.JsonProperty; diff --git a/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequestBuilder.java b/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequestBuilder.java index c1ea520..39bbd24 100644 --- a/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequestBuilder.java +++ b/src/main/java/io/github/ollama4j/models/chat/OllamaChatRequestBuilder.java @@ -5,7 +5,7 @@ * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. * - */ +*/ package io.github.ollama4j.models.chat; import io.github.ollama4j.utils.Options; @@ -17,7 +17,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; - import lombok.Setter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -30,8 +29,7 @@ public class OllamaChatRequestBuilder { private int imageURLConnectTimeoutSeconds = 10; private int imageURLReadTimeoutSeconds = 10; - @Setter - private boolean useTools = true; + @Setter private boolean useTools = true; public OllamaChatRequestBuilder withImageURLConnectTimeoutSeconds( int imageURLConnectTimeoutSeconds) { diff --git a/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java b/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java index e0fc423..b60d6df 100644 --- a/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java +++ b/src/test/java/io/github/ollama4j/integrationtests/OllamaAPIIntegrationTest.java @@ -5,7 +5,7 @@ * Licensed under the MIT License (the "License"); * you may not use this file except in compliance with the License. * - */ +*/ package io.github.ollama4j.integrationtests; import static org.junit.jupiter.api.Assertions.*; @@ -28,7 +28,12 @@ import io.github.ollama4j.tools.ToolFunction; import io.github.ollama4j.tools.Tools; import io.github.ollama4j.tools.annotations.OllamaToolService; import io.github.ollama4j.utils.OptionsBuilder; - +import java.io.File; +import java.io.IOException; +import java.net.ConnectException; +import java.net.URISyntaxException; +import java.util.*; +import java.util.concurrent.CountDownLatch; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; @@ -38,13 +43,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.ollama.OllamaContainer; -import java.io.File; -import java.io.IOException; -import java.net.ConnectException; -import java.net.URISyntaxException; -import java.util.*; -import java.util.concurrent.CountDownLatch; - @OllamaToolService(providers = {AnnotatedTool.class}) @TestMethodOrder(OrderAnnotation.class) @SuppressWarnings({"HttpUrlsUsage", "SpellCheckingInspection", "FieldCanBeLocal", "ConstantValue"}) @@ -113,10 +111,10 @@ class OllamaAPIIntegrationTest { } 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."); + + " 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"; @@ -410,8 +408,8 @@ class OllamaAPIIntegrationTest { OllamaChatMessageRole.SYSTEM, String.format( "[INSTRUCTION-START] You are an obidient and helpful bot" - + " named %s. You always answer with only one word and" - + " that word is your name. [INSTRUCTION-END]", + + " named %s. You always answer with only one word and" + + " that word is your name. [INSTRUCTION-END]", expectedResponse)) .withMessage(OllamaChatMessageRole.USER, "Who are you?") .withOptions(new OptionsBuilder().setTemperature(0.0f).build()) @@ -1112,7 +1110,8 @@ class OllamaAPIIntegrationTest { OllamaResult result = api.generate( THINKING_TOOL_MODEL, - "Count 1 to 5. Just give me the numbers and do not give any other details or information.", + "Count 1 to 5. Just give me the numbers and do not give any other details" + + " or information.", raw, true, new OptionsBuilder().setTemperature(0.1f).build(), @@ -1137,7 +1136,8 @@ class OllamaAPIIntegrationTest { api.pullModel(TOOLS_MODEL); String prompt = - "Generate information about three major cities: their names, populations, and top attractions."; + "Generate information about three major cities: their names, populations, and top" + + " attractions."; Map format = new HashMap<>(); format.put("type", "object"); @@ -1270,7 +1270,8 @@ class OllamaAPIIntegrationTest { OllamaChatRequest requestModel = builder.withMessage( OllamaChatMessageRole.USER, - "I need to find information about employee John Smith. Think carefully about what details to retrieve.") + "I need to find information about employee John Smith. Think" + + " carefully about what details to retrieve.") .withThinking(true) .withOptions(new OptionsBuilder().setTemperature(0.1f).build()) .build(); @@ -1654,11 +1655,11 @@ class OllamaAPIIntegrationTest { "string") .description( "The name" - + " of the" - + " employee," - + " e.g." - + " John" - + " Doe") + + " of the" + + " employee," + + " e.g." + + " John" + + " Doe") .required( true) .build()) @@ -1672,16 +1673,16 @@ class OllamaAPIIntegrationTest { "string") .description( "The address" - + " of the" - + " employee," - + " Always" - + " returns" - + " a random" - + " address." - + " For example," - + " Church" - + " St, Bengaluru," - + " India") + + " of the" + + " employee," + + " Always" + + " returns" + + " a random" + + " address." + + " For example," + + " Church" + + " St, Bengaluru," + + " India") .required( true) .build()) @@ -1695,16 +1696,16 @@ class OllamaAPIIntegrationTest { "string") .description( "The phone" - + " number" - + " of the" - + " employee." - + " Always" - + " returns" - + " a random" - + " phone" - + " number." - + " For example," - + " 9911002233") + + " number" + + " of the" + + " employee." + + " Always" + + " returns" + + " a random" + + " phone" + + " number." + + " For example," + + " 9911002233") .required( true) .build())