Skip to content

Commit 27fe936

Browse files
committed
chore: temporarily disable Checkstyle enforcement
- Disable project-wide Checkstyle checks to unblock development - Add documentation for enabling Checkstyle locally - Fix remaining checkstyle violations in current codebase Fixes #1669
1 parent d44a6af commit 27fe936

File tree

60 files changed

+400
-400
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+400
-400
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ To check javadocs using the [javadoc:javadoc](https://maven.apache.org/plugins/m
9494
./mvnw javadoc:javadoc -Pjavadoc
9595
```
9696

97+
To build with checkstyles enabled.
98+
Checkstyles are currently disabled, but you can enable them by doing the following:
99+
```shell
100+
./mvnw clean package -DskipTests -Ddisable.checks=false
101+
```
102+
97103
## Project Links
98104

99105
* [Documentation](https://docs.spring.io/spring-ai/reference/)

document-readers/markdown-reader/src/main/java/org/springframework/ai/reader/markdown/MarkdownDocumentReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ static class DocumentVisitor extends AbstractVisitor {
111111

112112
private Document.Builder currentDocumentBuilder;
113113

114-
public DocumentVisitor(MarkdownDocumentReaderConfig config) {
114+
DocumentVisitor(MarkdownDocumentReaderConfig config) {
115115
this.config = config;
116116
}
117117

document-readers/markdown-reader/src/main/java/org/springframework/ai/reader/markdown/config/MarkdownDocumentReaderConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static Builder builder() {
5656
return new Builder();
5757
}
5858

59-
public static class Builder {
59+
public static final class Builder {
6060

6161
private boolean horizontalRuleCreateDocument = false;
6262

document-readers/pdf-reader/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
</scm>
3838

3939
<properties>
40-
<disable.checks>false</disable.checks>
4140
</properties>
4241

4342
<dependencies>

models/spring-ai-anthropic/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
</scm>
3939

4040
<properties>
41-
<disable.checks>false</disable.checks>
4241
</properties>
4342

4443
<dependencies>

models/spring-ai-azure-openai/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
</scm>
3737

3838
<properties>
39-
<disable.checks>false</disable.checks>
4039
</properties>
4140

4241
<dependencies>

models/spring-ai-bedrock-converse/pom.xml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2023-2024 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
218
<project xmlns="http://maven.apache.org/POM/4.0.0"
319
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
420
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
@@ -81,4 +97,4 @@
8197

8298
</dependencies>
8399

84-
</project>
100+
</project>

models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/BedrockProxyChatModel.java

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/*
2-
* Copyright 2024 - 2024 the original author or authors.
2+
* Copyright 2023-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.ai.bedrock.converse;
1718

1819
import java.io.IOException;
@@ -26,44 +27,11 @@
2627
import java.util.Map;
2728
import java.util.Set;
2829

29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
31-
import org.springframework.ai.bedrock.converse.api.ConverseApiUtils;
32-
import org.springframework.ai.bedrock.converse.api.URLValidator;
33-
import org.springframework.ai.chat.messages.AssistantMessage;
34-
import org.springframework.ai.chat.messages.MessageType;
35-
import org.springframework.ai.chat.messages.ToolResponseMessage;
36-
import org.springframework.ai.chat.messages.UserMessage;
37-
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
38-
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
39-
import org.springframework.ai.chat.metadata.DefaultUsage;
40-
import org.springframework.ai.chat.model.AbstractToolCallSupport;
41-
import org.springframework.ai.chat.model.ChatModel;
42-
import org.springframework.ai.chat.model.ChatResponse;
43-
import org.springframework.ai.chat.model.Generation;
44-
import org.springframework.ai.chat.model.MessageAggregator;
45-
import org.springframework.ai.chat.observation.ChatModelObservationContext;
46-
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
47-
import org.springframework.ai.chat.observation.ChatModelObservationDocumentation;
48-
import org.springframework.ai.chat.observation.DefaultChatModelObservationConvention;
49-
import org.springframework.ai.chat.prompt.ChatOptions;
50-
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
51-
import org.springframework.ai.chat.prompt.Prompt;
52-
import org.springframework.ai.model.ModelOptionsUtils;
53-
import org.springframework.ai.model.function.FunctionCallback;
54-
import org.springframework.ai.model.function.FunctionCallbackContext;
55-
import org.springframework.ai.model.function.FunctionCallingOptions;
56-
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder;
57-
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
58-
import org.springframework.ai.observation.conventions.AiProvider;
59-
import org.springframework.util.Assert;
60-
import org.springframework.util.CollectionUtils;
61-
import org.springframework.util.StreamUtils;
62-
import org.springframework.util.StringUtils;
63-
6430
import io.micrometer.observation.Observation;
6531
import io.micrometer.observation.ObservationRegistry;
6632
import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor;
33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
6735
import reactor.core.publisher.Flux;
6836
import reactor.core.publisher.Mono;
6937
import reactor.core.publisher.Sinks;
@@ -97,6 +65,39 @@
9765
import software.amazon.awssdk.services.bedrockruntime.model.ToolSpecification;
9866
import software.amazon.awssdk.services.bedrockruntime.model.ToolUseBlock;
9967

68+
import org.springframework.ai.bedrock.converse.api.ConverseApiUtils;
69+
import org.springframework.ai.bedrock.converse.api.URLValidator;
70+
import org.springframework.ai.chat.messages.AssistantMessage;
71+
import org.springframework.ai.chat.messages.MessageType;
72+
import org.springframework.ai.chat.messages.ToolResponseMessage;
73+
import org.springframework.ai.chat.messages.UserMessage;
74+
import org.springframework.ai.chat.metadata.ChatGenerationMetadata;
75+
import org.springframework.ai.chat.metadata.ChatResponseMetadata;
76+
import org.springframework.ai.chat.metadata.DefaultUsage;
77+
import org.springframework.ai.chat.model.AbstractToolCallSupport;
78+
import org.springframework.ai.chat.model.ChatModel;
79+
import org.springframework.ai.chat.model.ChatResponse;
80+
import org.springframework.ai.chat.model.Generation;
81+
import org.springframework.ai.chat.model.MessageAggregator;
82+
import org.springframework.ai.chat.observation.ChatModelObservationContext;
83+
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
84+
import org.springframework.ai.chat.observation.ChatModelObservationDocumentation;
85+
import org.springframework.ai.chat.observation.DefaultChatModelObservationConvention;
86+
import org.springframework.ai.chat.prompt.ChatOptions;
87+
import org.springframework.ai.chat.prompt.ChatOptionsBuilder;
88+
import org.springframework.ai.chat.prompt.Prompt;
89+
import org.springframework.ai.model.ModelOptionsUtils;
90+
import org.springframework.ai.model.function.FunctionCallback;
91+
import org.springframework.ai.model.function.FunctionCallbackContext;
92+
import org.springframework.ai.model.function.FunctionCallingOptions;
93+
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder;
94+
import org.springframework.ai.model.function.FunctionCallingOptionsBuilder.PortableFunctionCallingOptions;
95+
import org.springframework.ai.observation.conventions.AiProvider;
96+
import org.springframework.util.Assert;
97+
import org.springframework.util.CollectionUtils;
98+
import org.springframework.util.StreamUtils;
99+
import org.springframework.util.StringUtils;
100+
100101
/**
101102
* A {@link ChatModel} implementation that uses the Amazon Bedrock Converse API to
102103
* interact with the <a href=
@@ -335,7 +336,7 @@ else if (prompt.getOptions() instanceof ChatOptions) {
335336
.topP(updatedRuntimeOptions.getTopP() != null ? updatedRuntimeOptions.getTopP().floatValue() : null)
336337
.build();
337338
Document additionalModelRequestFields = ConverseApiUtils
338-
.getChatOptionsAdditionalModelRequestFields(defaultOptions, prompt.getOptions());
339+
.getChatOptionsAdditionalModelRequestFields(this.defaultOptions, prompt.getOptions());
339340

340341
return ConverseRequest.builder()
341342
.modelId(updatedRuntimeOptions.getModel())
@@ -411,10 +412,8 @@ private ChatResponse toChatResponse(ConverseResponse response) {
411412
List<Generation> generations = message.content()
412413
.stream()
413414
.filter(content -> content.type() != ContentBlock.Type.TOOL_USE)
414-
.map(content -> {
415-
return new Generation(new AssistantMessage(content.text(), Map.of()),
416-
ChatGenerationMetadata.from(response.stopReasonAsString(), null));
417-
})
415+
.map(content -> new Generation(new AssistantMessage(content.text(), Map.of()),
416+
ChatGenerationMetadata.from(response.stopReasonAsString(), null)))
418417
.toList();
419418

420419
List<Generation> allGenerations = new ArrayList<>(generations);
@@ -508,7 +507,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {
508507
// @formatter:off
509508
Flux<ChatResponse> chatResponses = ConverseApiUtils.toChatResponse(response);
510509

511-
Flux<ChatResponse> chatResponseFlux = chatResponses.switchMap(chatResponse -> {
510+
Flux<ChatResponse> chatResponseFlux = chatResponses.switchMap(chatResponse -> {
512511
if (!this.isProxyToolCalls(prompt, this.defaultOptions) && chatResponse != null
513512
&& this.isToolCall(chatResponse, Set.of("tool_use"))) {
514513
var toolCallConversation = this.handleToolCalls(prompt, chatResponse);
@@ -540,14 +539,14 @@ public Flux<ConverseStreamOutput> converseStream(ConverseStreamRequest converseS
540539
Sinks.Many<ConverseStreamOutput> eventSink = Sinks.many().multicast().onBackpressureBuffer();
541540

542541
ConverseStreamResponseHandler.Visitor visitor = ConverseStreamResponseHandler.Visitor.builder()
543-
.onDefault((output) -> {
542+
.onDefault(output -> {
544543
logger.debug("Received converse stream output:{}", output);
545544
eventSink.tryEmitNext(output);
546545
})
547546
.build();
548547

549548
ConverseStreamResponseHandler responseHandler = ConverseStreamResponseHandler.builder()
550-
.onEventStream(stream -> stream.subscribe((e) -> e.accept(visitor)))
549+
.onEventStream(stream -> stream.subscribe(e -> e.accept(visitor)))
551550
.onComplete(() -> {
552551
EmitResult emitResult = eventSink.tryEmitComplete();
553552

@@ -559,7 +558,7 @@ public Flux<ConverseStreamOutput> converseStream(ConverseStreamRequest converseS
559558
eventSink.emitComplete(EmitFailureHandler.busyLooping(Duration.ofSeconds(3)));
560559
logger.info("Completed streaming response.");
561560
})
562-
.onError((error) -> {
561+
.onError(error -> {
563562
logger.error("Error handling Bedrock converse stream response", error);
564563
eventSink.tryEmitError(error);
565564
})
@@ -571,11 +570,20 @@ public Flux<ConverseStreamOutput> converseStream(ConverseStreamRequest converseS
571570

572571
}
573572

573+
/**
574+
* Use the provided convention for reporting observation data
575+
* @param observationConvention The provided convention
576+
*/
577+
public void setObservationConvention(ChatModelObservationConvention observationConvention) {
578+
Assert.notNull(observationConvention, "observationConvention cannot be null");
579+
this.observationConvention = observationConvention;
580+
}
581+
574582
public static Builder builder() {
575583
return new Builder();
576584
}
577585

578-
public static class Builder {
586+
public static final class Builder {
579587

580588
private AwsCredentialsProvider credentialsProvider;
581589

@@ -696,13 +704,4 @@ public BedrockProxyChatModel build() {
696704

697705
}
698706

699-
/**
700-
* Use the provided convention for reporting observation data
701-
* @param observationConvention The provided convention
702-
*/
703-
public void setObservationConvention(ChatModelObservationConvention observationConvention) {
704-
Assert.notNull(observationConvention, "observationConvention cannot be null");
705-
this.observationConvention = observationConvention;
706-
}
707-
708707
}

models/spring-ai-bedrock-converse/src/main/java/org/springframework/ai/bedrock/converse/api/BedrockUsage.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
/*
2-
* Copyright 2024 - 2024 the original author or authors.
2+
* Copyright 2023-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* https://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.ai.bedrock.converse.api;
1718

19+
import software.amazon.awssdk.services.bedrockruntime.model.TokenUsage;
20+
1821
import org.springframework.ai.chat.metadata.Usage;
1922
import org.springframework.util.Assert;
2023

21-
import software.amazon.awssdk.services.bedrockruntime.model.TokenUsage;
22-
2324
/**
2425
* {@link Usage} implementation for Bedrock Converse API.
2526
*
@@ -46,17 +47,17 @@ protected BedrockUsage(Long inputTokens, Long outputTokens) {
4647

4748
@Override
4849
public Long getPromptTokens() {
49-
return inputTokens;
50+
return this.inputTokens;
5051
}
5152

5253
@Override
5354
public Long getGenerationTokens() {
54-
return outputTokens;
55+
return this.outputTokens;
5556
}
5657

5758
@Override
5859
public String toString() {
59-
return "BedrockUsage [inputTokens=" + inputTokens + ", outputTokens=" + outputTokens + "]";
60+
return "BedrockUsage [inputTokens=" + this.inputTokens + ", outputTokens=" + this.outputTokens + "]";
6061
}
6162

62-
}
63+
}

0 commit comments

Comments
 (0)