Fix checkstyle errors

This commit is contained in:
Ilayaperumal Gopinathan
2024-11-19 23:20:08 +00:00
parent 3812d2e6d8
commit 3b95dfd87f
11 changed files with 85 additions and 47 deletions

View File

@@ -261,7 +261,8 @@ public class AnthropicApi {
/**
* The CLAUDE_INSTANT_1_2
*/
@Deprecated CLAUDE_INSTANT_1_2("claude-instant-1.2");
@Deprecated
CLAUDE_INSTANT_1_2("claude-instant-1.2");
// @formatter:on
private final String value;

View File

@@ -24,13 +24,34 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import com.azure.ai.openai.OpenAIAsyncClient;
import com.azure.ai.openai.OpenAIClient;
import com.azure.ai.openai.OpenAIClientBuilder;
import com.azure.ai.openai.models.*;
import com.azure.ai.openai.models.ChatChoice;
import com.azure.ai.openai.models.ChatCompletions;
import com.azure.ai.openai.models.ChatCompletionsFunctionToolCall;
import com.azure.ai.openai.models.ChatCompletionsFunctionToolDefinition;
import com.azure.ai.openai.models.ChatCompletionsFunctionToolDefinitionFunction;
import com.azure.ai.openai.models.ChatCompletionsJsonResponseFormat;
import com.azure.ai.openai.models.ChatCompletionsOptions;
import com.azure.ai.openai.models.ChatCompletionsResponseFormat;
import com.azure.ai.openai.models.ChatCompletionsTextResponseFormat;
import com.azure.ai.openai.models.ChatCompletionsToolCall;
import com.azure.ai.openai.models.ChatCompletionsToolDefinition;
import com.azure.ai.openai.models.ChatMessageContentItem;
import com.azure.ai.openai.models.ChatMessageImageContentItem;
import com.azure.ai.openai.models.ChatMessageImageUrl;
import com.azure.ai.openai.models.ChatMessageTextContentItem;
import com.azure.ai.openai.models.ChatRequestAssistantMessage;
import com.azure.ai.openai.models.ChatRequestMessage;
import com.azure.ai.openai.models.ChatRequestSystemMessage;
import com.azure.ai.openai.models.ChatRequestToolMessage;
import com.azure.ai.openai.models.ChatRequestUserMessage;
import com.azure.ai.openai.models.CompletionsFinishReason;
import com.azure.ai.openai.models.ContentFilterResultsForPrompt;
import com.azure.ai.openai.models.FunctionCall;
import com.azure.core.util.BinaryData;
import io.micrometer.observation.Observation;
import io.micrometer.observation.ObservationRegistry;

View File

@@ -1,9 +1,24 @@
package org.springframework.ai.azure.openai;
/*
* 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.azure.ai.openai.OpenAIClientBuilder;
package org.springframework.ai.azure.openai;
import java.util.List;
import com.azure.ai.openai.OpenAIClientBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -35,8 +50,8 @@ public class AzureOpenAiChatModelTests {
List<FunctionCallback> functionCallbacks = List.of(new TestFunctionCallback(callbackFromConstructorParam));
AzureOpenAiChatModel openAiChatModel = new AzureOpenAiChatModel(mockClient, chatOptions,
functionCallbackContext, functionCallbacks);
AzureOpenAiChatModel openAiChatModel = new AzureOpenAiChatModel(this.mockClient, chatOptions,
this.functionCallbackContext, functionCallbacks);
assert 2 == openAiChatModel.getFunctionCallbackRegister().size();
@@ -53,13 +68,13 @@ public class AzureOpenAiChatModelTests {
private final String name;
public TestFunctionCallback(String name) {
TestFunctionCallback(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
return this.name;
}
@Override
@@ -79,4 +94,4 @@ public class AzureOpenAiChatModelTests {
}
}
}

View File

@@ -24,7 +24,6 @@ import com.azure.core.credential.AzureKeyCredential;
import io.micrometer.observation.tck.TestObservationRegistry;
import io.micrometer.observation.tck.TestObservationRegistryAssert;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.springframework.ai.document.MetadataMode;
import org.springframework.ai.embedding.EmbeddingRequest;

View File

@@ -16,10 +16,6 @@
package org.springframework.ai.ollama;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
import java.time.Duration;
import org.junit.jupiter.api.Test;
@@ -32,6 +28,10 @@ import org.springframework.ai.ollama.api.OllamaApi;
import org.springframework.ai.ollama.api.OllamaModel;
import org.springframework.ai.ollama.api.OllamaOptions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.BDDMockito.given;
/**
* @author Jihoon Kim
* @since 1.0.0
@@ -49,7 +49,7 @@ public class OllamaChatModelTests {
public void buildOllamaChatModel() {
Exception exception = assertThrows(IllegalArgumentException.class,
() -> OllamaChatModel.builder()
.withOllamaApi(ollamaApi)
.withOllamaApi(this.ollamaApi)
.withDefaultOptions(OllamaOptions.create().withModel(OllamaModel.LLAMA2))
.withModelManagementOptions(null)
.build());
@@ -64,12 +64,12 @@ public class OllamaChatModelTests {
Duration promptEvalDuration = Duration.ofSeconds(8);
Integer promptEvalCount = 808;
given(response.evalDuration()).willReturn(evalDuration);
given(response.evalCount()).willReturn(evalCount);
given(response.promptEvalDuration()).willReturn(promptEvalDuration);
given(response.promptEvalCount()).willReturn(promptEvalCount);
given(this.response.evalDuration()).willReturn(evalDuration);
given(this.response.evalCount()).willReturn(evalCount);
given(this.response.promptEvalDuration()).willReturn(promptEvalDuration);
given(this.response.promptEvalCount()).willReturn(promptEvalCount);
ChatResponseMetadata metadata = OllamaChatModel.from(response);
ChatResponseMetadata metadata = OllamaChatModel.from(this.response);
assertEquals(evalDuration, metadata.get("eval-duration"));
assertEquals(evalCount, metadata.get("eval-count"));

View File

@@ -30,7 +30,6 @@ import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.ai.chat.prompt.SystemPromptTemplate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotSame;
@SuppressWarnings("unchecked")
class PromptTests {
@@ -145,9 +144,9 @@ class PromptTests {
Prompt prompt = promptTemplate.create(model, chatOptions);
Prompt copiedPrompt = prompt.copy();
assertNotSame(prompt, copiedPrompt);
assertNotSame(prompt.getOptions(), copiedPrompt.getOptions());
assertNotSame(prompt.getInstructions(), copiedPrompt.getInstructions());
assertThat(prompt).isNotSameAs(copiedPrompt);
assertThat(prompt.getOptions()).isNotSameAs(copiedPrompt.getOptions());
assertThat(prompt.getInstructions()).isNotSameAs(copiedPrompt.getInstructions());
}
}

View File

@@ -30,7 +30,6 @@ import org.opensearch.client.transport.OpenSearchTransport;
import org.opensearch.client.transport.aws.AwsSdk2Transport;
import org.opensearch.client.transport.aws.AwsSdk2TransportOptions;
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder;
import org.springframework.util.StringUtils;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
@@ -51,6 +50,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClas
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
@AutoConfiguration
@ConditionalOnClass({ OpenSearchVectorStore.class, EmbeddingModel.class, OpenSearchClient.class })
@@ -188,7 +188,7 @@ public class OpenSearchVectorStoreAutoConfiguration {
private final OpenSearchVectorStoreProperties.Aws aws;
public PropertiesAwsOpenSearchConnectionDetails(OpenSearchVectorStoreProperties properties) {
PropertiesAwsOpenSearchConnectionDetails(OpenSearchVectorStoreProperties properties) {
this.aws = properties.getAws();
}

View File

@@ -17,9 +17,10 @@
package org.springframework.ai.docker.compose.service.connection.opensearch;
import org.junit.jupiter.api.Test;
import org.testcontainers.utility.DockerImageName;
import org.springframework.ai.autoconfigure.vectorstore.opensearch.AwsOpenSearchConnectionDetails;
import org.springframework.boot.docker.compose.service.connection.test.AbstractDockerComposeIntegrationTests;
import org.testcontainers.utility.DockerImageName;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -16,10 +16,11 @@
package org.springframework.ai.testcontainers.service.connection.opensearch;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.springframework.ai.autoconfigure.vectorstore.opensearch.AwsOpenSearchConnectionDetails;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionDetailsFactory;
import org.springframework.boot.testcontainers.service.connection.ContainerConnectionSource;
import org.testcontainers.containers.localstack.LocalStackContainer;
/**
* @author Eddú Meléndez

View File

@@ -16,11 +16,22 @@
package org.springframework.ai.testcontainers.service.connection.opensearch;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import com.jayway.jsonpath.JsonPath;
import net.minidev.json.JSONArray;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.springframework.ai.autoconfigure.vectorstore.opensearch.OpenSearchVectorStoreAutoConfiguration;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
@@ -35,16 +46,6 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.testcontainers.containers.localstack.LocalStackContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

View File

@@ -24,25 +24,25 @@ import java.util.Map;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.opensearch.testcontainers.OpensearchContainer;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import org.springframework.ai.autoconfigure.vectorstore.opensearch.OpenSearchVectorStoreAutoConfiguration;
import org.springframework.ai.autoconfigure.vectorstore.opensearch.OpenSearchVectorStoreProperties;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.transformers.TransformersEmbeddingModel;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.FilteredClassLoader;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testcontainers.lifecycle.TestcontainersLifecycleApplicationContextInitializer;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.boot.testcontainers.service.connection.ServiceConnectionAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import software.amazon.awssdk.http.apache.ApacheHttpClient;
import software.amazon.awssdk.regions.Region;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasSize;
@@ -75,7 +75,7 @@ class OpenSearchContainerConnectionDetailsFactoryTest {
@Test
public void addAndSearchTest() {
contextRunner.run(context -> {
this.contextRunner.run(context -> {
VectorStore vectorStore = context.getBean(VectorStore.class);
vectorStore.add(this.documents);