Skip to content

Commit 5caed69

Browse files
committed
Checkstyle changes
1 parent 35f46e9 commit 5caed69

File tree

10 files changed

+75
-69
lines changed

10 files changed

+75
-69
lines changed

models/spring-ai-oci-genai/src/main/java/org/springframework/ai/oci/cohere/OCICohereChatModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void validateChatOptions(OCICohereChatOptions options) {
170170
}
171171

172172
private List<Generation> getGenerations(Prompt prompt, OCICohereChatOptions options) {
173-
com.oracle.bmc.generativeaiinference.responses.ChatResponse cr = genAi
173+
com.oracle.bmc.generativeaiinference.responses.ChatResponse cr = this.genAi
174174
.chat(toCohereChatRequest(prompt, options));
175175
return toGenerations(cr, options);
176176

models/spring-ai-oci-genai/src/test/java/org/springframework/ai/oci/BaseOCIGenAITest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/*
2-
* Copyright 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.oci;
1718

1819
import java.io.IOException;
@@ -22,6 +23,7 @@
2223
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
2324
import com.oracle.bmc.generativeaiinference.GenerativeAiInference;
2425
import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient;
26+
2527
import org.springframework.ai.oci.cohere.OCICohereChatOptions;
2628

2729
public class BaseOCIGenAITest {

models/spring-ai-oci-genai/src/test/java/org/springframework/ai/oci/cohere/OCICohereChatModelIT.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
2-
* Copyright 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.oci.cohere;
1718

1819
import org.junit.jupiter.api.Test;
1920
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
21+
2022
import org.springframework.ai.chat.messages.SystemMessage;
2123
import org.springframework.ai.chat.messages.UserMessage;
2224
import org.springframework.ai.chat.model.ChatModel;
@@ -25,11 +27,10 @@
2527
import org.springframework.ai.oci.BaseOCIGenAITest;
2628

2729
import static org.assertj.core.api.Assertions.assertThat;
28-
import static org.springframework.ai.oci.BaseOCIGenAITest.OCI_CHAT_MODEL_ID_KEY;
29-
import static org.springframework.ai.oci.BaseOCIGenAITest.OCI_COMPARTMENT_ID_KEY;
3030

31-
@EnabledIfEnvironmentVariable(named = OCI_COMPARTMENT_ID_KEY, matches = ".+")
32-
@EnabledIfEnvironmentVariable(named = OCI_CHAT_MODEL_ID_KEY, matches = ".+")
31+
@EnabledIfEnvironmentVariable(named = org.springframework.ai.oci.BaseOCIGenAITest.OCI_COMPARTMENT_ID_KEY,
32+
matches = ".+")
33+
@EnabledIfEnvironmentVariable(named = org.springframework.ai.oci.BaseOCIGenAITest.OCI_CHAT_MODEL_ID_KEY, matches = ".+")
3334
public class OCICohereChatModelIT extends BaseOCIGenAITest {
3435

3536
private static final ChatModel chatModel = new OCICohereChatModel(getGenerativeAIClient(), options().build());

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/oci/genai/OCICohereChatModelProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class OCICohereChatModelProperties {
4141
.build();
4242

4343
public boolean isEnabled() {
44-
return enabled;
44+
return this.enabled;
4545
}
4646

4747
public void setEnabled(boolean enabled) {

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/oci/genai/OCIGenAiAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
@AutoConfiguration
4949
@ConditionalOnClass({ GenerativeAiInferenceClient.class, OCIEmbeddingModel.class })
5050
@EnableConfigurationProperties({ OCIConnectionProperties.class, OCIEmbeddingModelProperties.class,
51-
OCICohereChatModelProperties.class, })
51+
OCICohereChatModelProperties.class })
5252
public class OCIGenAiAutoConfiguration {
5353

5454
private static BasicAuthenticationDetailsProvider authenticationProvider(OCIConnectionProperties properties)

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/oci/genai/OCIGenAIAutoConfigurationTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
/*
2-
* Copyright 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.autoconfigure.oci.genai;
1718

1819
import java.nio.file.Files;
@@ -23,6 +24,7 @@
2324
import com.oracle.bmc.http.client.pki.Pem;
2425
import org.junit.jupiter.api.Test;
2526
import org.junit.jupiter.api.io.TempDir;
27+
2628
import org.springframework.ai.oci.cohere.OCICohereChatModel;
2729
import org.springframework.ai.oci.cohere.OCICohereChatOptions;
2830
import org.springframework.boot.autoconfigure.AutoConfigurations;

spring-ai-spring-boot-autoconfigure/src/test/java/org/springframework/ai/autoconfigure/oci/genai/OCIGenAiAutoConfigurationIT.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ public class OCIGenAiAutoConfigurationIT {
5757
private final ApplicationContextRunner cohereChatContextRunner = new ApplicationContextRunner().withPropertyValues(
5858
// @formatter:off
5959
"spring.ai.oci.genai.authenticationType=file",
60-
"spring.ai.oci.genai.file=" + CONFIG_FILE,
61-
"spring.ai.oci.genai.cohere.chat.options.compartment=" + COMPARTMENT_ID,
60+
"spring.ai.oci.genai.file=" + this.CONFIG_FILE,
61+
"spring.ai.oci.genai.cohere.chat.options.compartment=" + this.COMPARTMENT_ID,
6262
"spring.ai.oci.genai.cohere.chat.options.servingMode=on-demand",
63-
"spring.ai.oci.genai.cohere.chat.options.model=" + CHAT_MODEL_ID
63+
"spring.ai.oci.genai.cohere.chat.options.model=" + this.CHAT_MODEL_ID
6464
// @formatter:on
6565
).withConfiguration(AutoConfigurations.of(OCIGenAiAutoConfiguration.class));
6666

src/checkstyle/checkstyle-suppressions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@
2929
<suppress files="FiltersParser\.java" checks="MultipleVariableDeclarations"/>
3030
<suppress files="FiltersLexer\.java" checks="MultipleVariableDeclarations"/>
3131
<suppress files="BaseOllamaIT.java" checks="HideUtilityClassConstructor"/>
32+
<suppress files="BaseOCIGenAITest.java" checks="HideUtilityClassConstructor"/>
3233

3334
</suppressions>

vector-stores/spring-ai-coherence-store/src/main/java/org/springframework/ai/vectorstore/CoherenceVectorStore.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ public void afterPropertiesSet() throws Exception {
231231
this.documentChunks = this.session.getMap(this.mapName);
232232
switch (this.indexType) {
233233
case HNSW -> this.documentChunks
234-
.addIndex(new HnswIndex<>(DocumentChunk::vector, this.distanceType.name(), dimensions));
234+
.addIndex(new HnswIndex<>(DocumentChunk::vector, this.distanceType.name(), this.dimensions));
235235
case BINARY -> this.documentChunks.addIndex(new BinaryQuantIndex<>(DocumentChunk::vector));
236236
}
237237
}
@@ -255,7 +255,7 @@ private Float32Vector toFloat32Vector(final float[] floats) {
255255
}
256256

257257
String getMapName() {
258-
return mapName;
258+
return this.mapName;
259259
}
260260

261261
}

vector-stores/spring-ai-coherence-store/src/test/java/org/springframework/ai/vectorstore/CoherenceVectorStoreIT.java

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -92,48 +92,6 @@ public static String getText(final String uri) {
9292
.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=COSINE",
9393
"test.spring.ai.vectorstore.coherence.indexType=NONE");
9494

95-
@SpringBootConfiguration
96-
@EnableAutoConfiguration
97-
public static class TestClient {
98-
99-
@Value("${test.spring.ai.vectorstore.coherence.distanceType}")
100-
CoherenceVectorStore.DistanceType distanceType;
101-
102-
@Value("${test.spring.ai.vectorstore.coherence.indexType}")
103-
CoherenceVectorStore.IndexType indexType;
104-
105-
@Bean
106-
public VectorStore vectorStore(EmbeddingModel embeddingModel, Session session) {
107-
return new CoherenceVectorStore(embeddingModel, session).setDistanceType(distanceType)
108-
.setIndexType(indexType)
109-
.setForcedNormalization(distanceType == CoherenceVectorStore.DistanceType.COSINE
110-
|| distanceType == CoherenceVectorStore.DistanceType.IP);
111-
}
112-
113-
@Bean
114-
public Session session(Coherence coherence) {
115-
return coherence.getSession();
116-
}
117-
118-
@Bean
119-
public Coherence coherence() {
120-
return Coherence.clusterMember().start().join();
121-
}
122-
123-
@Bean
124-
public EmbeddingModel embeddingModel() {
125-
try {
126-
TransformersEmbeddingModel tem = new TransformersEmbeddingModel();
127-
tem.afterPropertiesSet();
128-
return tem;
129-
}
130-
catch (Exception e) {
131-
throw new RuntimeException("Failed initializing embedding model", e);
132-
}
133-
}
134-
135-
}
136-
13795
private static void truncateMap(ApplicationContext context, String mapName) {
13896
Session session = context.getBean(Session.class);
13997
session.getMap(mapName).truncate();
@@ -153,24 +111,24 @@ public static Stream<Arguments> distanceAndIndex() {
153111
@ParameterizedTest(name = "Distance {0}, Index {1} : {displayName}")
154112
@MethodSource("distanceAndIndex")
155113
public void addAndSearch(CoherenceVectorStore.DistanceType distanceType, CoherenceVectorStore.IndexType indexType) {
156-
contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
114+
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
157115
.withPropertyValues("test.spring.ai.vectorstore.coherence.indexType=" + indexType)
158116
.run(context -> {
159117

160118
VectorStore vectorStore = context.getBean(VectorStore.class);
161119

162-
vectorStore.add(documents);
120+
vectorStore.add(this.documents);
163121

164122
List<Document> results = vectorStore
165123
.similaritySearch(SearchRequest.query("What is Great Depression").withTopK(1));
166124

167125
assertThat(results).hasSize(1);
168126
Document resultDoc = results.get(0);
169-
assertThat(resultDoc.getId()).isEqualTo(documents.get(2).getId());
127+
assertThat(resultDoc.getId()).isEqualTo(this.documents.get(2).getId());
170128
assertThat(resultDoc.getMetadata()).containsKeys("meta2", "distance");
171129

172130
// Remove all documents from the store
173-
vectorStore.delete(documents.stream().map(doc -> doc.getId()).toList());
131+
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
174132

175133
List<Document> results2 = vectorStore
176134
.similaritySearch(SearchRequest.query("Great Depression").withTopK(1));
@@ -184,7 +142,7 @@ public void addAndSearch(CoherenceVectorStore.DistanceType distanceType, Coheren
184142
@MethodSource("distanceAndIndex")
185143
public void searchWithFilters(CoherenceVectorStore.DistanceType distanceType,
186144
CoherenceVectorStore.IndexType indexType) {
187-
contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
145+
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
188146
.withPropertyValues("test.spring.ai.vectorstore.coherence.indexType=" + indexType)
189147
.run(context -> {
190148

@@ -250,7 +208,7 @@ public void searchWithFilters(CoherenceVectorStore.DistanceType distanceType,
250208

251209
@Test
252210
public void documentUpdate() {
253-
contextRunner.run(context -> {
211+
this.contextRunner.run(context -> {
254212
VectorStore vectorStore = context.getBean(VectorStore.class);
255213

256214
Document document = new Document(UUID.randomUUID().toString(), "Spring AI rocks!!",
@@ -286,11 +244,11 @@ public void documentUpdate() {
286244

287245
@Test
288246
public void searchWithThreshold() {
289-
contextRunner.run(context -> {
247+
this.contextRunner.run(context -> {
290248

291249
VectorStore vectorStore = context.getBean(VectorStore.class);
292250

293-
vectorStore.add(documents);
251+
vectorStore.add(this.documents);
294252

295253
List<Document> fullResult = vectorStore
296254
.similaritySearch(SearchRequest.query("Time Shelter").withTopK(5).withSimilarityThresholdAll());
@@ -310,7 +268,7 @@ public void searchWithThreshold() {
310268

311269
assertThat(results).hasSize(1);
312270
Document resultDoc = results.get(0);
313-
assertThat(resultDoc.getId()).isEqualTo(documents.get(1).getId());
271+
assertThat(resultDoc.getId()).isEqualTo(this.documents.get(1).getId());
314272

315273
truncateMap(context, ((CoherenceVectorStore) vectorStore).getMapName());
316274
});
@@ -338,4 +296,46 @@ private static boolean isSortedByDistance(final List<Document> documents) {
338296
return true;
339297
}
340298

299+
@SpringBootConfiguration
300+
@EnableAutoConfiguration
301+
public static class TestClient {
302+
303+
@Value("${test.spring.ai.vectorstore.coherence.distanceType}")
304+
CoherenceVectorStore.DistanceType distanceType;
305+
306+
@Value("${test.spring.ai.vectorstore.coherence.indexType}")
307+
CoherenceVectorStore.IndexType indexType;
308+
309+
@Bean
310+
public VectorStore vectorStore(EmbeddingModel embeddingModel, Session session) {
311+
return new CoherenceVectorStore(embeddingModel, session).setDistanceType(this.distanceType)
312+
.setIndexType(this.indexType)
313+
.setForcedNormalization(this.distanceType == CoherenceVectorStore.DistanceType.COSINE
314+
|| this.distanceType == CoherenceVectorStore.DistanceType.IP);
315+
}
316+
317+
@Bean
318+
public Session session(Coherence coherence) {
319+
return coherence.getSession();
320+
}
321+
322+
@Bean
323+
public Coherence coherence() {
324+
return Coherence.clusterMember().start().join();
325+
}
326+
327+
@Bean
328+
public EmbeddingModel embeddingModel() {
329+
try {
330+
TransformersEmbeddingModel tem = new TransformersEmbeddingModel();
331+
tem.afterPropertiesSet();
332+
return tem;
333+
}
334+
catch (Exception e) {
335+
throw new RuntimeException("Failed initializing embedding model", e);
336+
}
337+
}
338+
339+
}
340+
341341
}

0 commit comments

Comments
 (0)