Skip to content

Commit c3dba30

Browse files
committed
Enabling checkstyle on spring-ai-openai
1 parent 9c7af56 commit c3dba30

File tree

44 files changed

+292
-259
lines changed

Some content is hidden

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

44 files changed

+292
-259
lines changed

models/spring-ai-openai/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
<developerConnection>[email protected]:spring-projects/spring-ai.git</developerConnection>
3737
</scm>
3838

39+
<properties>
40+
<disable.checks>false</disable.checks>
41+
</properties>
42+
3943
<dependencies>
4044

4145
<!-- production dependencies -->

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiAudioSpeechModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public SpeechResponse call(SpeechPrompt speechPrompt) {
132132
var speech = speechEntity.getBody();
133133

134134
if (speech == null) {
135-
this.logger.warn("No speech response returned for speechRequest: {}", speechRequest);
135+
logger.warn("No speech response returned for speechRequest: {}", speechRequest);
136136
return new SpeechResponse(new Speech(new byte[0]));
137137
}
138138

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiAudioTranscriptionModel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public AudioTranscriptionResponse call(AudioTranscriptionPrompt transcriptionPro
118118
var transcription = transcriptionEntity.getBody();
119119

120120
if (transcription == null) {
121-
this.logger.warn("No transcription returned for request: {}", audioResource);
121+
logger.warn("No transcription returned for request: {}", audioResource);
122122
return new AudioTranscriptionResponse(null);
123123
}
124124

@@ -139,7 +139,7 @@ public AudioTranscriptionResponse call(AudioTranscriptionPrompt transcriptionPro
139139
var transcription = transcriptionEntity.getBody();
140140

141141
if (transcription == null) {
142-
this.logger.warn("No transcription returned for request: {}", audioResource);
142+
logger.warn("No transcription returned for request: {}", audioResource);
143143
return new AudioTranscriptionResponse(null);
144144
}
145145

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiAudioTranscriptionOptions.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,37 +122,48 @@ public int hashCode() {
122122

123123
@Override
124124
public boolean equals(Object obj) {
125-
if (this == obj)
125+
if (this == obj) {
126126
return true;
127-
if (obj == null)
127+
}
128+
if (obj == null) {
128129
return false;
129-
if (getClass() != obj.getClass())
130+
}
131+
if (getClass() != obj.getClass()) {
130132
return false;
133+
}
131134
OpenAiAudioTranscriptionOptions other = (OpenAiAudioTranscriptionOptions) obj;
132135
if (this.model == null) {
133-
if (other.model != null)
136+
if (other.model != null) {
134137
return false;
138+
}
135139
}
136-
else if (!this.model.equals(other.model))
140+
else if (!this.model.equals(other.model)) {
137141
return false;
142+
}
138143
if (this.prompt == null) {
139-
if (other.prompt != null)
144+
if (other.prompt != null) {
140145
return false;
146+
}
141147
}
142-
else if (!this.prompt.equals(other.prompt))
148+
else if (!this.prompt.equals(other.prompt)) {
143149
return false;
150+
}
144151
if (this.language == null) {
145-
if (other.language != null)
152+
if (other.language != null) {
146153
return false;
154+
}
147155
}
148-
else if (!this.language.equals(other.language))
156+
else if (!this.language.equals(other.language)) {
149157
return false;
158+
}
150159
if (this.responseFormat == null) {
151-
if (other.responseFormat != null)
160+
if (other.responseFormat != null) {
152161
return false;
162+
}
153163
}
154-
else if (!this.responseFormat.equals(other.responseFormat))
164+
else if (!this.responseFormat.equals(other.responseFormat)) {
155165
return false;
166+
}
156167
return true;
157168
}
158169

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiChatModel.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {
307307
@SuppressWarnings("null")
308308
String id = chatCompletion2.id();
309309

310-
List<Generation> generations = chatCompletion2.choices().stream().map(choice -> {// @formatter:off
311-
310+
List<Generation> generations = chatCompletion2.choices().stream().map(choice -> { // @formatter:off
312311
if (choice.message().role() != null) {
313312
roleMap.putIfAbsent(id, choice.message().role().name());
314313
}
@@ -347,9 +346,7 @@ public Flux<ChatResponse> stream(Prompt prompt) {
347346
}
348347
})
349348
.doOnError(observation::error)
350-
.doFinally(s -> {
351-
observation.stop();
352-
})
349+
.doFinally(s -> observation.stop())
353350
.contextWrite(ctx -> ctx.put(ObservationThreadLocalAccessor.KEY, observation));
354351
// @formatter:on
355352

@@ -454,10 +451,8 @@ else if (message.getMessageType() == MessageType.ASSISTANT) {
454451
else if (message.getMessageType() == MessageType.TOOL) {
455452
ToolResponseMessage toolMessage = (ToolResponseMessage) message;
456453

457-
toolMessage.getResponses().forEach(response -> {
458-
Assert.isTrue(response.id() != null, "ToolResponseMessage must have an id");
459-
});
460-
454+
toolMessage.getResponses()
455+
.forEach(response -> Assert.isTrue(response.id() != null, "ToolResponseMessage must have an id"));
461456
return toolMessage.getResponses()
462457
.stream()
463458
.map(tr -> new ChatCompletionMessage(tr.responseData(), ChatCompletionMessage.Role.TOOL, tr.name(),

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageModel.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ private ImageResponse convertResponse(ResponseEntity<OpenAiImageApi.OpenAiImageR
169169
return new ImageResponse(List.of());
170170
}
171171

172-
List<ImageGeneration> imageGenerationList = imageApiResponse.data().stream().map(entry -> {
173-
return new ImageGeneration(new Image(entry.url(), entry.b64Json()),
174-
new OpenAiImageGenerationMetadata(entry.revisedPrompt()));
175-
}).toList();
172+
List<ImageGeneration> imageGenerationList = imageApiResponse.data()
173+
.stream()
174+
.map(entry -> new ImageGeneration(new Image(entry.url(), entry.b64Json()),
175+
new OpenAiImageGenerationMetadata(entry.revisedPrompt())))
176+
.toList();
176177

177178
ImageResponseMetadata openAiImageResponseMetadata = new ImageResponseMetadata(imageApiResponse.created());
178179
return new ImageResponse(imageGenerationList, openAiImageResponseMetadata);

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public String toString() {
234234
+ ", user='" + this.user + '\'' + '}';
235235
}
236236

237-
public static class Builder {
237+
public static final class Builder {
238238

239239
private final OpenAiImageOptions options;
240240

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiModerationModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private ModerationResponse convertResponse(
106106
OpenAiModerationApi.OpenAiModerationRequest openAiModerationRequest) {
107107
OpenAiModerationApi.OpenAiModerationResponse moderationApiResponse = moderationResponseEntity.getBody();
108108
if (moderationApiResponse == null) {
109-
this.logger.warn("No moderation response returned for request: {}", openAiModerationRequest);
109+
logger.warn("No moderation response returned for request: {}", openAiModerationRequest);
110110
return new ModerationResponse(new Generation());
111111
}
112112

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiModerationOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void setModel(String model) {
5050
this.model = model;
5151
}
5252

53-
public static class Builder {
53+
public static final class Builder {
5454

5555
private final OpenAiModerationOptions options;
5656

models/spring-ai-openai/src/main/java/org/springframework/ai/openai/aot/OpenAiRuntimeHints.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@ private static Set<TypeReference> eval(Set<TypeReference> referenceSet) {
4848
@Override
4949
public void registerHints(@NonNull RuntimeHints hints, @Nullable ClassLoader classLoader) {
5050
var mcs = MemberCategory.values();
51-
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiApi.class)))
51+
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiApi.class))) {
5252
hints.reflection().registerType(tr, mcs);
53-
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiAudioApi.class)))
53+
}
54+
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiAudioApi.class))) {
5455
hints.reflection().registerType(tr, mcs);
55-
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiImageApi.class)))
56+
}
57+
for (var tr : eval(findJsonAnnotatedClassesInPackage(OpenAiImageApi.class))) {
5658
hints.reflection().registerType(tr, mcs);
59+
}
5760
}
5861

5962
}

0 commit comments

Comments
 (0)