diff --git a/langchain4j-azure-open-ai-spring-boot-starter/pom.xml b/langchain4j-azure-open-ai-spring-boot-starter/pom.xml index f08c4dc..f642244 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/pom.xml +++ b/langchain4j-azure-open-ai-spring-boot-starter/pom.xml @@ -34,13 +34,6 @@ true - - - org.projectlombok - lombok - provided - - org.springframework.boot diff --git a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/AutoConfig.java b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/AutoConfig.java index 1515fb6..6d96d79 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/AutoConfig.java +++ b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/AutoConfig.java @@ -30,30 +30,30 @@ AzureOpenAiChatModel openAiChatModelByNonAzureApiKey(Properties properties) { } AzureOpenAiChatModel openAiChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getChatModel(); + ChatModelProperties chatModelProperties = properties.chatModel(); AzureOpenAiChatModel.Builder builder = AzureOpenAiChatModel.builder() - .endpoint(chatModelProperties.getEndpoint()) - .serviceVersion(chatModelProperties.getServiceVersion()) - .apiKey(chatModelProperties.getApiKey()) - .deploymentName(chatModelProperties.getDeploymentName()) + .endpoint(chatModelProperties.endpoint()) + .serviceVersion(chatModelProperties.serviceVersion()) + .apiKey(chatModelProperties.apiKey()) + .deploymentName(chatModelProperties.deploymentName()) // TODO inject tokenizer? - .maxTokens(chatModelProperties.getMaxTokens()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .logitBias(chatModelProperties.getLogitBias()) - .user(chatModelProperties.getUser()) - .stop(chatModelProperties.getStop()) - .presencePenalty(chatModelProperties.getPresencePenalty()) - .frequencyPenalty(chatModelProperties.getFrequencyPenalty()) - .seed(chatModelProperties.getSeed()) - .timeout(Duration.ofSeconds(chatModelProperties.getTimeout() == null ? 0 : chatModelProperties.getTimeout())) - .maxRetries(chatModelProperties.getMaxRetries()) + .maxTokens(chatModelProperties.maxTokens()) + .temperature(chatModelProperties.temperature()) + .topP(chatModelProperties.topP()) + .logitBias(chatModelProperties.logitBias()) + .user(chatModelProperties.user()) + .stop(chatModelProperties.stop()) + .presencePenalty(chatModelProperties.presencePenalty()) + .frequencyPenalty(chatModelProperties.frequencyPenalty()) + .seed(chatModelProperties.seed()) + .timeout(Duration.ofSeconds(chatModelProperties.timeout() == null ? 0 : chatModelProperties.timeout())) + .maxRetries(chatModelProperties.maxRetries()) .proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration())) - .logRequestsAndResponses(chatModelProperties.getLogRequestsAndResponses() != null && chatModelProperties.getLogRequestsAndResponses()) - .userAgentSuffix(chatModelProperties.getUserAgentSuffix()) - .customHeaders(chatModelProperties.getCustomHeaders()); - if (chatModelProperties.getNonAzureApiKey() != null) { - builder.nonAzureApiKey(chatModelProperties.getNonAzureApiKey()); + .logRequestsAndResponses(chatModelProperties.logRequestsAndResponses() != null && chatModelProperties.logRequestsAndResponses()) + .userAgentSuffix(chatModelProperties.userAgentSuffix()) + .customHeaders(chatModelProperties.customHeaders()); + if (chatModelProperties.nonAzureApiKey() != null) { + builder.nonAzureApiKey(chatModelProperties.nonAzureApiKey()); } return builder.build(); } @@ -71,30 +71,30 @@ AzureOpenAiStreamingChatModel openAiStreamingChatModelByNonAzureApiKey(Propertie } AzureOpenAiStreamingChatModel openAiStreamingChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getStreamingChatModel(); + ChatModelProperties chatModelProperties = properties.streamingChatModel(); AzureOpenAiStreamingChatModel.Builder builder = AzureOpenAiStreamingChatModel.builder() - .endpoint(chatModelProperties.getEndpoint()) - .serviceVersion(chatModelProperties.getServiceVersion()) - .apiKey(chatModelProperties.getApiKey()) - .deploymentName(chatModelProperties.getDeploymentName()) + .endpoint(chatModelProperties.endpoint()) + .serviceVersion(chatModelProperties.serviceVersion()) + .apiKey(chatModelProperties.apiKey()) + .deploymentName(chatModelProperties.deploymentName()) // TODO inject tokenizer? - .maxTokens(chatModelProperties.getMaxTokens()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .logitBias(chatModelProperties.getLogitBias()) - .user(chatModelProperties.getUser()) - .stop(chatModelProperties.getStop()) - .presencePenalty(chatModelProperties.getPresencePenalty()) - .frequencyPenalty(chatModelProperties.getFrequencyPenalty()) - .seed(chatModelProperties.getSeed()) - .timeout(Duration.ofSeconds(chatModelProperties.getTimeout() == null ? 0 : chatModelProperties.getTimeout())) - .maxRetries(chatModelProperties.getMaxRetries()) + .maxTokens(chatModelProperties.maxTokens()) + .temperature(chatModelProperties.temperature()) + .topP(chatModelProperties.topP()) + .logitBias(chatModelProperties.logitBias()) + .user(chatModelProperties.user()) + .stop(chatModelProperties.stop()) + .presencePenalty(chatModelProperties.presencePenalty()) + .frequencyPenalty(chatModelProperties.frequencyPenalty()) + .seed(chatModelProperties.seed()) + .timeout(Duration.ofSeconds(chatModelProperties.timeout() == null ? 0 : chatModelProperties.timeout())) + .maxRetries(chatModelProperties.maxRetries()) .proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration())) - .logRequestsAndResponses(chatModelProperties.getLogRequestsAndResponses() != null && chatModelProperties.getLogRequestsAndResponses()) - .userAgentSuffix(chatModelProperties.getUserAgentSuffix()) - .customHeaders(chatModelProperties.getCustomHeaders()); - if (chatModelProperties.getNonAzureApiKey() != null) { - builder.nonAzureApiKey(chatModelProperties.getNonAzureApiKey()); + .logRequestsAndResponses(chatModelProperties.logRequestsAndResponses() != null && chatModelProperties.logRequestsAndResponses()) + .userAgentSuffix(chatModelProperties.userAgentSuffix()) + .customHeaders(chatModelProperties.customHeaders()); + if (chatModelProperties.nonAzureApiKey() != null) { + builder.nonAzureApiKey(chatModelProperties.nonAzureApiKey()); } return builder.build(); } @@ -112,22 +112,22 @@ AzureOpenAiEmbeddingModel openAiEmbeddingModelByNonAzureApiKey(Properties proper } AzureOpenAiEmbeddingModel openAiEmbeddingModel(Properties properties, Tokenizer tokenizer) { - EmbeddingModelProperties embeddingModelProperties = properties.getEmbeddingModel(); + EmbeddingModelProperties embeddingModelProperties = properties.embeddingModel(); AzureOpenAiEmbeddingModel.Builder builder = AzureOpenAiEmbeddingModel.builder() - .endpoint(embeddingModelProperties.getEndpoint()) - .serviceVersion(embeddingModelProperties.getServiceVersion()) - .apiKey(embeddingModelProperties.getApiKey()) - .deploymentName(embeddingModelProperties.getDeploymentName()) + .endpoint(embeddingModelProperties.endpoint()) + .serviceVersion(embeddingModelProperties.serviceVersion()) + .apiKey(embeddingModelProperties.apiKey()) + .deploymentName(embeddingModelProperties.deploymentName()) .tokenizer(tokenizer) - .timeout(Duration.ofSeconds(embeddingModelProperties.getTimeout() == null ? 0 : embeddingModelProperties.getTimeout())) - .maxRetries(embeddingModelProperties.getMaxRetries()) + .timeout(Duration.ofSeconds(embeddingModelProperties.timeout() == null ? 0 : embeddingModelProperties.timeout())) + .maxRetries(embeddingModelProperties.maxRetries()) .proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration())) - .logRequestsAndResponses(embeddingModelProperties.getLogRequestsAndResponses() != null && embeddingModelProperties.getLogRequestsAndResponses()) - .userAgentSuffix(embeddingModelProperties.getUserAgentSuffix()) - .dimensions(embeddingModelProperties.getDimensions()) - .customHeaders(embeddingModelProperties.getCustomHeaders()); - if (embeddingModelProperties.getNonAzureApiKey() != null) { - builder.nonAzureApiKey(embeddingModelProperties.getNonAzureApiKey()); + .logRequestsAndResponses(embeddingModelProperties.logRequestsAndResponses() != null && embeddingModelProperties.logRequestsAndResponses()) + .userAgentSuffix(embeddingModelProperties.userAgentSuffix()) + .dimensions(embeddingModelProperties.dimensions()) + .customHeaders(embeddingModelProperties.customHeaders()); + if (embeddingModelProperties.nonAzureApiKey() != null) { + builder.nonAzureApiKey(embeddingModelProperties.nonAzureApiKey()); } return builder.build(); } @@ -145,25 +145,25 @@ AzureOpenAiImageModel openAiImageModelByNonAzureApiKey(Properties properties) { } AzureOpenAiImageModel openAiImageModel(Properties properties) { - ImageModelProperties imageModelProperties = properties.getImageModel(); + ImageModelProperties imageModelProperties = properties.imageModel(); AzureOpenAiImageModel.Builder builder = AzureOpenAiImageModel.builder() - .endpoint(imageModelProperties.getEndpoint()) - .serviceVersion(imageModelProperties.getServiceVersion()) - .apiKey(imageModelProperties.getApiKey()) - .deploymentName(imageModelProperties.getDeploymentName()) - .quality(imageModelProperties.getQuality()) - .size(imageModelProperties.getSize()) - .user(imageModelProperties.getUser()) - .style(imageModelProperties.getStyle()) - .responseFormat(imageModelProperties.getResponseFormat()) - .timeout(imageModelProperties.getTimeout() == null ? null : Duration.ofSeconds(imageModelProperties.getTimeout())) - .maxRetries(imageModelProperties.getMaxRetries()) + .endpoint(imageModelProperties.endpoint()) + .serviceVersion(imageModelProperties.serviceVersion()) + .apiKey(imageModelProperties.apiKey()) + .deploymentName(imageModelProperties.deploymentName()) + .quality(imageModelProperties.quality()) + .size(imageModelProperties.size()) + .user(imageModelProperties.user()) + .style(imageModelProperties.style()) + .responseFormat(imageModelProperties.responseFormat()) + .timeout(imageModelProperties.timeout() == null ? null : Duration.ofSeconds(imageModelProperties.timeout())) + .maxRetries(imageModelProperties.maxRetries()) .proxyOptions(ProxyOptions.fromConfiguration(Configuration.getGlobalConfiguration())) - .logRequestsAndResponses(imageModelProperties.getLogRequestsAndResponses() != null && imageModelProperties.getLogRequestsAndResponses()) - .userAgentSuffix(imageModelProperties.getUserAgentSuffix()) - .customHeaders(imageModelProperties.getCustomHeaders()); - if (imageModelProperties.getNonAzureApiKey() != null) { - builder.nonAzureApiKey(imageModelProperties.getNonAzureApiKey()); + .logRequestsAndResponses(imageModelProperties.logRequestsAndResponses() != null && imageModelProperties.logRequestsAndResponses()) + .userAgentSuffix(imageModelProperties.userAgentSuffix()) + .customHeaders(imageModelProperties.customHeaders()); + if (imageModelProperties.nonAzureApiKey() != null) { + builder.nonAzureApiKey(imageModelProperties.nonAzureApiKey()); } return builder.build(); } diff --git a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ChatModelProperties.java b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ChatModelProperties.java index 4535e47..5835406 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ChatModelProperties.java +++ b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ChatModelProperties.java @@ -1,33 +1,29 @@ package dev.langchain4j.azure.openai.spring; -import lombok.Getter; -import lombok.Setter; - import java.util.List; import java.util.Map; -@Getter -@Setter -class ChatModelProperties { +record ChatModelProperties( - String endpoint; - String serviceVersion; - String apiKey; - String deploymentName; - Integer maxTokens; - Double temperature; - Double topP; - Map logitBias; - String user; - List stop; - Double presencePenalty; - Double frequencyPenalty; - Long seed; - String responseFormat; - Integer timeout; // TODO use Duration instead - Integer maxRetries; - Boolean logRequestsAndResponses; - String userAgentSuffix; - Map customHeaders; - String nonAzureApiKey; + String endpoint, + String serviceVersion, + String apiKey, + String deploymentName, + Integer maxTokens, + Double temperature, + Double topP, + Map logitBias, + String user, + List stop, + Double presencePenalty, + Double frequencyPenalty, + Long seed, + String responseFormat, + Integer timeout, // TODO use Duration instead + Integer maxRetries, + Boolean logRequestsAndResponses, + String userAgentSuffix, + Map customHeaders, + String nonAzureApiKey +) { } \ No newline at end of file diff --git a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/EmbeddingModelProperties.java b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/EmbeddingModelProperties.java index 7522e95..daea633 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/EmbeddingModelProperties.java +++ b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/EmbeddingModelProperties.java @@ -1,23 +1,19 @@ package dev.langchain4j.azure.openai.spring; -import lombok.Getter; -import lombok.Setter; - import java.util.Map; -@Getter -@Setter -class EmbeddingModelProperties { +record EmbeddingModelProperties( - String endpoint; - String serviceVersion; - String apiKey; - String deploymentName; - Integer timeout; // TODO use duration instead - Integer maxRetries; - Boolean logRequestsAndResponses; - String userAgentSuffix; - Integer dimensions; - Map customHeaders; - String nonAzureApiKey; + String endpoint, + String serviceVersion, + String apiKey, + String deploymentName, + Integer timeout, // TODO use duration instead + Integer maxRetries, + Boolean logRequestsAndResponses, + String userAgentSuffix, + Integer dimensions, + Map customHeaders, + String nonAzureApiKey +) { } \ No newline at end of file diff --git a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ImageModelProperties.java b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ImageModelProperties.java index aadfcf3..a7299a6 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ImageModelProperties.java +++ b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/ImageModelProperties.java @@ -1,27 +1,23 @@ package dev.langchain4j.azure.openai.spring; -import lombok.Getter; -import lombok.Setter; - import java.util.Map; -@Getter -@Setter -class ImageModelProperties { +record ImageModelProperties( - String endpoint; - String serviceVersion; - String apiKey; - String deploymentName; - String quality; - String size; - String user; - String style; - String responseFormat; - Integer timeout; - Integer maxRetries; - Boolean logRequestsAndResponses; - String userAgentSuffix; - Map customHeaders; - String nonAzureApiKey; + String endpoint, + String serviceVersion, + String apiKey, + String deploymentName, + String quality, + String size, + String user, + String style, + String responseFormat, + Integer timeout, + Integer maxRetries, + Boolean logRequestsAndResponses, + String userAgentSuffix, + Map customHeaders, + String nonAzureApiKey +){ } \ No newline at end of file diff --git a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/Properties.java b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/Properties.java index da11552..c0e350b 100644 --- a/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/Properties.java +++ b/langchain4j-azure-open-ai-spring-boot-starter/src/main/java/dev/langchain4j/azure/openai/spring/Properties.java @@ -1,26 +1,22 @@ package dev.langchain4j.azure.openai.spring; -import lombok.Getter; -import lombok.Setter; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.NestedConfigurationProperty; -@Getter -@Setter @ConfigurationProperties(prefix = Properties.PREFIX) -public class Properties { - - static final String PREFIX = "langchain4j.azure-open-ai"; +public record Properties( @NestedConfigurationProperty - ChatModelProperties chatModel; + ChatModelProperties chatModel, @NestedConfigurationProperty - ChatModelProperties streamingChatModel; + ChatModelProperties streamingChatModel, @NestedConfigurationProperty - EmbeddingModelProperties embeddingModel; + EmbeddingModelProperties embeddingModel, @NestedConfigurationProperty - ImageModelProperties imageModel; + ImageModelProperties imageModel +) { + static final String PREFIX = "langchain4j.azure-open-ai"; }