diff --git a/spring-ai-commons/src/main/java/org/springframework/ai/document/DocumentMetadata.java b/spring-ai-commons/src/main/java/org/springframework/ai/document/DocumentMetadata.java index 5cef1f5f458..5ca903da5f6 100644 --- a/spring-ai-commons/src/main/java/org/springframework/ai/document/DocumentMetadata.java +++ b/spring-ai-commons/src/main/java/org/springframework/ai/document/DocumentMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. @@ -32,13 +32,14 @@ public enum DocumentMetadata { * The lower the distance, the more they are similar. * It's the opposite of the similarity score. */ - DISTANCE(); + DISTANCE("distance"); private final String value; - DocumentMetadata() { - this.value = "distance"; + DocumentMetadata(String value) { + this.value = value; } + public String value() { return this.value; } diff --git a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiObservationMetricAttributes.java b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiObservationMetricAttributes.java index a06e4e60f3b..eb7df7d535a 100644 --- a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiObservationMetricAttributes.java +++ b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiObservationMetricAttributes.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. @@ -33,12 +33,12 @@ public enum AiObservationMetricAttributes { /** * The type of token being counted (input, output, total). */ - TOKEN_TYPE(); + TOKEN_TYPE("gen_ai.token.type"); private final String value; - AiObservationMetricAttributes() { - this.value = "gen_ai.token.type"; + AiObservationMetricAttributes(String value) { + this.value = value; } /** diff --git a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiOperationType.java b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiOperationType.java index 8efc00e0efc..ec2022ee1f9 100644 --- a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiOperationType.java +++ b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiOperationType.java @@ -30,7 +30,6 @@ public enum AiOperationType { // @formatter:off - // Please, keep the alphabetical sorting. /** * AI operation type for chat. */ diff --git a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiProvider.java b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiProvider.java index 81d88bb81c7..88105725a69 100644 --- a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiProvider.java +++ b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/AiProvider.java @@ -1,5 +1,5 @@ /* - * Copyright 2023-2024 the original author or authors. + * Copyright 2023-2025 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. @@ -30,7 +30,6 @@ public enum AiProvider { // @formatter:off - // Please, keep the alphabetical sorting. /** * AI system provided by Anthropic. */ @@ -47,41 +46,44 @@ public enum AiProvider { BEDROCK_CONVERSE("bedrock_converse"), /** - * AI system provided by Mistral. + * AI system provided by DeepSeek. */ - MISTRAL_AI("mistral_ai"), + DEEPSEEK("deepseek"), /** - * AI system provided by Oracle OCI. + * AI system provided by Vertex AI. */ - OCI_GENAI("oci_genai"), + GOOGLE_GENAI_AI("google_genai"), /** - * AI system provided by Ollama. + * AI system provided by Minimax. */ - OLLAMA("ollama"), + MINIMAX("minimax"), /** - * AI system provided by OpenAI. + * AI system provided by Mistral. */ - OPENAI("openai"), + MISTRAL_AI("mistral_ai"), /** - * AI system provided by Minimax. + * AI system provided by Oracle OCI. */ - MINIMAX("minimax"), - + OCI_GENAI("oci_genai"), + /** + * AI system provided by Ollama. + */ + OLLAMA("ollama"), /** - * AI system provided by Zhipuai. + * AI system provided by ONNX. */ - ZHIPUAI("zhipuai"), + ONNX("onnx"), /** - * AI system provided by DeepSeek. + * AI system provided by OpenAI. */ - DEEPSEEK("deepseek"), + OPENAI("openai"), /** * AI system provided by Spring AI. @@ -94,14 +96,9 @@ public enum AiProvider { VERTEX_AI("vertex_ai"), /** - * AI system provided by Vertex AI. - */ - GOOGLE_GENAI_AI("google_genai"), - - /** - * AI system provided by ONNX. + * AI system provided by Zhipuai. */ - ONNX("onnx"); + ZHIPUAI("zhipuai"); private final String value; diff --git a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/SpringAiKind.java b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/SpringAiKind.java index 0823609cc7a..8ea4f195891 100644 --- a/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/SpringAiKind.java +++ b/spring-ai-commons/src/main/java/org/springframework/ai/observation/conventions/SpringAiKind.java @@ -26,7 +26,6 @@ public enum SpringAiKind { // @formatter:off - // Please, keep the alphabetical sorting. /** * Spring AI kind for advisor. */ diff --git a/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiOperationTypeTests.java b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiOperationTypeTests.java new file mode 100644 index 00000000000..2c3ec41d05b --- /dev/null +++ b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiOperationTypeTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023-2025 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.observation.conventions; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for {@link AiOperationType}. + * + * @author Thomas Vitale + */ +class AiOperationTypeTests { + + @Test + void enumValuesShouldBeSortedAlphabetically() { + List actualNames = Arrays.stream(AiOperationType.values()).map(Enum::name).collect(Collectors.toList()); + + List sortedNames = actualNames.stream().sorted().collect(Collectors.toList()); + + assertThat(actualNames).as("Enum values should be sorted alphabetically").isEqualTo(sortedNames); + } + +} diff --git a/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiProviderTests.java b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiProviderTests.java new file mode 100644 index 00000000000..ac5ba2095d2 --- /dev/null +++ b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/AiProviderTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023-2025 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.observation.conventions; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for {@link AiProvider}. + * + * @author Thomas Vitale + */ +class AiProviderTests { + + @Test + void enumValuesShouldBeSortedAlphabetically() { + List actualNames = Arrays.stream(AiProvider.values()).map(Enum::name).collect(Collectors.toList()); + + List sortedNames = actualNames.stream().sorted().collect(Collectors.toList()); + + assertThat(actualNames).as("Enum values should be sorted alphabetically").isEqualTo(sortedNames); + } + +} diff --git a/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/SpringAiKindTests.java b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/SpringAiKindTests.java new file mode 100644 index 00000000000..3a6c51d9144 --- /dev/null +++ b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/SpringAiKindTests.java @@ -0,0 +1,43 @@ +/* + * Copyright 2023-2025 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.observation.conventions; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for {@link SpringAiKind}. + * + * @author Thomas Vitale + */ +class SpringAiKindTests { + + @Test + void enumValuesShouldBeSortedAlphabetically() { + List actualNames = Arrays.stream(SpringAiKind.values()).map(Enum::name).collect(Collectors.toList()); + + List sortedNames = actualNames.stream().sorted().collect(Collectors.toList()); + + assertThat(actualNames).as("Enum values should be sorted alphabetically").isEqualTo(sortedNames); + } + +} diff --git a/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/VectorStoreProviderTests.java b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/VectorStoreProviderTests.java new file mode 100644 index 00000000000..7ee3c2f6567 --- /dev/null +++ b/spring-ai-commons/src/test/java/org/springframework/ai/observation/conventions/VectorStoreProviderTests.java @@ -0,0 +1,45 @@ +/* + * Copyright 2023-2025 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.observation.conventions; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +/** + * Unit tests for {@link VectorStoreProvider}. + * + * @author Thomas Vitale + */ +class VectorStoreProviderTests { + + @Test + void enumValuesShouldBeSortedAlphabetically() { + List actualNames = Arrays.stream(VectorStoreProvider.values()) + .map(Enum::name) + .collect(Collectors.toList()); + + List sortedNames = actualNames.stream().sorted().collect(Collectors.toList()); + + assertThat(actualNames).as("Enum values should be sorted alphabetically").isEqualTo(sortedNames); + } + +}