Skip to content

Commit

Permalink
Fix checkstyle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilayaperumalg committed Nov 19, 2024
1 parent 3812d2e commit 3b95dfd
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public enum ChatModel implements ChatModelDescription {
/**
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,34 @@
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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -35,8 +50,8 @@ public void createAzureOpenAiChatModelTest() {

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();

Expand All @@ -53,13 +68,13 @@ private class TestFunctionCallback implements FunctionCallback {

private final String name;

public TestFunctionCallback(String name) {
TestFunctionCallback(String name) {
this.name = name;
}

@Override
public String getName() {
return name;
return this.name;
}

@Override
Expand All @@ -79,4 +94,4 @@ public String call(String functionInput) {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,6 +28,10 @@
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
Expand All @@ -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());
Expand All @@ -64,12 +64,12 @@ public void buildChatResponseMetadata() {
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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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 {
Expand Down Expand Up @@ -145,9 +144,9 @@ public void testPromptCopy() {
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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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;
Expand All @@ -51,6 +50,7 @@
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 })
Expand Down Expand Up @@ -188,7 +188,7 @@ static class PropertiesAwsOpenSearchConnectionDetails implements AwsOpenSearchCo

private final OpenSearchVectorStoreProperties.Aws aws;

public PropertiesAwsOpenSearchConnectionDetails(OpenSearchVectorStoreProperties properties) {
PropertiesAwsOpenSearchConnectionDetails(OpenSearchVectorStoreProperties properties) {
this.aws = properties.getAws();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,16 +46,6 @@
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,25 @@
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;
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 3b95dfd

Please sign in to comment.