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.
This commit is contained in:
amithkoujalgi 2025-09-20 15:40:02 +05:30
parent cac94e0faf
commit 7a2a307a0a
No known key found for this signature in database
GPG Key ID: E29A37746AF94B70
5 changed files with 56 additions and 49 deletions

View File

@ -26,6 +26,14 @@ repos:
- id: commitizen - id: commitizen
stages: [commit-msg] 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 # # for java code quality
# - repo: https://github.com/gherynos/pre-commit-java # - repo: https://github.com/gherynos/pre-commit-java
# rev: v0.6.10 # rev: v0.6.10

View File

@ -5,7 +5,7 @@
* Licensed under the MIT License (the "License"); * Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* *
*/ */
package io.github.ollama4j; package io.github.ollama4j;
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParseException;

View File

@ -5,7 +5,7 @@
* Licensed under the MIT License (the "License"); * Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* *
*/ */
package io.github.ollama4j.models.chat; package io.github.ollama4j.models.chat;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;

View File

@ -5,7 +5,7 @@
* Licensed under the MIT License (the "License"); * Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* *
*/ */
package io.github.ollama4j.models.chat; package io.github.ollama4j.models.chat;
import io.github.ollama4j.utils.Options; import io.github.ollama4j.utils.Options;
@ -17,7 +17,6 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.Setter; import lombok.Setter;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -30,8 +29,7 @@ public class OllamaChatRequestBuilder {
private int imageURLConnectTimeoutSeconds = 10; private int imageURLConnectTimeoutSeconds = 10;
private int imageURLReadTimeoutSeconds = 10; private int imageURLReadTimeoutSeconds = 10;
@Setter @Setter private boolean useTools = true;
private boolean useTools = true;
public OllamaChatRequestBuilder withImageURLConnectTimeoutSeconds( public OllamaChatRequestBuilder withImageURLConnectTimeoutSeconds(
int imageURLConnectTimeoutSeconds) { int imageURLConnectTimeoutSeconds) {

View File

@ -5,7 +5,7 @@
* Licensed under the MIT License (the "License"); * Licensed under the MIT License (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* *
*/ */
package io.github.ollama4j.integrationtests; package io.github.ollama4j.integrationtests;
import static org.junit.jupiter.api.Assertions.*; 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.Tools;
import io.github.ollama4j.tools.annotations.OllamaToolService; import io.github.ollama4j.tools.annotations.OllamaToolService;
import io.github.ollama4j.utils.OptionsBuilder; 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.BeforeAll;
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Order;
@ -38,13 +43,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.ollama.OllamaContainer; 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}) @OllamaToolService(providers = {AnnotatedTool.class})
@TestMethodOrder(OrderAnnotation.class) @TestMethodOrder(OrderAnnotation.class)
@SuppressWarnings({"HttpUrlsUsage", "SpellCheckingInspection", "FieldCanBeLocal", "ConstantValue"}) @SuppressWarnings({"HttpUrlsUsage", "SpellCheckingInspection", "FieldCanBeLocal", "ConstantValue"})
@ -113,10 +111,10 @@ class OllamaAPIIntegrationTest {
} else { } else {
throw new RuntimeException( throw new RuntimeException(
"USE_EXTERNAL_OLLAMA_HOST is not set so, we will be using Testcontainers" "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" + " 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" + " 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" + " set the env var OLLAMA_HOST=http://localhost:11435 or a different"
+ " host/port."); + " host/port.");
} }
} catch (Exception e) { } catch (Exception e) {
String ollamaVersion = "0.6.1"; String ollamaVersion = "0.6.1";
@ -410,8 +408,8 @@ class OllamaAPIIntegrationTest {
OllamaChatMessageRole.SYSTEM, OllamaChatMessageRole.SYSTEM,
String.format( String.format(
"[INSTRUCTION-START] You are an obidient and helpful bot" "[INSTRUCTION-START] You are an obidient and helpful bot"
+ " named %s. You always answer with only one word and" + " named %s. You always answer with only one word and"
+ " that word is your name. [INSTRUCTION-END]", + " that word is your name. [INSTRUCTION-END]",
expectedResponse)) expectedResponse))
.withMessage(OllamaChatMessageRole.USER, "Who are you?") .withMessage(OllamaChatMessageRole.USER, "Who are you?")
.withOptions(new OptionsBuilder().setTemperature(0.0f).build()) .withOptions(new OptionsBuilder().setTemperature(0.0f).build())
@ -1112,7 +1110,8 @@ class OllamaAPIIntegrationTest {
OllamaResult result = OllamaResult result =
api.generate( api.generate(
THINKING_TOOL_MODEL, 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, raw,
true, true,
new OptionsBuilder().setTemperature(0.1f).build(), new OptionsBuilder().setTemperature(0.1f).build(),
@ -1137,7 +1136,8 @@ class OllamaAPIIntegrationTest {
api.pullModel(TOOLS_MODEL); api.pullModel(TOOLS_MODEL);
String prompt = 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<String, Object> format = new HashMap<>(); Map<String, Object> format = new HashMap<>();
format.put("type", "object"); format.put("type", "object");
@ -1270,7 +1270,8 @@ class OllamaAPIIntegrationTest {
OllamaChatRequest requestModel = OllamaChatRequest requestModel =
builder.withMessage( builder.withMessage(
OllamaChatMessageRole.USER, 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) .withThinking(true)
.withOptions(new OptionsBuilder().setTemperature(0.1f).build()) .withOptions(new OptionsBuilder().setTemperature(0.1f).build())
.build(); .build();
@ -1654,11 +1655,11 @@ class OllamaAPIIntegrationTest {
"string") "string")
.description( .description(
"The name" "The name"
+ " of the" + " of the"
+ " employee," + " employee,"
+ " e.g." + " e.g."
+ " John" + " John"
+ " Doe") + " Doe")
.required( .required(
true) true)
.build()) .build())
@ -1672,16 +1673,16 @@ class OllamaAPIIntegrationTest {
"string") "string")
.description( .description(
"The address" "The address"
+ " of the" + " of the"
+ " employee," + " employee,"
+ " Always" + " Always"
+ " returns" + " returns"
+ " a random" + " a random"
+ " address." + " address."
+ " For example," + " For example,"
+ " Church" + " Church"
+ " St, Bengaluru," + " St, Bengaluru,"
+ " India") + " India")
.required( .required(
true) true)
.build()) .build())
@ -1695,16 +1696,16 @@ class OllamaAPIIntegrationTest {
"string") "string")
.description( .description(
"The phone" "The phone"
+ " number" + " number"
+ " of the" + " of the"
+ " employee." + " employee."
+ " Always" + " Always"
+ " returns" + " returns"
+ " a random" + " a random"
+ " phone" + " phone"
+ " number." + " number."
+ " For example," + " For example,"
+ " 9911002233") + " 9911002233")
.required( .required(
true) true)
.build()) .build())