Checkstyle changes

This commit is contained in:
Soby Chacko
2024-11-07 18:07:58 -05:00
committed by Ilayaperumal Gopinathan
parent c1fc687730
commit 865d429451
12 changed files with 81 additions and 73 deletions

View File

@@ -291,7 +291,7 @@ public abstract class AbstractBedrockApi<I, O, SO> {
})
.onDefault(event -> {
logger.error("Unknown or unhandled event: " + event.toString());
eventSink.emitError(new Throwable("Unknown or unhandled event: " + event.toString()),DEFAULT_EMIT_FAILURE_HANDLER);
eventSink.emitError(new Throwable("Unknown or unhandled event: " + event.toString()), DEFAULT_EMIT_FAILURE_HANDLER);
})
.build();

View File

@@ -170,7 +170,7 @@ public class OCICohereChatModel implements ChatModel {
}
private List<Generation> getGenerations(Prompt prompt, OCICohereChatOptions options) {
com.oracle.bmc.generativeaiinference.responses.ChatResponse cr = genAi
com.oracle.bmc.generativeaiinference.responses.ChatResponse cr = this.genAi
.chat(toCohereChatRequest(prompt, options));
return toGenerations(cr, options);

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2024 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.oci;
import java.io.IOException;
@@ -22,6 +23,7 @@ import com.oracle.bmc.Region;
import com.oracle.bmc.auth.ConfigFileAuthenticationDetailsProvider;
import com.oracle.bmc.generativeaiinference.GenerativeAiInference;
import com.oracle.bmc.generativeaiinference.GenerativeAiInferenceClient;
import org.springframework.ai.oci.cohere.OCICohereChatOptions;
public class BaseOCIGenAITest {

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2024 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,10 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.oci.cohere;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatModel;
@@ -25,11 +27,10 @@ import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.oci.BaseOCIGenAITest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.ai.oci.BaseOCIGenAITest.OCI_CHAT_MODEL_ID_KEY;
import static org.springframework.ai.oci.BaseOCIGenAITest.OCI_COMPARTMENT_ID_KEY;
@EnabledIfEnvironmentVariable(named = OCI_COMPARTMENT_ID_KEY, matches = ".+")
@EnabledIfEnvironmentVariable(named = OCI_CHAT_MODEL_ID_KEY, matches = ".+")
@EnabledIfEnvironmentVariable(named = org.springframework.ai.oci.BaseOCIGenAITest.OCI_COMPARTMENT_ID_KEY,
matches = ".+")
@EnabledIfEnvironmentVariable(named = org.springframework.ai.oci.BaseOCIGenAITest.OCI_CHAT_MODEL_ID_KEY, matches = ".+")
public class OCICohereChatModelIT extends BaseOCIGenAITest {
private static final ChatModel chatModel = new OCICohereChatModel(getGenerativeAIClient(), options().build());

View File

@@ -23,7 +23,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.slf4j.Logger;
@@ -42,7 +41,6 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
/**
@@ -161,7 +159,8 @@ public class OpenAiChatModelResponseFormatIT {
}
var outputConverter = new BeanOutputConverter<>(MathReasoning.class);
// @formatter:off
// CHECKSTYLE:OFF
var expectedJsonSchema = """
{
"$schema" : "https://json-schema.org/draft/2020-12/schema",
@@ -197,6 +196,8 @@ public class OpenAiChatModelResponseFormatIT {
"required" : [ "steps", "final_answer" ],
"additionalProperties" : false
}""";
// @formatter:on
// CHECKSTYLE:ON
var jsonSchema1 = outputConverter.getJsonSchema();
assertThat(jsonSchema1).isNotNull();

View File

@@ -41,7 +41,7 @@ public class OCICohereChatModelProperties {
.build();
public boolean isEnabled() {
return enabled;
return this.enabled;
}
public void setEnabled(boolean enabled) {

View File

@@ -48,7 +48,7 @@ import org.springframework.util.StringUtils;
@AutoConfiguration
@ConditionalOnClass({ GenerativeAiInferenceClient.class, OCIEmbeddingModel.class })
@EnableConfigurationProperties({ OCIConnectionProperties.class, OCIEmbeddingModelProperties.class,
OCICohereChatModelProperties.class, })
OCICohereChatModelProperties.class })
public class OCIGenAiAutoConfiguration {
private static BasicAuthenticationDetailsProvider authenticationProvider(OCIConnectionProperties properties)

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2024 the original author or authors.
* Copyright 2023-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ai.autoconfigure.oci.genai;
import java.nio.file.Files;
@@ -23,6 +24,7 @@ import java.security.KeyPairGenerator;
import com.oracle.bmc.http.client.pki.Pem;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.ai.oci.cohere.OCICohereChatModel;
import org.springframework.ai.oci.cohere.OCICohereChatOptions;
import org.springframework.boot.autoconfigure.AutoConfigurations;

View File

@@ -57,10 +57,10 @@ public class OCIGenAiAutoConfigurationIT {
private final ApplicationContextRunner cohereChatContextRunner = new ApplicationContextRunner().withPropertyValues(
// @formatter:off
"spring.ai.oci.genai.authenticationType=file",
"spring.ai.oci.genai.file=" + CONFIG_FILE,
"spring.ai.oci.genai.cohere.chat.options.compartment=" + COMPARTMENT_ID,
"spring.ai.oci.genai.file=" + this.CONFIG_FILE,
"spring.ai.oci.genai.cohere.chat.options.compartment=" + this.COMPARTMENT_ID,
"spring.ai.oci.genai.cohere.chat.options.servingMode=on-demand",
"spring.ai.oci.genai.cohere.chat.options.model=" + CHAT_MODEL_ID
"spring.ai.oci.genai.cohere.chat.options.model=" + this.CHAT_MODEL_ID
// @formatter:on
).withConfiguration(AutoConfigurations.of(OCIGenAiAutoConfiguration.class));

View File

@@ -29,5 +29,7 @@
<suppress files="FiltersParser\.java" checks="MultipleVariableDeclarations"/>
<suppress files="FiltersLexer\.java" checks="MultipleVariableDeclarations"/>
<suppress files="BaseOllamaIT.java" checks="HideUtilityClassConstructor"/>
<suppress files="BaseOCIGenAITest.java" checks="HideUtilityClassConstructor"/>
<suppress files="OpenAiChatModelResponseFormatIT.java" checks="RegexpSinglelineJava"/>
</suppressions>

View File

@@ -231,7 +231,7 @@ public class CoherenceVectorStore implements VectorStore, InitializingBean {
this.documentChunks = this.session.getMap(this.mapName);
switch (this.indexType) {
case HNSW -> this.documentChunks
.addIndex(new HnswIndex<>(DocumentChunk::vector, this.distanceType.name(), dimensions));
.addIndex(new HnswIndex<>(DocumentChunk::vector, this.distanceType.name(), this.dimensions));
case BINARY -> this.documentChunks.addIndex(new BinaryQuantIndex<>(DocumentChunk::vector));
}
}
@@ -255,7 +255,7 @@ public class CoherenceVectorStore implements VectorStore, InitializingBean {
}
String getMapName() {
return mapName;
return this.mapName;
}
}

View File

@@ -92,48 +92,6 @@ public class CoherenceVectorStoreIT {
.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=COSINE",
"test.spring.ai.vectorstore.coherence.indexType=NONE");
@SpringBootConfiguration
@EnableAutoConfiguration
public static class TestClient {
@Value("${test.spring.ai.vectorstore.coherence.distanceType}")
CoherenceVectorStore.DistanceType distanceType;
@Value("${test.spring.ai.vectorstore.coherence.indexType}")
CoherenceVectorStore.IndexType indexType;
@Bean
public VectorStore vectorStore(EmbeddingModel embeddingModel, Session session) {
return new CoherenceVectorStore(embeddingModel, session).setDistanceType(distanceType)
.setIndexType(indexType)
.setForcedNormalization(distanceType == CoherenceVectorStore.DistanceType.COSINE
|| distanceType == CoherenceVectorStore.DistanceType.IP);
}
@Bean
public Session session(Coherence coherence) {
return coherence.getSession();
}
@Bean
public Coherence coherence() {
return Coherence.clusterMember().start().join();
}
@Bean
public EmbeddingModel embeddingModel() {
try {
TransformersEmbeddingModel tem = new TransformersEmbeddingModel();
tem.afterPropertiesSet();
return tem;
}
catch (Exception e) {
throw new RuntimeException("Failed initializing embedding model", e);
}
}
}
private static void truncateMap(ApplicationContext context, String mapName) {
Session session = context.getBean(Session.class);
session.getMap(mapName).truncate();
@@ -153,24 +111,24 @@ public class CoherenceVectorStoreIT {
@ParameterizedTest(name = "Distance {0}, Index {1} : {displayName}")
@MethodSource("distanceAndIndex")
public void addAndSearch(CoherenceVectorStore.DistanceType distanceType, CoherenceVectorStore.IndexType indexType) {
contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
.withPropertyValues("test.spring.ai.vectorstore.coherence.indexType=" + indexType)
.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
vectorStore.add(documents);
vectorStore.add(this.documents);
List<Document> results = vectorStore
.similaritySearch(SearchRequest.query("What is Great Depression").withTopK(1));
assertThat(results).hasSize(1);
Document resultDoc = results.get(0);
assertThat(resultDoc.getId()).isEqualTo(documents.get(2).getId());
assertThat(resultDoc.getId()).isEqualTo(this.documents.get(2).getId());
assertThat(resultDoc.getMetadata()).containsKeys("meta2", "distance");
// Remove all documents from the store
vectorStore.delete(documents.stream().map(doc -> doc.getId()).toList());
vectorStore.delete(this.documents.stream().map(doc -> doc.getId()).toList());
List<Document> results2 = vectorStore
.similaritySearch(SearchRequest.query("Great Depression").withTopK(1));
@@ -184,7 +142,7 @@ public class CoherenceVectorStoreIT {
@MethodSource("distanceAndIndex")
public void searchWithFilters(CoherenceVectorStore.DistanceType distanceType,
CoherenceVectorStore.IndexType indexType) {
contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
this.contextRunner.withPropertyValues("test.spring.ai.vectorstore.coherence.distanceType=" + distanceType)
.withPropertyValues("test.spring.ai.vectorstore.coherence.indexType=" + indexType)
.run(context -> {
@@ -250,7 +208,7 @@ public class CoherenceVectorStoreIT {
@Test
public void documentUpdate() {
contextRunner.run(context -> {
this.contextRunner.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
Document document = new Document(UUID.randomUUID().toString(), "Spring AI rocks!!",
@@ -286,11 +244,11 @@ public class CoherenceVectorStoreIT {
@Test
public void searchWithThreshold() {
contextRunner.run(context -> {
this.contextRunner.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
vectorStore.add(documents);
vectorStore.add(this.documents);
List<Document> fullResult = vectorStore
.similaritySearch(SearchRequest.query("Time Shelter").withTopK(5).withSimilarityThresholdAll());
@@ -310,7 +268,7 @@ public class CoherenceVectorStoreIT {
assertThat(results).hasSize(1);
Document resultDoc = results.get(0);
assertThat(resultDoc.getId()).isEqualTo(documents.get(1).getId());
assertThat(resultDoc.getId()).isEqualTo(this.documents.get(1).getId());
truncateMap(context, ((CoherenceVectorStore) vectorStore).getMapName());
});
@@ -338,4 +296,46 @@ public class CoherenceVectorStoreIT {
return true;
}
@SpringBootConfiguration
@EnableAutoConfiguration
public static class TestClient {
@Value("${test.spring.ai.vectorstore.coherence.distanceType}")
CoherenceVectorStore.DistanceType distanceType;
@Value("${test.spring.ai.vectorstore.coherence.indexType}")
CoherenceVectorStore.IndexType indexType;
@Bean
public VectorStore vectorStore(EmbeddingModel embeddingModel, Session session) {
return new CoherenceVectorStore(embeddingModel, session).setDistanceType(this.distanceType)
.setIndexType(this.indexType)
.setForcedNormalization(this.distanceType == CoherenceVectorStore.DistanceType.COSINE
|| this.distanceType == CoherenceVectorStore.DistanceType.IP);
}
@Bean
public Session session(Coherence coherence) {
return coherence.getSession();
}
@Bean
public Coherence coherence() {
return Coherence.clusterMember().start().join();
}
@Bean
public EmbeddingModel embeddingModel() {
try {
TransformersEmbeddingModel tem = new TransformersEmbeddingModel();
tem.afterPropertiesSet();
return tem;
}
catch (Exception e) {
throw new RuntimeException("Failed initializing embedding model", e);
}
}
}
}