diff --git a/spring-ai-core/src/main/java/org/springframework/ai/aot/KnuddelsRuntimeHints.java b/spring-ai-core/src/main/java/org/springframework/ai/aot/KnuddelsRuntimeHints.java index fb676484d9..ccc0e65644 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/aot/KnuddelsRuntimeHints.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/aot/KnuddelsRuntimeHints.java @@ -18,11 +18,12 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.ClassPathResource; +import org.springframework.lang.Nullable; public class KnuddelsRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(RuntimeHints hints, ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { hints.resources().registerResource(new ClassPathResource("/com/knuddels/jtokkit/cl100k_base.tiktoken")); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/aot/SpringAiCoreRuntimeHints.java b/spring-ai-core/src/main/java/org/springframework/ai/aot/SpringAiCoreRuntimeHints.java index 393687becd..643e194031 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/aot/SpringAiCoreRuntimeHints.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/aot/SpringAiCoreRuntimeHints.java @@ -29,7 +29,6 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.ClassPathResource; -import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; @@ -39,7 +38,7 @@ public class SpringAiCoreRuntimeHints implements RuntimeHintsRegistrar { @Override - public void registerHints(@NonNull RuntimeHints hints, @Nullable ClassLoader classLoader) { + public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) { var chatTypes = Set.of(AbstractMessage.class, AssistantMessage.class, ToolResponseMessage.class, Message.class, MessageType.class, UserMessage.class, SystemMessage.class, FunctionCallbackContext.class, diff --git a/spring-ai-core/src/main/java/org/springframework/ai/aot/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/aot/package-info.java new file mode 100644 index 0000000000..d584b48aee --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/aot/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for AOT runtime hints. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.aot; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscription.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscription.java index c6de0ed68e..cdf8b599b7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscription.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscription.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.ModelResult; @@ -25,12 +26,14 @@ * * @author Michael Lavelle * @author Piotr Olaszewski + * @author Soby Chacko * @since 0.8.1 */ public class AudioTranscription implements ModelResult { private final String text; + @Nullable private AudioTranscriptionMetadata transcriptionMetadata; public AudioTranscription(String text) { diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionMetadata.java index bd064a6596..4ffc8e5e17 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.ResultMetadata; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionOptions.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionOptions.java index 95bd877e71..20970091ed 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionOptions.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.ModelOptions; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionPrompt.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionPrompt.java index 6f5208240e..05d9245eb2 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionPrompt.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionPrompt.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.ModelRequest; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; /** * Represents an audio transcription prompt for an AI model. It implements the @@ -25,12 +27,14 @@ * * @author Michael Lavelle * @author Piotr Olaszewski + * @author Soby Chacko * @since 0.8.1 */ public class AudioTranscriptionPrompt implements ModelRequest { private final Resource audioResource; + @Nullable private AudioTranscriptionOptions modelOptions; /** @@ -50,7 +54,7 @@ public AudioTranscriptionPrompt(Resource audioResource) { * @param audioResource resource of the audio file. * @param modelOptions */ - public AudioTranscriptionPrompt(Resource audioResource, AudioTranscriptionOptions modelOptions) { + public AudioTranscriptionPrompt(Resource audioResource, @Nullable AudioTranscriptionOptions modelOptions) { this.audioResource = audioResource; this.modelOptions = modelOptions; } @@ -61,8 +65,9 @@ public Resource getInstructions() { } @Override + @Nullable public AudioTranscriptionOptions getOptions() { - return modelOptions; + return this.modelOptions; } } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponse.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponse.java index e1a652355d..1be4743018 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponse.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponse.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.ModelResponse; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponseMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponseMetadata.java index 66c3fdf897..0a047d9f72 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponseMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/AudioTranscriptionResponseMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.audio.transcription; import org.springframework.ai.model.MutableResponseMetadata; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/package-info.java new file mode 100644 index 0000000000..9f515b19f5 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/audio/transcription/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for audio transcription components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.audio.transcription; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/SimpleLoggerAdvisor.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/SimpleLoggerAdvisor.java index d09141720d..9f786a95f5 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/SimpleLoggerAdvisor.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/SimpleLoggerAdvisor.java @@ -1,5 +1,5 @@ /* - * Copyright 2024-2024 the original author or authors. + * Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.advisor; import java.util.Map; @@ -37,13 +38,9 @@ public class SimpleLoggerAdvisor implements RequestResponseAdvisor { private static final Logger logger = LoggerFactory.getLogger(SimpleLoggerAdvisor.class); - public static final Function DEFAULT_REQUEST_TO_STRING = (request) -> { - return request.toString(); - }; + public static final Function DEFAULT_REQUEST_TO_STRING = Record::toString; - public static final Function DEFAULT_RESPONSE_TO_STRING = (response) -> { - return ModelOptionsUtils.toJsonString(response); - }; + public static final Function DEFAULT_RESPONSE_TO_STRING = ModelOptionsUtils::toJsonString; private final Function requestToString; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationContext.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationContext.java index 5a4421e98c..8505ba692c 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationContext.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationContext.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.advisor.observation; import java.util.Map; @@ -20,12 +21,14 @@ import org.springframework.ai.chat.client.AdvisedRequest; import org.springframework.ai.chat.client.ChatClient; import org.springframework.ai.chat.prompt.Prompt; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import io.micrometer.observation.Observation; /** * @author Christian Tzolov + * @author Soby Chacko * @since 1.0.0 */ @@ -37,36 +40,43 @@ public enum Type { } + @Nullable private String advisorName; + @Nullable private Type advisorType; /** * The {@link AdvisedRequest} data to be advised. Represents the row * {@link ChatClient.ChatClientRequestSpec} data before sealed into a {@link Prompt}. */ + @Nullable private AdvisedRequest advisorRequest; /** * The shared data between the advisors in the chain. It is shared between all request * and response advising points of all advisors in the chain. */ + @Nullable private Map advisorRequestContext; /** * the shared data between the advisors in the chain. It is shared between all request * and response advising points of all advisors in the chain. */ + @Nullable private Map advisorResponseContext; public void setAdvisorName(String advisorName) { this.advisorName = advisorName; } + @Nullable public String getAdvisorName() { return this.advisorName; } + @Nullable public Type getAdvisorType() { return this.advisorType; } @@ -75,6 +85,7 @@ public void setAdvisorType(Type type) { this.advisorType = type; } + @Nullable public AdvisedRequest getAdvisedRequest() { return this.advisorRequest; } @@ -83,6 +94,7 @@ public void setAdvisedRequest(AdvisedRequest advisedRequest) { this.advisorRequest = advisedRequest; } + @Nullable public Map getAdvisorRequestContext() { return this.advisorRequestContext; } @@ -91,6 +103,7 @@ public void setAdvisorRequestContext(Map advisorRequestContext) this.advisorRequestContext = advisorRequestContext; } + @Nullable public Map getAdvisorResponseContext() { return this.advisorResponseContext; } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationDocumentation.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationDocumentation.java index 5bb022b087..c38e6f6628 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationDocumentation.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/AdvisorObservationDocumentation.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.advisor.observation; import io.micrometer.common.docs.KeyName; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/DefaultAdvisorObservationConvention.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/DefaultAdvisorObservationConvention.java index e6babe0189..c0f756b0b0 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/DefaultAdvisorObservationConvention.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/DefaultAdvisorObservationConvention.java @@ -93,8 +93,8 @@ public KeyValues getHighCardinalityKeyValues(AdvisorObservationContext context) return KeyValues.of(advisorName(context)); } - protected KeyValue advisorName(AdvisorObservationContext context) { - if (context.getAdvisorType() != null) { + protected KeyValue advisorName(@Nullable AdvisorObservationContext context) { + if (context != null && context.getAdvisorType() != null) { return KeyValue.of(HighCardinalityKeyNames.ADVISOR_NAME, context.getAdvisorName()); } return ADVISOR_NAME_NONE; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/ObservableRequestResponseAdvisor.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/ObservableRequestResponseAdvisor.java index cbc57f6f18..4775add23a 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/ObservableRequestResponseAdvisor.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/ObservableRequestResponseAdvisor.java @@ -38,6 +38,7 @@ public class ObservableRequestResponseAdvisor implements RequestResponseAdvisor private final ObservationRegistry observationRegistry; + @Nullable private final AdvisorObservationConvention customObservationConvention; public ObservableRequestResponseAdvisor(RequestResponseAdvisor targetAdvisor, diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/package-info.java new file mode 100644 index 0000000000..a00891c629 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/observation/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat client advisor observability components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.client.advisor.observation; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/package-info.java new file mode 100644 index 0000000000..ffd8088f27 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/advisor/package-info.java @@ -0,0 +1,9 @@ +/** + * Package containing chat client advisor components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.client.advisor; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientInputContentObservationFilter.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientInputContentObservationFilter.java index f250d4c0e8..fbae11f708 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientInputContentObservationFilter.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientInputContentObservationFilter.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.observation; import java.util.stream.Collectors; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationContext.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationContext.java index cb5bf80da1..124a11de7a 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationContext.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationContext.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.observation; import org.springframework.ai.chat.client.DefaultChatClient.DefaultChatClientRequestSpec; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationConvention.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationConvention.java index fd6790c484..f34abe1fae 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationConvention.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationConvention.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.observation; import io.micrometer.observation.Observation; @@ -22,7 +23,6 @@ * @author Christian Tzolov * @since 1.0.0 */ - public interface ChatClientObservationConvention extends ObservationConvention { @Override diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationDocumentation.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationDocumentation.java index 875832201c..1434d15bc8 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationDocumentation.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/ChatClientObservationDocumentation.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.observation; import io.micrometer.common.docs.KeyName; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/DefaultChatClientObservationConvention.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/DefaultChatClientObservationConvention.java index ba585a9284..57fa412672 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/DefaultChatClientObservationConvention.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/DefaultChatClientObservationConvention.java @@ -1,5 +1,5 @@ /* -* Copyright 2024 - 2024 the original author or authors. +* Copyright 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.chat.client.observation; import java.util.stream.Collectors; @@ -29,7 +30,6 @@ * @author Christian Tzolov * @since 1.0.0 */ - public class DefaultChatClientObservationConvention implements ChatClientObservationConvention { public static final String DEFAULT_NAME = "spring.ai.chat.client.operation"; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/package-info.java new file mode 100644 index 0000000000..e683368d13 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/observation/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat client observability components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.client.observation; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/client/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/package-info.java new file mode 100644 index 0000000000..a73950eaf1 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/client/package-info.java @@ -0,0 +1,9 @@ +/** + * Package containing chat client components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.client; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/memory/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/memory/package-info.java new file mode 100644 index 0000000000..4c5556539c --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/memory/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat memory components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.memory; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/messages/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/messages/package-info.java new file mode 100644 index 0000000000..587033c2de --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/messages/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat message components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.messages; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/metadata/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/metadata/package-info.java new file mode 100644 index 0000000000..59c9c9391d --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/metadata/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat metadata components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.metadata; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/model/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/model/package-info.java new file mode 100644 index 0000000000..55dbee5b6a --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/model/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat model components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.model; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/observation/package-info.java index 0f796c0b06..58a72c7927 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/observation/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/observation/package-info.java @@ -1,19 +1,6 @@ -/* - * Copyright 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 for chat observability components. */ - @NonNullApi @NonNullFields package org.springframework.ai.chat.observation; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/package-info.java index 4c0f666267..98d92eb712 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/package-info.java @@ -1,18 +1,3 @@ -/* - * 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. - */ /** * The org.sf.ai.chat package represents the bounded context for the Chat Model within the * AI generative model domain. This package extends the core domain defined in diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/prompt/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/prompt/package-info.java new file mode 100644 index 0000000000..c841d7b12e --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/prompt/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for chat prompt components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.chat.prompt; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/converter/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/converter/package-info.java new file mode 100644 index 0000000000..9d8ca66e11 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/converter/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for converter components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.converter; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/document/id/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/document/id/package-info.java new file mode 100644 index 0000000000..944d581775 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/document/id/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for document id components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.document.id; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/document/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/document/package-info.java new file mode 100644 index 0000000000..c54b763476 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/document/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for document components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.document; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/embedding/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/embedding/observation/package-info.java index 95579239b5..a6e95fc402 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/embedding/observation/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/embedding/observation/package-info.java @@ -1,19 +1,6 @@ -/* - * Copyright 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 for embedding observability components. */ - @NonNullApi @NonNullFields package org.springframework.ai.embedding.observation; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/embedding/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/embedding/package-info.java new file mode 100644 index 0000000000..3996058854 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/embedding/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for embedding components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.embedding; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/evaluation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/evaluation/package-info.java new file mode 100644 index 0000000000..4bc5dd7e91 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/evaluation/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for evaluation components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.evaluation; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/image/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/image/observation/package-info.java index f28e93b060..3720830fe4 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/image/observation/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/image/observation/package-info.java @@ -1,17 +1,5 @@ -/* - * Copyright 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 for image observability. */ @NonNullApi diff --git a/spring-ai-core/src/main/java/org/springframework/ai/image/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/image/package-info.java new file mode 100644 index 0000000000..59ef0b5a19 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/image/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for image components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.image; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/AbstractResponseMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/model/AbstractResponseMetadata.java index 42bd8678e8..f55776c1d7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/AbstractResponseMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/AbstractResponseMetadata.java @@ -1,6 +1,21 @@ +/* + * 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; -import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; import java.util.Collections; @@ -32,7 +47,6 @@ public T get(String key) { * @return entry * @throws IllegalArgumentException if not present */ - @NonNull public T getRequired(Object key) { T object = (T) this.map.get(key); if (object == null) { diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/Content.java b/spring-ai-core/src/main/java/org/springframework/ai/model/Content.java index 7a49511e9e..bb3879fb04 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/Content.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/Content.java @@ -1,7 +1,25 @@ +/* + * 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; import java.util.Map; +import org.springframework.lang.Nullable; + /** * Data structure that contains content and metadata. Common parent for the * {@link org.springframework.ai.document.Document} and the @@ -16,6 +34,7 @@ public interface Content { /** * Get the content of the message. */ + @Nullable String getContent(); // TODO consider getText /** diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/EmbeddingUtils.java b/spring-ai-core/src/main/java/org/springframework/ai/model/EmbeddingUtils.java index aba522636e..8853cab877 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/EmbeddingUtils.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/EmbeddingUtils.java @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; import java.util.ArrayList; import java.util.List; +import io.micrometer.context.Nullable; + /** * @author Christian Tzolov * @since 1.0.0 @@ -31,11 +34,13 @@ public static List doubleToFloat(final List doubles) { return doubles.stream().map(f -> f.floatValue()).toList(); } + @Nullable public static float[] toPrimitive(List floats) { return toPrimitive(floats.toArray(new Float[floats.size()])); } - public static float[] toPrimitive(final Float[] array) { + @Nullable + public static float[] toPrimitive(@Nullable final Float[] array) { if (array == null) { return null; } @@ -44,12 +49,13 @@ public static float[] toPrimitive(final Float[] array) { } final float[] result = new float[array.length]; for (int i = 0; i < array.length; i++) { - result[i] = array[i].floatValue(); + result[i] = array[i]; } return result; } - public static Float[] toFloatArray(final float[] array) { + @Nullable + public static Float[] toFloatArray(@Nullable final float[] array) { if (array == null) { return null; } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/Media.java b/spring-ai-core/src/main/java/org/springframework/ai/model/Media.java index 5391f1f98f..fcc6c1a259 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/Media.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/Media.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; import org.springframework.core.io.Resource; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/MediaContent.java b/spring-ai-core/src/main/java/org/springframework/ai/model/MediaContent.java index 4b436e82a6..976d2022ea 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/MediaContent.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/MediaContent.java @@ -1,3 +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. + */ + package org.springframework.ai.model; import java.util.Collection; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/Model.java b/spring-ai-core/src/main/java/org/springframework/ai/model/Model.java index 1671a3dc49..f11dcfb7e4 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/Model.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/Model.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; /** diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptions.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptions.java index 124818e80b..2318673ec3 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptions.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptions.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; /** diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptionsUtils.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptionsUtils.java index 809b1cc82a..7c618f4da5 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptionsUtils.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelOptionsUtils.java @@ -13,10 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -48,6 +50,7 @@ import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -299,7 +302,7 @@ public static T mergeBeans(S source, T target, Cla BeanWrapper sourceBeanWrap = new BeanWrapperImpl(source); BeanWrapper targetBeanWrap = new BeanWrapperImpl(target); - List interfaceNames = Arrays.stream(sourceInterfaceClazz.getMethods()).map(m -> m.getName()).toList(); + List interfaceNames = Arrays.stream(sourceInterfaceClazz.getMethods()).map(Method::getName).toList(); for (PropertyDescriptor descriptor : sourceBeanWrap.getPropertyDescriptors()) { @@ -361,7 +364,7 @@ public static String getJsonSchema(Class clazz, boolean toUpperCaseTypeValues return node.toPrettyString(); } - public static void toUpperCaseTypeValues(ObjectNode node) { + public static void toUpperCaseTypeValues(@Nullable ObjectNode node) { if (node == null) { return; } @@ -379,8 +382,8 @@ else if (value.isArray()) { }); } else if (value.isTextual() && entry.getKey().equals("type")) { - String oldValue = ((ObjectNode) node).get("type").asText(); - ((ObjectNode) node).put("type", oldValue.toUpperCase()); + String oldValue = node.get("type").asText(); + node.put("type", oldValue.toUpperCase()); } }); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelRequest.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelRequest.java index 94c2e8aefc..178ed8dee1 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelRequest.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelRequest.java @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; +import org.springframework.lang.Nullable; + /** * Interface representing a request to an AI model. This interface encapsulates the * necessary information required to interact with an AI model, including instructions or @@ -38,6 +41,7 @@ public interface ModelRequest { * Retrieves the customizable options for AI model interactions. * @return the customizable options for AI model interactions */ + @Nullable ModelOptions getOptions(); } \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResponse.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResponse.java index f4a9bf83a0..97de7dd533 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResponse.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResponse.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; import java.util.List; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResult.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResult.java index 6ee17815c7..0b3b7293c3 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResult.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ModelResult.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,8 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; +import org.springframework.lang.Nullable; + /** * This interface provides methods to access the main output of the AI model and the * metadata associated with this result. It is designed to offer a standardized and @@ -31,12 +34,14 @@ public interface ModelResult { * Retrieves the output generated by the AI model. * @return the output generated by the AI model */ + @Nullable T getOutput(); /** * Retrieves the metadata associated with the result of an AI model. * @return the metadata associated with the result */ + @Nullable ResultMetadata getMetadata(); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/MutableResponseMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/model/MutableResponseMetadata.java index ac0c9254e7..dff803a398 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/MutableResponseMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/MutableResponseMetadata.java @@ -1,6 +1,21 @@ +/* + * 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; -import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; import java.util.Collections; @@ -55,7 +70,6 @@ public Object remove(Object key) { * @return entry */ @Override - @NonNull public T getRequired(Object key) { T object = (T) this.map.get(key); if (object == null) { diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ResponseMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ResponseMetadata.java index 24e544d4f2..b914dbd24a 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ResponseMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ResponseMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; -import io.micrometer.common.lang.NonNull; import io.micrometer.common.lang.Nullable; import java.util.Map; @@ -46,7 +46,6 @@ public interface ResponseMetadata { * @throws IllegalArgumentException if not present * @return entry */ - @NonNull T getRequired(Object key); /** @@ -80,7 +79,7 @@ default T getOrDefault(String key, Supplier defaultObjectSupplier) { Set> entrySet(); - public Set keySet(); + Set keySet(); /** * Returns {@code true} if this map contains no key-value mappings. diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/ResultMetadata.java b/spring-ai-core/src/main/java/org/springframework/ai/model/ResultMetadata.java index 05d2aaca40..253d508f0f 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/ResultMetadata.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/ResultMetadata.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; /** diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/StreamingModel.java b/spring-ai-core/src/main/java/org/springframework/ai/model/StreamingModel.java index 2c1de77a9b..d807fc3ec3 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/StreamingModel.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/StreamingModel.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model; import reactor.core.publisher.Flux; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java index 6bd639c883..1af04aae91 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/AbstractFunctionCallback.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.util.function.Function; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java index 6f4e8bac48..9165b79e30 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallback.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; /** diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackContext.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackContext.java index 59f4309875..8574fb0c5c 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackContext.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.lang.reflect.Type; @@ -59,12 +60,12 @@ public void setSchemaType(SchemaType schemaType) { } @Override - public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException { + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = (GenericApplicationContext) applicationContext; } @SuppressWarnings({ "rawtypes", "unchecked" }) - public FunctionCallback getFunctionCallback(@NonNull String beanName, @Nullable String defaultDescription) { + public FunctionCallback getFunctionCallback(String beanName, @Nullable String defaultDescription) { Type beanType = FunctionContextUtils.findType(this.applicationContext.getBeanFactory(), beanName); diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java index bfa9c9c3c2..ee49bff0b2 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallbackWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.util.function.Function; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java index df603d2b38..d116f60abf 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptions.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.util.List; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java index 8368e7d1fc..5f2df6a92d 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.util.ArrayList; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/TypeResolverHelper.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/TypeResolverHelper.java index 1fa0736d3e..000057bd87 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/TypeResolverHelper.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/TypeResolverHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.function; import java.lang.reflect.GenericArrayType; @@ -23,6 +24,7 @@ import net.jodah.typetools.TypeResolver; import org.springframework.cloud.function.context.catalog.FunctionTypeUtils; +import org.springframework.lang.Nullable; /** * A utility class that provides methods for resolving types and classes related to @@ -107,10 +109,8 @@ public static Type getFunctionArgumentType(Type functionType, int argumentIndex) functionType = FunctionTypeUtils.discoverFunctionTypeFromClass(FunctionTypeUtils.getRawType(functionType)); } - var argumentType = functionType instanceof ParameterizedType + return functionType instanceof ParameterizedType ? ((ParameterizedType) functionType).getActualTypeArguments()[argumentIndex] : Object.class; - - return argumentType; } /** @@ -120,7 +120,8 @@ public static Type getFunctionArgumentType(Type functionType, int argumentIndex) * @return instance of {@link Class} as raw representation of the provided * {@link Type} */ - public static Class toRawClass(Type type) { + @Nullable + public static Class toRawClass(@Nullable Type type) { return type != null ? TypeResolver.resolveRawClass(type instanceof GenericArrayType ? type : TypeResolver.reify(type), null) : null; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/package-info.java new file mode 100644 index 0000000000..76de6e41c4 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for function calling components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.model.function; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelObservationContext.java b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelObservationContext.java index 0c0ac67671..535a58f785 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelObservationContext.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelObservationContext.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.observation; import io.micrometer.observation.Observation; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelUsageMetricsGenerator.java b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelUsageMetricsGenerator.java index dfd6e6c84e..bc87a6692f 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelUsageMetricsGenerator.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/ModelUsageMetricsGenerator.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.model.observation; import io.micrometer.common.KeyValue; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/package-info.java index 1d58177368..33f715d211 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/observation/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/observation/package-info.java @@ -1,19 +1,6 @@ -/* - * Copyright 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 for core model observation components. */ - @NonNullApi @NonNullFields package org.springframework.ai.model.observation; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/model/package-info.java index 57c2b34db7..97ec0b74fb 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/package-info.java @@ -1,18 +1,3 @@ -/* - * 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. - */ /** * Provides a set of interfaces and classes for a generic API designed to interact with * various AI models. This package includes interfaces for handling AI model calls, @@ -23,4 +8,9 @@ * ensuring a broad applicability across diverse AI scenarios. * */ -package org.springframework.ai.model; \ No newline at end of file +@NonNullApi +@NonNullFields +package org.springframework.ai.model; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/moderation/Categories.java b/spring-ai-core/src/main/java/org/springframework/ai/moderation/Categories.java index 3a170028e5..41dd99cc4d 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/moderation/Categories.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/moderation/Categories.java @@ -12,27 +12,27 @@ */ public class Categories { - private boolean sexual; + private final boolean sexual; - private boolean hate; + private final boolean hate; - private boolean harassment; + private final boolean harassment; - private boolean selfHarm; + private final boolean selfHarm; - private boolean sexualMinors; + private final boolean sexualMinors; - private boolean hateThreatening; + private final boolean hateThreatening; - private boolean violenceGraphic; + private final boolean violenceGraphic; - private boolean selfHarmIntent; + private final boolean selfHarmIntent; - private boolean selfHarmInstructions; + private final boolean selfHarmInstructions; - private boolean harassmentThreatening; + private final boolean harassmentThreatening; - private boolean violence; + private final boolean violence; private Categories(Builder builder) { this.sexual = builder.sexual; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/moderation/CategoryScores.java b/spring-ai-core/src/main/java/org/springframework/ai/moderation/CategoryScores.java index 8429b78347..1cc8d996c2 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/moderation/CategoryScores.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/moderation/CategoryScores.java @@ -12,27 +12,27 @@ */ public class CategoryScores { - private double sexual; + private final double sexual; - private double hate; + private final double hate; - private double harassment; + private final double harassment; - private double selfHarm; + private final double selfHarm; - private double sexualMinors; + private final double sexualMinors; - private double hateThreatening; + private final double hateThreatening; - private double violenceGraphic; + private final double violenceGraphic; - private double selfHarmIntent; + private final double selfHarmIntent; - private double selfHarmInstructions; + private final double selfHarmInstructions; - private double harassmentThreatening; + private final double harassmentThreatening; - private double violence; + private final double violence; private CategoryScores(Builder builder) { this.sexual = builder.sexual; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/moderation/Generation.java b/spring-ai-core/src/main/java/org/springframework/ai/moderation/Generation.java index 98a4cf5fd4..1ce4f835f8 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/moderation/Generation.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/moderation/Generation.java @@ -28,8 +28,10 @@ */ public class Generation implements ModelResult { + @Nullable private ModerationGenerationMetadata moderationGenerationMetadata; + @Nullable private Moderation moderation; public Generation() { @@ -51,11 +53,13 @@ public Generation withGenerationMetadata(@Nullable ModerationGenerationMetadata } @Override + @Nullable public Moderation getOutput() { return moderation; } @Override + @Nullable public ModerationGenerationMetadata getMetadata() { return moderationGenerationMetadata; } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/moderation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/moderation/package-info.java new file mode 100644 index 0000000000..c09bf447e8 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/moderation/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for moderation components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.moderation; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/observation/conventions/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/observation/conventions/package-info.java index 53f533019b..8168db1f38 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/observation/conventions/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/observation/conventions/package-info.java @@ -1,17 +1,5 @@ -/* - * Copyright 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 for core observation convention components. */ @NonNullApi diff --git a/spring-ai-core/src/main/java/org/springframework/ai/observation/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/observation/package-info.java index 1ef4dfd324..86ffb75da0 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/observation/package-info.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/observation/package-info.java @@ -1,19 +1,6 @@ -/* - * Copyright 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 for core observation components. */ - @NonNullApi @NonNullFields package org.springframework.ai.observation; diff --git a/spring-ai-core/src/main/java/org/springframework/ai/observation/tracing/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/observation/tracing/package-info.java new file mode 100644 index 0000000000..93407b4584 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/observation/tracing/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core observation tracing components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.observation.tracing; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/package-info.java new file mode 100644 index 0000000000..1e231e440a --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/parser/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/parser/package-info.java new file mode 100644 index 0000000000..c06b389584 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/parser/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core parser components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.parser; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/reader/ExtractedTextFormatter.java b/spring-ai-core/src/main/java/org/springframework/ai/reader/ExtractedTextFormatter.java index 03669f1b74..f64d520032 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/reader/ExtractedTextFormatter.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/reader/ExtractedTextFormatter.java @@ -35,16 +35,16 @@ public class ExtractedTextFormatter { /** Flag indicating if the text should be left-aligned */ - private boolean leftAlignment; + private final boolean leftAlignment; /** Number of top pages to skip before performing delete operations */ - private int numberOfTopPagesToSkipBeforeDelete; + private final int numberOfTopPagesToSkipBeforeDelete; /** Number of top text lines to delete from a page */ - private int numberOfTopTextLinesToDelete; + private final int numberOfTopTextLinesToDelete; /** Number of bottom text lines to delete from a page */ - private int numberOfBottomTextLinesToDelete; + private final int numberOfBottomTextLinesToDelete; /** * Private constructor to initialize the formatter from the builder. diff --git a/spring-ai-core/src/main/java/org/springframework/ai/reader/JsonReader.java b/spring-ai-core/src/main/java/org/springframework/ai/reader/JsonReader.java index 4c730adf0a..a051b5eda3 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/reader/JsonReader.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/reader/JsonReader.java @@ -42,16 +42,16 @@ */ public class JsonReader implements DocumentReader { - private Resource resource; + private final Resource resource; - private JsonMetadataGenerator jsonMetadataGenerator; + private final JsonMetadataGenerator jsonMetadataGenerator; private final ObjectMapper objectMapper = new ObjectMapper(); /** * The key from the JSON that we will use as the text to parse into the Document text */ - private List jsonKeysToUse; + private final List jsonKeysToUse; public JsonReader(Resource resource) { this(resource, new ArrayList<>().toArray(new String[0])); diff --git a/spring-ai-core/src/main/java/org/springframework/ai/reader/TextReader.java b/spring-ai-core/src/main/java/org/springframework/ai/reader/TextReader.java index becedabfd9..0d2ca10841 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/reader/TextReader.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/reader/TextReader.java @@ -49,7 +49,7 @@ public class TextReader implements DocumentReader { */ private Charset charset = StandardCharsets.UTF_8; - private Map customMetadata = new HashMap<>(); + private final Map customMetadata = new HashMap<>(); public TextReader(String resourceUrl) { this(new DefaultResourceLoader().getResource(resourceUrl)); diff --git a/spring-ai-core/src/main/java/org/springframework/ai/reader/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/reader/package-info.java new file mode 100644 index 0000000000..ab8d039fae --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/reader/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core reader components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.reader; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/JTokkitTokenCountEstimator.java b/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/JTokkitTokenCountEstimator.java index 8a1dc60aa0..d968f5a8f7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/JTokkitTokenCountEstimator.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/JTokkitTokenCountEstimator.java @@ -22,6 +22,7 @@ import org.springframework.ai.model.Media; import org.springframework.ai.model.MediaContent; +import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -45,7 +46,7 @@ public JTokkitTokenCountEstimator(EncodingType tokenEncodingType) { } @Override - public int estimate(String text) { + public int estimate(@Nullable String text) { if (text == null) { return 0; } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/package-info.java new file mode 100644 index 0000000000..22ef915502 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/tokenizer/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core tokenizer components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.tokenizer; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/transformer/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/transformer/package-info.java new file mode 100644 index 0000000000..e97321d821 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/transformer/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core transformer components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.transformer; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/transformer/splitter/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/transformer/splitter/package-info.java new file mode 100644 index 0000000000..ecddebd118 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/transformer/splitter/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core splitter components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.transformer.splitter; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/util/api/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/util/api/package-info.java new file mode 100644 index 0000000000..f947e1982d --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/util/api/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for api utils. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.util.api; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/util/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/util/package-info.java new file mode 100644 index 0000000000..2b7f7431cb --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/util/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core utilities. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.util; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SearchRequest.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SearchRequest.java index b430793cdd..4882763648 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SearchRequest.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SearchRequest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 - 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. @@ -13,12 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.ai.vectorstore; import org.springframework.ai.document.Document; import org.springframework.ai.vectorstore.filter.Filter; import org.springframework.ai.vectorstore.filter.FilterExpressionBuilder; import org.springframework.ai.vectorstore.filter.FilterExpressionTextParser; +import org.springframework.lang.Nullable; import org.springframework.util.Assert; import java.util.Objects; @@ -50,6 +52,7 @@ public class SearchRequest { private double similarityThreshold = SIMILARITY_THRESHOLD_ACCEPT_ALL; + @Nullable private Filter.Expression filterExpression; private SearchRequest(String query) { @@ -185,7 +188,7 @@ public SearchRequest withSimilarityThresholdAll() { * filter criteria. The 'null' value stands for no expression filters. * @return this builder. */ - public SearchRequest withFilterExpression(Filter.Expression expression) { + public SearchRequest withFilterExpression(@Nullable Filter.Expression expression) { this.filterExpression = expression; return this; } @@ -224,26 +227,27 @@ public SearchRequest withFilterExpression(Filter.Expression expression) { * 'null' value stands for no expression filters. * @return this.builder */ - public SearchRequest withFilterExpression(String textExpression) { + public SearchRequest withFilterExpression(@Nullable String textExpression) { this.filterExpression = (textExpression != null) ? new FilterExpressionTextParser().parse(textExpression) : null; return this; } public String getQuery() { - return query; + return this.query; } public int getTopK() { - return topK; + return this.topK; } public double getSimilarityThreshold() { - return similarityThreshold; + return this.similarityThreshold; } + @Nullable public Filter.Expression getFilterExpression() { - return filterExpression; + return this.filterExpression; } public boolean hasFilterExpression() { @@ -252,8 +256,8 @@ public boolean hasFilterExpression() { @Override public String toString() { - return "SearchRequest{" + "query='" + query + '\'' + ", topK=" + topK + ", similarityThreshold=" - + similarityThreshold + ", filterExpression=" + filterExpression + '}'; + return "SearchRequest{" + "query='" + this.query + '\'' + ", topK=" + this.topK + ", similarityThreshold=" + + this.similarityThreshold + ", filterExpression=" + this.filterExpression + '}'; } @Override @@ -263,13 +267,14 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SearchRequest that = (SearchRequest) o; - return topK == that.topK && Double.compare(that.similarityThreshold, similarityThreshold) == 0 - && Objects.equals(query, that.query) && Objects.equals(filterExpression, that.filterExpression); + return this.topK == that.topK && Double.compare(that.similarityThreshold, this.similarityThreshold) == 0 + && Objects.equals(this.query, that.query) + && Objects.equals(this.filterExpression, that.filterExpression); } @Override public int hashCode() { - return Objects.hash(query, topK, similarityThreshold, filterExpression); + return Objects.hash(this.query, this.topK, this.similarityThreshold, this.filterExpression); } } \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java index 338327e819..d2bd69f005 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/SimpleVectorStore.java @@ -42,6 +42,7 @@ import org.springframework.ai.vectorstore.observation.VectorStoreObservationContext; import org.springframework.ai.vectorstore.observation.VectorStoreObservationConvention; import org.springframework.core.io.Resource; +import org.springframework.lang.Nullable; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; @@ -174,8 +175,7 @@ public void load(File file) { }; ObjectMapper objectMapper = new ObjectMapper(); try { - Map deserializedMap = objectMapper.readValue(file, typeRef); - this.store = deserializedMap; + this.store = objectMapper.readValue(file, typeRef); } catch (IOException ex) { throw new RuntimeException(ex); @@ -191,8 +191,7 @@ public void load(Resource resource) { }; ObjectMapper objectMapper = new ObjectMapper(); try { - Map deserializedMap = objectMapper.readValue(resource.getInputStream(), typeRef); - this.store = deserializedMap; + this.store = objectMapper.readValue(resource.getInputStream(), typeRef); } catch (IOException ex) { throw new RuntimeException(ex); @@ -218,9 +217,9 @@ private float[] getUserQueryEmbedding(String query) { public static class Similarity { - private String key; + private final String key; - private double score; + private final double score; public Similarity(String key, double score) { this.key = key; @@ -229,13 +228,13 @@ public Similarity(String key, double score) { } - public class EmbeddingMath { + public static class EmbeddingMath { private EmbeddingMath() { throw new UnsupportedOperationException("This is a utility class and cannot be instantiated"); } - public static double cosineSimilarity(float[] vectorX, float[] vectorY) { + public static double cosineSimilarity(@Nullable float[] vectorX, @Nullable float[] vectorY) { if (vectorX == null || vectorY == null) { throw new RuntimeException("Vectors must not be null"); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/VectorStore.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/VectorStore.java index dadcdda3b1..b2b8631f6a 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/VectorStore.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/VectorStore.java @@ -20,6 +20,7 @@ import org.springframework.ai.document.Document; import org.springframework.ai.document.DocumentWriter; +import org.springframework.lang.Nullable; /** * The {@code VectorStore} interface defines the operations for managing and querying @@ -52,6 +53,7 @@ default void accept(List documents) { * @param idList list of document ids for which documents will be removed. * @return */ + @Nullable Optional delete(List idList); /** @@ -61,6 +63,7 @@ default void accept(List documents) { * topK, similarity threshold and metadata filter expressions. * @return Returns documents th match the query request conditions. */ + @Nullable List similaritySearch(SearchRequest request); /** @@ -70,6 +73,7 @@ default void accept(List documents) { * @return Returns a list of documents that have embeddings similar to the query text * embedding. */ + @Nullable default List similaritySearch(String query) { return this.similaritySearch(SearchRequest.query(query)); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionConverter.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionConverter.java index 127f2dc927..7fb693956a 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionConverter.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/FilterExpressionConverter.java @@ -24,6 +24,6 @@ */ public interface FilterExpressionConverter { - public String convertExpression(Filter.Expression expression); + String convertExpression(Filter.Expression expression); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/package-info.java new file mode 100644 index 0000000000..6fb7707872 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/antlr4/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core vector store filter antlr components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.vectorstore.filter.antlr4; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/converter/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/converter/package-info.java new file mode 100644 index 0000000000..f70849408e --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/converter/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core vector store converter components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.vectorstore.filter.converter; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/package-info.java new file mode 100644 index 0000000000..c315abaf6f --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/filter/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core vector store filter components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.vectorstore.filter; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/observation/AbstractObservationVectorStore.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/observation/AbstractObservationVectorStore.java index ee4e98a6bc..5441a48de7 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/observation/AbstractObservationVectorStore.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/observation/AbstractObservationVectorStore.java @@ -58,6 +58,7 @@ public void add(List documents) { } @Override + @Nullable public Optional delete(List deleteDocIds) { VectorStoreObservationContext observationContext = this @@ -71,6 +72,7 @@ public Optional delete(List deleteDocIds) { } @Override + @Nullable public List similaritySearch(SearchRequest request) { VectorStoreObservationContext searchObservationContext = this diff --git a/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/package-info.java new file mode 100644 index 0000000000..122ff9f450 --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/vectorstore/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core vector store components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.vectorstore; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file diff --git a/spring-ai-core/src/main/java/org/springframework/ai/writer/package-info.java b/spring-ai-core/src/main/java/org/springframework/ai/writer/package-info.java new file mode 100644 index 0000000000..a80898ba8e --- /dev/null +++ b/spring-ai-core/src/main/java/org/springframework/ai/writer/package-info.java @@ -0,0 +1,9 @@ +/** + * Package for core writer components. + */ +@NonNullApi +@NonNullFields +package org.springframework.ai.writer; + +import org.springframework.lang.NonNullApi; +import org.springframework.lang.NonNullFields; \ No newline at end of file