Code cleanup

- Fix javadoc for Qdrant vector store
 - Fix checkstyle errors
This commit is contained in:
Ilayaperumal Gopinathan
2024-11-27 20:12:02 +00:00
parent 23a3d13b39
commit 9ebc6d2c3c
13 changed files with 84 additions and 68 deletions

View File

@@ -698,8 +698,10 @@ public class OpenAiApi {
public enum OutputModality {
// @formatter:off
@JsonProperty("audio") AUDIO,
@JsonProperty("text") TEXT;
@JsonProperty("audio")
AUDIO,
@JsonProperty("text")
TEXT
// @formatter:on
}
@@ -936,23 +938,34 @@ public class OpenAiApi {
* Specifies the voice type.
*/
public enum Voice {
@JsonProperty("alloy") ALLOY,
@JsonProperty("echo") ECHO,
@JsonProperty("fable") FABLE,
@JsonProperty("onyx") ONYX,
@JsonProperty("nova") NOVA,
@JsonProperty("shimmer") SHIMMER;
@JsonProperty("alloy")
ALLOY,
@JsonProperty("echo")
ECHO,
@JsonProperty("fable")
FABLE,
@JsonProperty("onyx")
ONYX,
@JsonProperty("nova")
NOVA,
@JsonProperty("shimmer")
SHIMMER
}
/**
* Specifies the output audio format.
*/
public enum AudioResponseFormat {
@JsonProperty("mp3") MP3,
@JsonProperty("flac") FLAC,
@JsonProperty("opus") OPUS,
@JsonProperty("pcm16") PCM16,
@JsonProperty("wav") WAV;
@JsonProperty("mp3")
MP3,
@JsonProperty("flac")
FLAC,
@JsonProperty("opus")
OPUS,
@JsonProperty("pcm16")
PCM16,
@JsonProperty("wav")
WAV
}
}
@@ -1069,23 +1082,7 @@ public class OpenAiApi {
@JsonProperty("type") String type,
@JsonProperty("text") String text,
@JsonProperty("image_url") ImageUrl imageUrl,
@JsonProperty("input_audio") InputAudio inputAudio) {// @formatter:on
/**
* @param data Base64 encoded audio data.
* @param format The format of the encoded audio data. Currently supports
* "wav" and "mp3".
*/
@JsonInclude(Include.NON_NULL)
public record InputAudio(// @formatter:off
@JsonProperty("data") String data,
@JsonProperty("format") Format format) {
public enum Format {
@JsonProperty("mp3") MP3,
@JsonProperty("wav") WAV;
}// @formatter:on
}
@JsonProperty("input_audio") InputAudio inputAudio) { // @formatter:on
/**
* Shortcut constructor for a text content.
@@ -1111,6 +1108,24 @@ public class OpenAiApi {
this("input_audio", null, null, inputAudio);
}
/**
* @param data Base64 encoded audio data.
* @param format The format of the encoded audio data. Currently supports
* "wav" and "mp3".
*/
@JsonInclude(Include.NON_NULL)
public record InputAudio(// @formatter:off
@JsonProperty("data") String data,
@JsonProperty("format") Format format) {
public enum Format {
@JsonProperty("mp3")
MP3,
@JsonProperty("wav")
WAV
} // @formatter:on
}
/**
* Shortcut constructor for an image content.
*
@@ -1182,7 +1197,7 @@ public class OpenAiApi {
@JsonProperty("data") String data,
@JsonProperty("expires_at") Long expiresAt,
@JsonProperty("transcript") String transcript
) {// @formatter:on
) { // @formatter:on
}
}
@@ -1214,7 +1229,7 @@ public class OpenAiApi {
@JsonProperty("system_fingerprint") String systemFingerprint,
@JsonProperty("object") String object,
@JsonProperty("usage") Usage usage
) {// @formatter:on
) { // @formatter:on
/**
* Chat completion choice.
@@ -1229,7 +1244,7 @@ public class OpenAiApi {
@JsonProperty("finish_reason") ChatCompletionFinishReason finishReason,
@JsonProperty("index") Integer index,
@JsonProperty("message") ChatCompletionMessage message,
@JsonProperty("logprobs") LogProbs logprobs) {// @formatter:on
@JsonProperty("logprobs") LogProbs logprobs) { // @formatter:on
}
}
@@ -1373,7 +1388,7 @@ public class OpenAiApi {
@JsonProperty("service_tier") String serviceTier,
@JsonProperty("system_fingerprint") String systemFingerprint,
@JsonProperty("object") String object,
@JsonProperty("usage") Usage usage) {// @formatter:on
@JsonProperty("usage") Usage usage) { // @formatter:on
/**
* Chat completion choice.

View File

@@ -16,8 +16,14 @@
package org.springframework.ai.openai.api;
import java.io.IOException;
import java.util.Base64;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import reactor.core.publisher.Flux;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletion;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionChunk;
import org.springframework.ai.openai.api.OpenAiApi.ChatCompletionMessage;
@@ -27,11 +33,6 @@ import org.springframework.ai.openai.api.OpenAiApi.Embedding;
import org.springframework.ai.openai.api.OpenAiApi.EmbeddingList;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.ResponseEntity;
import reactor.core.publisher.Flux;
import java.io.IOException;
import java.util.Base64;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -85,7 +86,7 @@ public class OpenAiApiIT {
ChatCompletionMessage chatCompletionMessage = new ChatCompletionMessage(content, Role.USER);
ChatCompletionRequest chatCompletionRequest = new ChatCompletionRequest(List.of(chatCompletionMessage),
OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue(), 0.0);
ResponseEntity<ChatCompletion> response = openAiApi.chatCompletionEntity(chatCompletionRequest);
ResponseEntity<ChatCompletion> response = this.openAiApi.chatCompletionEntity(chatCompletionRequest);
assertThat(response).isNotNull();
assertThat(response.getBody()).isNotNull();
@@ -105,7 +106,7 @@ public class OpenAiApiIT {
ChatCompletionRequest.AudioParameters.AudioResponseFormat.MP3);
ChatCompletionRequest chatCompletionRequest = new ChatCompletionRequest(List.of(chatCompletionMessage),
OpenAiApi.ChatModel.GPT_4_O_AUDIO_PREVIEW.getValue(), audioParameters);
ResponseEntity<ChatCompletion> response = openAiApi.chatCompletionEntity(chatCompletionRequest);
ResponseEntity<ChatCompletion> response = this.openAiApi.chatCompletionEntity(chatCompletionRequest);
assertThat(response).isNotNull();
assertThat(response.getBody()).isNotNull();

View File

@@ -66,7 +66,7 @@ public class MessageTypeContentTests {
ArgumentCaptor<MultiValueMap<String, String>> headersCaptor;
Flux<ChatCompletionChunk> fluxResponse = Flux.generate(
() -> new ChatCompletionChunk("id", List.of(), 0l, "model", null, "fp", "object", null), (state, sink) -> {
() -> new ChatCompletionChunk("id", List.of(), 0L, "model", null, "fp", "object", null), (state, sink) -> {
sink.next(state);
sink.complete();
return state;

View File

@@ -129,7 +129,7 @@ public class OpenAiRetryTests {
var choice = new ChatCompletion.Choice(ChatCompletionFinishReason.STOP, 0,
new ChatCompletionMessage("Response", Role.ASSISTANT), null);
ChatCompletion expectedChatCompletion = new ChatCompletion("id", List.of(choice), 666l, "model", null, null,
ChatCompletion expectedChatCompletion = new ChatCompletion("id", List.of(choice), 666L, "model", null, null,
null, new OpenAiApi.Usage(10, 10, 10));
given(this.openAiApi.chatCompletionEntity(isA(ChatCompletionRequest.class), any()))
@@ -158,7 +158,7 @@ public class OpenAiRetryTests {
var choice = new ChatCompletionChunk.ChunkChoice(ChatCompletionFinishReason.STOP, 0,
new ChatCompletionMessage("Response", Role.ASSISTANT), null);
ChatCompletionChunk expectedChatCompletion = new ChatCompletionChunk("id", List.of(choice), 666l, "model", null,
ChatCompletionChunk expectedChatCompletion = new ChatCompletionChunk("id", List.of(choice), 666L, "model", null,
null, null, null);
given(this.openAiApi.chatCompletionStream(isA(ChatCompletionRequest.class), any()))

View File

@@ -36,8 +36,8 @@ import org.springframework.ai.chat.client.advisor.api.AdvisedResponse;
import org.springframework.ai.chat.client.advisor.api.CallAroundAdvisor;
import org.springframework.ai.chat.client.advisor.api.CallAroundAdvisorChain;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallback.SchemaType;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatOptions;
import org.springframework.beans.factory.annotation.Autowired;

View File

@@ -26,8 +26,8 @@ import org.springframework.ai.chat.messages.MessageType;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.ToolResponseMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackWrapper;
import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;

View File

@@ -37,7 +37,6 @@ import org.springframework.core.KotlinDetector;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.ResolvableType;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
/**

View File

@@ -94,7 +94,7 @@ public interface FunctionCallback {
* Describes the type of the schema used to describe the input parameters of the
* function.
*/
public enum SchemaType {
enum SchemaType {
/**
* JSON schema

View File

@@ -1,18 +1,19 @@
/*
* Copyright 2024 - 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.
*/
* Copyright 2024-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.
*/
package org.springframework.ai.model.function;
import org.springframework.lang.NonNull;

View File

@@ -194,7 +194,7 @@ public class FilterExpressionTextParserTests {
@Test
public void testUnescapedIdentifierWithUnderscores() {
Expression exp = parser.parse("file_name == 'medicaid-wa-faqs.pdf'");
Expression exp = this.parser.parse("file_name == 'medicaid-wa-faqs.pdf'");
assertThat(exp).isEqualTo(new Expression(EQ, new Key("file_name"), new Value("medicaid-wa-faqs.pdf")));
}

View File

@@ -26,9 +26,9 @@ import org.springframework.ai.embedding.observation.EmbeddingModelObservationCon
import org.springframework.ai.minimax.MiniMaxChatModel;
import org.springframework.ai.minimax.MiniMaxEmbeddingModel;
import org.springframework.ai.minimax.api.MiniMaxApi;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;

View File

@@ -25,10 +25,10 @@ import io.micrometer.observation.ObservationRegistry;
import org.springframework.ai.autoconfigure.retry.SpringAiRetryAutoConfiguration;
import org.springframework.ai.chat.observation.ChatModelObservationConvention;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.ai.model.function.FunctionCallback;
import org.springframework.ai.model.function.FunctionCallback.SchemaType;
import org.springframework.ai.model.function.FunctionCallbackResolver;
import org.springframework.ai.model.function.DefaultFunctionCallbackResolver;
import org.springframework.ai.vertexai.gemini.VertexAiGeminiChatModel;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfiguration;

View File

@@ -200,9 +200,9 @@ public class QdrantVectorStore extends AbstractObservationVectorStore implements
}
/**
* Extracts metadata from a Protobuf Struct.
* @param metadataStruct The Protobuf Struct containing metadata.
* @return The metadata as a map.
* Returns {@link Document} using the {@link ScoredPoint}
* @param point ScoredPoint containing the query response.
* @return the {@link Document} representing the response.
*/
private Document toDocument(ScoredPoint point) {
try {