Various checkstyle fixes

This commit is contained in:
Soby Chacko
2024-11-18 19:17:09 -05:00
parent c038526dd1
commit f5b00a027c
38 changed files with 86 additions and 85 deletions

View File

@@ -298,12 +298,14 @@ public class AnthropicApi {
/**
* The user role.
*/
@JsonProperty("user") USER,
@JsonProperty("user")
USER,
/**
* The assistant role.
*/
@JsonProperty("assistant") ASSISTANT
@JsonProperty("assistant")
ASSISTANT
// @formatter:on
}
@@ -824,7 +826,7 @@ public class AnthropicApi {
/**
* Chat completion response object.
*
*
* @param id Unique object identifier. The format and length of IDs may change over
* time.
* @param type Object type. For Messages, this is always "message".

View File

@@ -28,8 +28,9 @@ import org.springframework.ai.anthropic.api.AnthropicApi.ChatCompletionResponse;
import org.springframework.ai.anthropic.api.AnthropicApi.ContentBlock;
import org.springframework.ai.anthropic.api.AnthropicApi.Role;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
/**
* @author Christian Tzolov

View File

@@ -124,7 +124,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.user("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius.")
.functions(FunctionCallback.builder()
.description("Get the weather in location")
.method("getWeatherNonStatic",String.class, Unit.class)
.method("getWeatherNonStatic", String.class, Unit.class)
.targetObject(targetObject)
.build())
.call()
@@ -148,7 +148,7 @@ class AnthropicChatClientMethodInvokingFunctionCallbackIT {
.description("Get the weather in location")
.method("getWeatherWithContext", String.class, Unit.class, ToolContext.class)
.targetObject(targetObject)
.build())
.build())
.toolContext(Map.of("tool", "value"))
.call()
.content();

View File

@@ -257,7 +257,7 @@ class BedrockConverseChatClientIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.defaultUser(u -> u.text("What's the weather like in San Francisco, Tokyo, and Paris? Return the temperature in Celsius."))
.build()
.prompt()
@@ -280,7 +280,7 @@ class BedrockConverseChatClientIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.stream()
.content();
// @formatter:on

View File

@@ -35,7 +35,7 @@ import org.springframework.util.Assert;
/**
* Anthropic Chat API.
*
*
* @author Christian Tzolov
* @author Thomas Vitale
* @author Wei Jiang

View File

@@ -244,7 +244,7 @@ public class Anthropic3ChatOptions implements ChatOptions {
/**
* Builder for {@link Anthropic3ChatOptions}.
*/
public static class Builder {
public static final class Builder {
private final Anthropic3ChatOptions options = new Anthropic3ChatOptions();

View File

@@ -248,7 +248,7 @@ public class Anthropic3ChatBedrockApi extends
private Double topP;
private List<String> stopSequences;
private String anthropicVersion;
private Builder(List<ChatCompletionMessage> messages) {
this.messages = messages;
}

View File

@@ -249,7 +249,7 @@ public class Ai21Jurassic2ChatBedrockApi extends
/**
* Builder for {@link Ai21Jurassic2ChatRequest}.
*/
public static class Builder {
public static final class Builder {
private String prompt;
private Double temperature;
private Double topP;

View File

@@ -24,7 +24,6 @@ import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.ai.chat.messages.AssistantMessage;
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.Generation;

View File

@@ -229,7 +229,7 @@ class MistralAiChatClientIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.call()
.content();
// @formatter:on
@@ -275,7 +275,7 @@ class MistralAiChatClientIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.stream()
.content();
// @formatter:on

View File

@@ -24,7 +24,6 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.ollama.BaseOllamaIT;
import org.springframework.ai.ollama.api.OllamaApi.ChatRequest;
import org.springframework.ai.ollama.api.OllamaApi.ChatResponse;

View File

@@ -142,6 +142,15 @@ public class OpenAiUsage implements Usage {
valueOrZero(details.rejectedPredictionTokens()));
}
@Override
public String toString() {
return getUsage().toString();
}
private int valueOrZero(Integer value) {
return value != null ? value : 0;
}
public record PromptTokensDetails(// @formatter:off
Integer audioTokens,
Integer cachedTokens) {
@@ -154,13 +163,4 @@ public class OpenAiUsage implements Usage {
Integer rejectedPredictionTokens) { // @formatter:on
}
@Override
public String toString() {
return getUsage().toString();
}
private int valueOrZero(Integer value) {
return value != null ? value : 0;
}
}

View File

@@ -105,11 +105,10 @@ class OpenAiSpeechModelIT extends AbstractIT {
assertThat(responseFlux).isNotNull();
List<SpeechResponse> responses = responseFlux.collectList().block();
assertThat(responses).isNotNull();
responses.forEach(response -> {
// System.out.println("Audio data chunk size: " +
// response.getResult().getOutput().length);
assertThat(response.getResult().getOutput()).isNotEmpty();
});
responses.forEach(response ->
// System.out.println("Audio data chunk size: " +
// response.getResult().getOutput().length);
assertThat(response.getResult().getOutput()).isNotEmpty());
}
}

View File

@@ -62,7 +62,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.user("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius.")
.functions(FunctionCallback.builder()
.description("Get the weather in location")
.method("getWeatherStatic",String.class, Unit.class)
.method("getWeatherStatic", String.class, Unit.class)
.targetClass(TestFunctionClass.class)
.build())
.call()
@@ -107,7 +107,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.user("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius.")
.functions(FunctionCallback.builder()
.description("Get the weather in location")
.method("getWeatherNonStatic",String.class, Unit.class)
.method("getWeatherNonStatic", String.class, Unit.class)
.targetObject(targetObject)
.build())
.call()
@@ -129,7 +129,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.user("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius.")
.functions(FunctionCallback.builder()
.description("Get the weather in location")
.method("getWeatherWithContext", String.class, Unit.class, ToolContext.class)
.method("getWeatherWithContext", String.class, Unit.class, ToolContext.class)
.targetObject(targetObject)
.build())
.toolContext(Map.of("tool", "value"))
@@ -176,7 +176,7 @@ class OpenAiChatClientMethodInvokingFunctionCallbackIT {
.description("Can turn lights on in the Living Room")
.method("turnLivingRoomLightOn")
.targetObject(targetObject)
.build())
.build())
.call()
.content();
// @formatter:on

View File

@@ -88,7 +88,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.call()
.content();
// @formatter:on
@@ -229,7 +229,7 @@ class OpenAiChatClientMultipleFunctionCallsIT extends AbstractIT {
.description("Get the weather in location")
.function("getCurrentWeather", new MockWeatherService())
.inputType(MockWeatherService.Request.class)
.build())
.build())
.stream()
.content();
// @formatter:on

View File

@@ -25,7 +25,6 @@ import java.util.Map;
import org.springframework.ai.chat.metadata.EmptyUsage;
import org.springframework.ai.document.Document;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.embedding.AbstractEmbeddingModel;
import org.springframework.ai.embedding.Embedding;
import org.springframework.ai.embedding.EmbeddingOptions;

View File

@@ -168,7 +168,7 @@ public class VertexAiEmbeddingConnectionDetails {
if (this.predictionServiceSettings == null) {
try {
this.predictionServiceSettings = PredictionServiceSettings.newBuilder()
.setEndpoint(endpoint)
.setEndpoint(this.endpoint)
.build();
}
catch (IOException e) {

View File

@@ -18,7 +18,6 @@ package org.springframework.ai.vertexai.embedding.multimodal;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

View File

@@ -948,7 +948,7 @@ public class ZhiPuAiApi {
/**
* Creates an embedding vector representing the input text.
*
*
* @param <T> Type of the input.
* @param input Input text to embed, encoded as a string or array of tokens.
* @param model ID of the model to use.

View File

@@ -235,7 +235,7 @@ public abstract class AbstractChatMemoryAdvisor<T> implements CallAroundAdvisor,
/**
* Set the conversation id.
* @param conversationId the conversation id
* @param conversationId the conversation id
* @return the builder
*/
public AbstractBuilder withConversationId(String conversationId) {

View File

@@ -20,7 +20,7 @@ import reactor.core.publisher.Flux;
/**
* Around advisor that runs around stream based requests.
*
*
* @author Christian Tzolov
* @author Dariusz Jedrzejczyk
* @since 1.0.0

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for chat client advisors.
*/

View File

@@ -199,7 +199,7 @@ public class AdvisorObservationContext extends Observation.Context {
/**
* Builder for {@link AdvisorObservationContext}.
*/
public static class Builder {
public static final class Builder {
private String advisorName;

View File

@@ -23,7 +23,7 @@ import io.micrometer.observation.docs.ObservationDocumentation;
/**
* AI Advisor observation documentation.
*
*
* @author Christian Tzolov
* @since 1.0.0
*/

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for chat client advisors observations.
*/

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides classes for observing chat data.
*/

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Chat client.
*/

View File

@@ -20,7 +20,6 @@ import java.lang.reflect.Type;
import java.util.Objects;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.core.util.DefaultIndenter;
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter;
import com.fasterxml.jackson.databind.DeserializationFeature;

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides the API for embedding observations.
*/

View File

@@ -142,7 +142,7 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
@Override
public <O> FunctionInvokingSpec<Void, O> function(String name, Supplier<O> supplier) {
Function<Void, O> function = (input) -> supplier.get();
Function<Void, O> function = input -> supplier.get();
return new DefaultFunctionInvokingSpec<>(name, function).inputType(Void.class);
}
@@ -159,7 +159,18 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
return new DefaultMethodInvokingSpec(methodName, argumentTypes);
}
class DefaultFunctionInvokingSpec<I, O> implements FunctionInvokingSpec<I, O> {
private String generateDescription(String fromName) {
String generatedDescription = ParsingUtils.reConcatenateCamelCase(fromName, " ");
logger.info("Description is not set! A best effort attempt to generate a description:'{}' from the:'{}'",
generatedDescription, fromName);
logger.info("It is recommended to set the Description explicitly! Use the 'description()' method!");
return generatedDescription;
}
final class DefaultFunctionInvokingSpec<I, O> implements FunctionInvokingSpec<I, O> {
private final String name;
@@ -196,7 +207,6 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
public FunctionInvokingSpec<I, O> inputType(ParameterizedTypeReference<?> inputType) {
Assert.notNull(inputType, "InputType must not be null");
this.inputType = inputType.getType();
;
return this;
}
@@ -229,7 +239,7 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
}
class DefaultMethodInvokingSpec implements FunctionCallback.MethodInvokingSpec {
final class DefaultMethodInvokingSpec implements FunctionCallback.MethodInvokingSpec {
private String name;
@@ -272,9 +282,9 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
public FunctionCallback build() {
Assert.isTrue(this.targetClass != null || this.targetObject != null,
"Target class or object must not be null");
var method = ReflectionUtils.findMethod(targetClass, methodName, argumentTypes);
Assert.notNull(method,
"Method: '" + methodName + "' with arguments:" + Arrays.toString(argumentTypes) + " not found!");
var method = ReflectionUtils.findMethod(this.targetClass, this.methodName, this.argumentTypes);
Assert.notNull(method, "Method: '" + this.methodName + "' with arguments:"
+ Arrays.toString(this.argumentTypes) + " not found!");
return new MethodInvokingFunctionCallback(this.targetObject, method, this.getDescription(), objectMapper,
this.name, responseConverter);
}
@@ -289,15 +299,4 @@ public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder
}
private String generateDescription(String fromName) {
String generatedDescription = ParsingUtils.reConcatenateCamelCase(fromName, " ");
logger.info("Description is not set! A best effort attempt to generate a description:'{}' from the:'{}'",
generatedDescription, fromName);
logger.info("It is recommended to set the Description explicitly! Use the 'description()' method!");
return generatedDescription;
}
}

View File

@@ -85,7 +85,7 @@ public final class FunctionCallbackWrapper<I, O> extends AbstractFunctionCallbac
* @deprecated in favor of {@link DefaultFunctionCallbackBuilder}
*/
@Deprecated
public static class Builder<I, O> {
public static final class Builder<I, O> {
private final BiFunction<I, ToolContext, O> biFunction;

View File

@@ -30,7 +30,7 @@ import org.springframework.util.Assert;
* that can be consumed by the Model. The default implementation converts the output into
* String before sending it to the Model. Provide a custom function responseConverter
* implementation to override this.
*
*
* @param <I> the input type
* @param <O> the output type
* @author Christian Tzolov

View File

@@ -182,7 +182,7 @@ public class MethodInvokingFunctionCallback implements FunctionCallback {
return ModelOptionsUtils.toJsonString(response);
}
return responseConverter.apply(response);
return this.responseConverter.apply(response);
}
catch (Exception e) {
ReflectionUtils.handleReflectionException(e);

View File

@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Provides classes for observing events in the system.
*/

View File

@@ -275,7 +275,7 @@ class DefaultFunctionCallbackBuilderTests {
private T datum;
public T getDatum() {
return datum;
return this.datum;
}
public void setDatum(T value) {

View File

@@ -92,9 +92,7 @@ public class TypeResolverHelperIT {
@Bean
Consumer<WeatherRequest> weatherConsumer() {
return (weatherRequest) -> {
System.out.println(weatherRequest);
};
return System.out::println;
}
}

View File

@@ -353,9 +353,6 @@ class FunctionCallbackWithPlainFunctionBeanIT {
return (weatherService::apply);
}
record LightInfo(String roomName, boolean isOn) {
}
@Bean
@Description("Turn light on or off in a room")
public Function<LightInfo, Void> turnLight() {
@@ -395,18 +392,6 @@ class FunctionCallbackWithPlainFunctionBeanIT {
};
}
record TrainSearchSchedule(String from, String to, String date) {
}
record TrainSearchScheduleResponse(String from, String to, String date, String trainNumber) {
}
record TrainSearchRequest<T>(T data) {
}
record TrainSearchResponse<T>(T data) {
}
@Bean
@Description("Schedule a train reservation")
public Function<TrainSearchRequest<TrainSearchSchedule>, TrainSearchResponse<TrainSearchScheduleResponse>> trainReservation() {
@@ -429,4 +414,19 @@ class FunctionCallbackWithPlainFunctionBeanIT {
}
record LightInfo(String roomName, boolean isOn) {
}
record TrainSearchSchedule(String from, String to, String date) {
}
record TrainSearchScheduleResponse(String from, String to, String date, String trainNumber) {
}
record TrainSearchRequest<T>(T data) {
}
record TrainSearchResponse<T>(T data) {
}
}

View File

@@ -32,6 +32,7 @@
<suppress files="BaseOCIGenAITest.java" checks="HideUtilityClassConstructor"/>
<suppress files="OpenAiChatModelResponseFormatIT.java" checks="RegexpSinglelineJava"/>
<suppress files="MethodInvokingFunctionCallbackTests.java" checks="RegexpSinglelineJava"/>
<suppress files="DefaultFunctionCallbackBuilderTests.java" checks="RegexpSinglelineJava"/>
<suppress files="ClientIT.java" checks="RegexpSinglelineJava"/>