From 3827ca7b482125f865bf42a88df8646e8656acf4 Mon Sep 17 00:00:00 2001 From: Martin7-1 Date: Mon, 23 Dec 2024 02:30:49 +0800 Subject: [PATCH 1/2] remove dashscope and qianfan spring boot starter --- .../pom.xml | 67 ------- .../dashscope/spring/AutoConfig.java | 113 ------------ .../dashscope/spring/ChatModelProperties.java | 23 --- .../spring/EmbeddingModelProperties.java | 12 -- .../spring/LanguageModelProperties.java | 23 --- .../dashscope/spring/Properties.java | 32 ---- .../dashscope/spring/TokenizerProperties.java | 11 -- ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../dashscope/spring/AutoConfigIT.java | 146 ---------------- .../pom.xml | 61 ------- .../qianfan/spring/AutoConfig.java | 110 ------------ .../qianfan/spring/ChatModelProperties.java | 26 --- .../spring/EmbeddingModelProperties.java | 22 --- .../spring/LanguageModelProperties.java | 25 --- .../qianfan/spring/Properties.java | 29 ---- ...ot.autoconfigure.AutoConfiguration.imports | 1 - .../qianfan/spring/AutoConfigIT.java | 163 ------------------ pom.xml | 2 - 18 files changed, 867 deletions(-) delete mode 100644 langchain4j-dashscope-spring-boot-starter/pom.xml delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/AutoConfig.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/ChatModelProperties.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/EmbeddingModelProperties.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/LanguageModelProperties.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/Properties.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/TokenizerProperties.java delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 langchain4j-dashscope-spring-boot-starter/src/test/java/dev/langchain4j/dashscope/spring/AutoConfigIT.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/pom.xml delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/AutoConfig.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/ChatModelProperties.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/EmbeddingModelProperties.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/LanguageModelProperties.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/Properties.java delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports delete mode 100644 langchain4j-qianfan-spring-boot-starter/src/test/java/dev/langchain4j/qianfan/spring/AutoConfigIT.java diff --git a/langchain4j-dashscope-spring-boot-starter/pom.xml b/langchain4j-dashscope-spring-boot-starter/pom.xml deleted file mode 100644 index de20f75b..00000000 --- a/langchain4j-dashscope-spring-boot-starter/pom.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - 4.0.0 - - - dev.langchain4j - langchain4j-spring - 1.0.0-alpha1 - ../pom.xml - - - langchain4j-dashscope-spring-boot-starter - LangChain4j Spring Boot starter for DashScope - - - - - dev.langchain4j - langchain4j-dashscope - ${project.version} - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-autoconfigure-processor - true - - - - - org.projectlombok - lombok - provided - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - Apache-2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - - - diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/AutoConfig.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/AutoConfig.java deleted file mode 100644 index 98eb1c7f..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/AutoConfig.java +++ /dev/null @@ -1,113 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import dev.langchain4j.model.dashscope.*; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; - -@AutoConfiguration -@EnableConfigurationProperties(Properties.class) -public class AutoConfig { - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".chat-model.api-key") - QwenChatModel qwenChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getChatModel(); - return QwenChatModel.builder() - .baseUrl(chatModelProperties.getBaseUrl()) - .apiKey(chatModelProperties.getApiKey()) - .modelName(chatModelProperties.getModelName()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .topK(chatModelProperties.getTopK()) - .enableSearch(chatModelProperties.getEnableSearch()) - .seed(chatModelProperties.getSeed()) - .repetitionPenalty(chatModelProperties.getRepetitionPenalty()) - .temperature(chatModelProperties.getTemperature()) - .stops(chatModelProperties.getStops()) - .maxTokens(chatModelProperties.getMaxTokens()) - .build(); - } - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".streaming-chat-model.api-key") - QwenStreamingChatModel qwenStreamingChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getStreamingChatModel(); - return QwenStreamingChatModel.builder() - .baseUrl(chatModelProperties.getBaseUrl()) - .apiKey(chatModelProperties.getApiKey()) - .modelName(chatModelProperties.getModelName()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .topK(chatModelProperties.getTopK()) - .enableSearch(chatModelProperties.getEnableSearch()) - .seed(chatModelProperties.getSeed()) - .repetitionPenalty(chatModelProperties.getRepetitionPenalty()) - .temperature(chatModelProperties.getTemperature()) - .stops(chatModelProperties.getStops()) - .maxTokens(chatModelProperties.getMaxTokens()) - .build(); - } - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".language-model.api-key") - QwenLanguageModel qwenLanguageModel(Properties properties) { - LanguageModelProperties languageModelProperties = properties.getLanguageModel(); - return QwenLanguageModel.builder() - .baseUrl(languageModelProperties.getBaseUrl()) - .apiKey(languageModelProperties.getApiKey()) - .modelName(languageModelProperties.getModelName()) - .temperature(languageModelProperties.getTemperature()) - .topP(languageModelProperties.getTopP()) - .topK(languageModelProperties.getTopK()) - .enableSearch(languageModelProperties.getEnableSearch()) - .seed(languageModelProperties.getSeed()) - .repetitionPenalty(languageModelProperties.getRepetitionPenalty()) - .temperature(languageModelProperties.getTemperature()) - .stops(languageModelProperties.getStops()) - .maxTokens(languageModelProperties.getMaxTokens()) - .build(); - } - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".streaming-language-model.api-key") - QwenStreamingLanguageModel qwenStreamingLanguageModel(Properties properties) { - LanguageModelProperties languageModelProperties = properties.getStreamingLanguageModel(); - return QwenStreamingLanguageModel.builder() - .baseUrl(languageModelProperties.getBaseUrl()) - .apiKey(languageModelProperties.getApiKey()) - .modelName(languageModelProperties.getModelName()) - .temperature(languageModelProperties.getTemperature()) - .topP(languageModelProperties.getTopP()) - .topK(languageModelProperties.getTopK()) - .enableSearch(languageModelProperties.getEnableSearch()) - .seed(languageModelProperties.getSeed()) - .repetitionPenalty(languageModelProperties.getRepetitionPenalty()) - .temperature(languageModelProperties.getTemperature()) - .stops(languageModelProperties.getStops()) - .maxTokens(languageModelProperties.getMaxTokens()) - .build(); - } - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".embedding-model.api-key") - QwenEmbeddingModel qwenEmbeddingModel(Properties properties) { - EmbeddingModelProperties embeddingModelProperties = properties.getEmbeddingModel(); - return QwenEmbeddingModel.builder() - .baseUrl(embeddingModelProperties.getBaseUrl()) - .apiKey(embeddingModelProperties.getApiKey()) - .modelName(embeddingModelProperties.getModelName()) - .build(); - } - - @Bean - @ConditionalOnProperty(Properties.PREFIX + ".tokenizer.api-key") - QwenTokenizer qwenTokenizer(Properties properties) { - TokenizerProperties tokenizerProperties = properties.getTokenizer(); - return QwenTokenizer.builder() - .apiKey(tokenizerProperties.getApiKey()) - .modelName(tokenizerProperties.getModelName()) - .build(); - } -} \ No newline at end of file diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/ChatModelProperties.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/ChatModelProperties.java deleted file mode 100644 index a5d1d0da..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/ChatModelProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -class ChatModelProperties { - - private String baseUrl; - private String apiKey; - private String modelName; - private Double topP; - private Integer topK; - private Boolean enableSearch; - private Integer seed; - private Float repetitionPenalty; - private Float temperature; - private List stops; - private Integer maxTokens; -} \ No newline at end of file diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/EmbeddingModelProperties.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/EmbeddingModelProperties.java deleted file mode 100644 index 095430bf..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/EmbeddingModelProperties.java +++ /dev/null @@ -1,12 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -class EmbeddingModelProperties { - private String baseUrl; - private String apiKey; - private String modelName; -} \ No newline at end of file diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/LanguageModelProperties.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/LanguageModelProperties.java deleted file mode 100644 index 994382ca..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/LanguageModelProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import lombok.Getter; -import lombok.Setter; - -import java.util.List; - -@Getter -@Setter -class LanguageModelProperties { - - private String baseUrl; - private String apiKey; - private String modelName; - private Double topP; - private Integer topK; - private Boolean enableSearch; - private Integer seed; - private Float repetitionPenalty; - private Float temperature; - private List stops; - private Integer maxTokens; -} \ No newline at end of file diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/Properties.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/Properties.java deleted file mode 100644 index 2e81b3c3..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/Properties.java +++ /dev/null @@ -1,32 +0,0 @@ -package dev.langchain4j.dashscope.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.dashscope"; - - @NestedConfigurationProperty - ChatModelProperties chatModel; - - @NestedConfigurationProperty - ChatModelProperties streamingChatModel; - - @NestedConfigurationProperty - LanguageModelProperties languageModel; - - @NestedConfigurationProperty - LanguageModelProperties streamingLanguageModel; - - @NestedConfigurationProperty - EmbeddingModelProperties embeddingModel; - - @NestedConfigurationProperty - TokenizerProperties tokenizer; -} diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/TokenizerProperties.java b/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/TokenizerProperties.java deleted file mode 100644 index 0d2ad8f8..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/java/dev/langchain4j/dashscope/spring/TokenizerProperties.java +++ /dev/null @@ -1,11 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import lombok.Getter; -import lombok.Setter; - -@Getter -@Setter -public class TokenizerProperties { - private String apiKey; - private String modelName; -} diff --git a/langchain4j-dashscope-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/langchain4j-dashscope-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 9914be73..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -dev.langchain4j.dashscope.spring.AutoConfig \ No newline at end of file diff --git a/langchain4j-dashscope-spring-boot-starter/src/test/java/dev/langchain4j/dashscope/spring/AutoConfigIT.java b/langchain4j-dashscope-spring-boot-starter/src/test/java/dev/langchain4j/dashscope/spring/AutoConfigIT.java deleted file mode 100644 index 1017b07e..00000000 --- a/langchain4j-dashscope-spring-boot-starter/src/test/java/dev/langchain4j/dashscope/spring/AutoConfigIT.java +++ /dev/null @@ -1,146 +0,0 @@ -package dev.langchain4j.dashscope.spring; - -import dev.langchain4j.data.message.AiMessage; -import dev.langchain4j.model.StreamingResponseHandler; -import dev.langchain4j.model.chat.ChatLanguageModel; -import dev.langchain4j.model.chat.StreamingChatLanguageModel; -import dev.langchain4j.model.dashscope.*; -import dev.langchain4j.model.embedding.EmbeddingModel; -import dev.langchain4j.model.language.LanguageModel; -import dev.langchain4j.model.language.StreamingLanguageModel; -import dev.langchain4j.model.output.Response; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import java.util.concurrent.CompletableFuture; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; - -@EnabledIfEnvironmentVariable(named = "DASHSCOPE_API_KEY", matches = ".+") -public class AutoConfigIT { - private static final String API_KEY = System.getenv("DASHSCOPE_API_KEY"); - private static final String CHAT_MODEL = QwenModelName.QWEN_MAX; - - ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AutoConfig.class)); - - @Test - void should_provide_chat_model() { - contextRunner - .withPropertyValues( - "langchain4j.dashscope.chat-model.api-key=" + API_KEY, - "langchain4j.dashscope.chat-model.model-name=" + CHAT_MODEL, - "langchain4j.dashscope.chat-model.max-tokens=20" - ) - .run(context -> { - ChatLanguageModel chatLanguageModel = context.getBean(ChatLanguageModel.class); - assertThat(chatLanguageModel).isInstanceOf(QwenChatModel.class); - assertThat(chatLanguageModel.generate("What is the capital of Germany?")).contains("Berlin"); - - assertThat(context.getBean(QwenChatModel.class)).isSameAs(chatLanguageModel); - }); - } - - @Test - void should_provide_streaming_chat_model() { - contextRunner - .withPropertyValues( - "langchain4j.dashscope.streaming-chat-model.api-key=" + API_KEY, - "langchain4j.dashscope.streaming-chat-model.model-name=" + CHAT_MODEL, - "langchain4j.dashscope.streaming-chat-model.max-tokens=20" - ) - .run(context -> { - - StreamingChatLanguageModel streamingChatLanguageModel = context.getBean(StreamingChatLanguageModel.class); - assertThat(streamingChatLanguageModel).isInstanceOf(QwenStreamingChatModel.class); - CompletableFuture> future = new CompletableFuture<>(); - streamingChatLanguageModel.generate("What is the capital of Germany?", new StreamingResponseHandler<>() { - - @Override - public void onNext(String token) { - } - - @Override - public void onComplete(Response response) { - future.complete(response); - } - - @Override - public void onError(Throwable error) { - } - }); - Response response = future.get(60, SECONDS); - assertThat(response.content().text()).contains("Berlin"); - - assertThat(context.getBean(QwenStreamingChatModel.class)).isSameAs(streamingChatLanguageModel); - }); - } - - @Test - void should_provide_language_model() { - contextRunner - .withPropertyValues( - "langchain4j.dashscope.language-model.api-key=" + API_KEY, - "langchain4j.dashscope.language-model.max-tokens=20" - ) - .run(context -> { - - LanguageModel languageModel = context.getBean(LanguageModel.class); - assertThat(languageModel).isInstanceOf(QwenLanguageModel.class); - assertThat(languageModel.generate("What is the capital of Germany?").content()).contains("Berlin"); - - assertThat(context.getBean(QwenLanguageModel.class)).isSameAs(languageModel); - }); - } - - @Test - void should_provide_streaming_language_model() { - contextRunner - .withPropertyValues( - "langchain4j.dashscope.streaming-language-model.api-key=" + API_KEY, - "langchain4j.dashscope.streaming-language-model.max-tokens=20" - ) - .run(context -> { - - StreamingLanguageModel streamingLanguageModel = context.getBean(StreamingLanguageModel.class); - assertThat(streamingLanguageModel).isInstanceOf(QwenStreamingLanguageModel.class); - CompletableFuture> future = new CompletableFuture<>(); - streamingLanguageModel.generate("What is the capital of Germany?", new StreamingResponseHandler<>() { - - @Override - public void onNext(String token) { - } - - @Override - public void onComplete(Response response) { - future.complete(response); - } - - @Override - public void onError(Throwable error) { - } - }); - Response response = future.get(60, SECONDS); - assertThat(response.content()).contains("Berlin"); - - assertThat(context.getBean(QwenStreamingLanguageModel.class)).isSameAs(streamingLanguageModel); - }); - } - - @Test - void should_provide_embedding_model() { - contextRunner - .withPropertyValues("langchain4j.dashscope.embedding-model.api-key=" + API_KEY) - .run(context -> { - - EmbeddingModel embeddingModel = context.getBean(EmbeddingModel.class); - assertThat(embeddingModel).isInstanceOf(QwenEmbeddingModel.class); - assertThat(embeddingModel.embed("hi").content().dimension()).isEqualTo(1536); - - assertThat(context.getBean(QwenEmbeddingModel.class)).isSameAs(embeddingModel); - }); - } -} diff --git a/langchain4j-qianfan-spring-boot-starter/pom.xml b/langchain4j-qianfan-spring-boot-starter/pom.xml deleted file mode 100644 index 8feca571..00000000 --- a/langchain4j-qianfan-spring-boot-starter/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - 4.0.0 - - dev.langchain4j - langchain4j-spring - 1.0.0-alpha1 - ../pom.xml - - - langchain4j-qianfan-spring-boot-starter - LangChain4j Spring Boot starter for Qianfan - - - dev.langchain4j - langchain4j-qianfan - ${project.version} - - - - org.springframework.boot - spring-boot-starter - - - - org.springframework.boot - spring-boot-autoconfigure-processor - true - - - - - org.projectlombok - lombok - provided - - - - - org.springframework.boot - spring-boot-configuration-processor - true - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - Apache-2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - repo - A business-friendly OSS license - - - \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/AutoConfig.java b/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/AutoConfig.java deleted file mode 100644 index 3d70c0ce..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/AutoConfig.java +++ /dev/null @@ -1,110 +0,0 @@ -package dev.langchain4j.qianfan.spring; - -import dev.langchain4j.model.qianfan.*; -import org.springframework.boot.autoconfigure.AutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; - -import static dev.langchain4j.qianfan.spring.Properties.PREFIX; - -@AutoConfiguration -@EnableConfigurationProperties(Properties.class) -public class AutoConfig { - - @Bean - @ConditionalOnProperty(PREFIX + ".chat-model.api-key") - QianfanChatModel qianfanChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getChatModel(); - return QianfanChatModel.builder() - .baseUrl(chatModelProperties.getBaseUrl()) - .apiKey(chatModelProperties.getApiKey()) - .secretKey(chatModelProperties.getSecretKey()) - .endpoint(chatModelProperties.getEndpoint()) - .penaltyScore(chatModelProperties.getPenaltyScore()) - .modelName(chatModelProperties.getModelName()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .responseFormat(chatModelProperties.getResponseFormat()) - .maxRetries(chatModelProperties.getMaxRetries()) - .logRequests(chatModelProperties.getLogRequests()) - .logResponses(chatModelProperties.getLogResponses()) - .build(); - } - - @Bean - @ConditionalOnProperty(PREFIX + ".streaming-chat-model.api-key") - QianfanStreamingChatModel qianfanStreamingChatModel(Properties properties) { - ChatModelProperties chatModelProperties = properties.getStreamingChatModel(); - return QianfanStreamingChatModel.builder() - .endpoint(chatModelProperties.getEndpoint()) - .penaltyScore(chatModelProperties.getPenaltyScore()) - .temperature(chatModelProperties.getTemperature()) - .topP(chatModelProperties.getTopP()) - .baseUrl(chatModelProperties.getBaseUrl()) - .apiKey(chatModelProperties.getApiKey()) - .secretKey(chatModelProperties.getSecretKey()) - .modelName(chatModelProperties.getModelName()) - .responseFormat(chatModelProperties.getResponseFormat()) - .logRequests(chatModelProperties.getLogRequests()) - .logResponses(chatModelProperties.getLogResponses()) - .build(); - } - - @Bean - @ConditionalOnProperty(PREFIX + ".language-model.api-key") - QianfanLanguageModel qianfanLanguageModel(Properties properties) { - LanguageModelProperties languageModelProperties = properties.getLanguageModel(); - return QianfanLanguageModel.builder() - .endpoint(languageModelProperties.getEndpoint()) - .penaltyScore(languageModelProperties.getPenaltyScore()) - .topK(languageModelProperties.getTopK()) - .topP(languageModelProperties.getTopP()) - .baseUrl(languageModelProperties.getBaseUrl()) - .apiKey(languageModelProperties.getApiKey()) - .secretKey(languageModelProperties.getSecretKey()) - .modelName(languageModelProperties.getModelName()) - .temperature(languageModelProperties.getTemperature()) - .maxRetries(languageModelProperties.getMaxRetries()) - .logRequests(languageModelProperties.getLogRequests()) - .logResponses(languageModelProperties.getLogResponses()) - .build(); - } - - @Bean - @ConditionalOnProperty(PREFIX + ".streaming-language-model.api-key") - QianfanStreamingLanguageModel openAiStreamingLanguageModel(Properties properties) { - LanguageModelProperties languageModelProperties = properties.getStreamingLanguageModel(); - return QianfanStreamingLanguageModel.builder() - .endpoint(languageModelProperties.getEndpoint()) - .penaltyScore(languageModelProperties.getPenaltyScore()) - .topK(languageModelProperties.getTopK()) - .topP(languageModelProperties.getTopP()) - .baseUrl(languageModelProperties.getBaseUrl()) - .apiKey(languageModelProperties.getApiKey()) - .secretKey(languageModelProperties.getSecretKey()) - .modelName(languageModelProperties.getModelName()) - .temperature(languageModelProperties.getTemperature()) - .maxRetries(languageModelProperties.getMaxRetries()) - .logRequests(languageModelProperties.getLogRequests()) - .logResponses(languageModelProperties.getLogResponses()) - .build(); - } - - @Bean - @ConditionalOnProperty(PREFIX + ".embedding-model.api-key") - QianfanEmbeddingModel qianfanEmbeddingModel(Properties properties) { - EmbeddingModelProperties embeddingModelProperties = properties.getEmbeddingModel(); - return QianfanEmbeddingModel.builder() - .baseUrl(embeddingModelProperties.getBaseUrl()) - .endpoint(embeddingModelProperties.getEndpoint()) - .apiKey(embeddingModelProperties.getApiKey()) - .secretKey(embeddingModelProperties.getSecretKey()) - .modelName(embeddingModelProperties.getModelName()) - .user(embeddingModelProperties.getUser()) - .maxRetries(embeddingModelProperties.getMaxRetries()) - .logRequests(embeddingModelProperties.getLogRequests()) - .logResponses(embeddingModelProperties.getLogResponses()) - .build(); - } -} \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/ChatModelProperties.java b/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/ChatModelProperties.java deleted file mode 100644 index 703e9d20..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/ChatModelProperties.java +++ /dev/null @@ -1,26 +0,0 @@ -package dev.langchain4j.qianfan.spring; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - -import java.time.Duration; -import java.util.List; -import java.util.Map; - -@Getter -@Setter -class ChatModelProperties { - String baseUrl; - String apiKey; - String secretKey; - Double temperature; - Integer maxRetries; - Double topP; - String modelName; - String endpoint; - String responseFormat; - Double penaltyScore; - Boolean logRequests; - Boolean logResponses; -} \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/EmbeddingModelProperties.java b/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/EmbeddingModelProperties.java deleted file mode 100644 index 41dbba67..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/EmbeddingModelProperties.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.langchain4j.qianfan.spring; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - -import java.time.Duration; - -@Getter -@Setter -class EmbeddingModelProperties { - - String baseUrl; - String apiKey; - String secretKey; - Integer maxRetries; - String modelName; - String endpoint; - String user; - Boolean logRequests; - Boolean logResponses; -} \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/LanguageModelProperties.java b/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/LanguageModelProperties.java deleted file mode 100644 index 135bfb73..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/LanguageModelProperties.java +++ /dev/null @@ -1,25 +0,0 @@ -package dev.langchain4j.qianfan.spring; - -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.NestedConfigurationProperty; - -import java.time.Duration; - -@Getter -@Setter -class LanguageModelProperties { - - String baseUrl; - String apiKey; - String secretKey; - Double temperature; - Integer maxRetries; - Integer topK; - Double topP; - String modelName; - String endpoint; - Double penaltyScore; - Boolean logRequests; - Boolean logResponses; -} \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/Properties.java b/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/Properties.java deleted file mode 100644 index 7f809283..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/java/dev/langchain4j/qianfan/spring/Properties.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.langchain4j.qianfan.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.qianfan"; - - @NestedConfigurationProperty - ChatModelProperties chatModel; - - @NestedConfigurationProperty - ChatModelProperties streamingChatModel; - - @NestedConfigurationProperty - LanguageModelProperties languageModel; - - @NestedConfigurationProperty - LanguageModelProperties streamingLanguageModel; - - @NestedConfigurationProperty - EmbeddingModelProperties embeddingModel; -} diff --git a/langchain4j-qianfan-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/langchain4j-qianfan-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports deleted file mode 100644 index 610d79a9..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ /dev/null @@ -1 +0,0 @@ -dev.langchain4j.qianfan.spring.AutoConfig \ No newline at end of file diff --git a/langchain4j-qianfan-spring-boot-starter/src/test/java/dev/langchain4j/qianfan/spring/AutoConfigIT.java b/langchain4j-qianfan-spring-boot-starter/src/test/java/dev/langchain4j/qianfan/spring/AutoConfigIT.java deleted file mode 100644 index 876265b7..00000000 --- a/langchain4j-qianfan-spring-boot-starter/src/test/java/dev/langchain4j/qianfan/spring/AutoConfigIT.java +++ /dev/null @@ -1,163 +0,0 @@ -package dev.langchain4j.qianfan.spring; - -import dev.langchain4j.data.message.AiMessage; -import dev.langchain4j.model.StreamingResponseHandler; -import dev.langchain4j.model.chat.ChatLanguageModel; -import dev.langchain4j.model.chat.StreamingChatLanguageModel; -import dev.langchain4j.model.embedding.EmbeddingModel; -import dev.langchain4j.model.language.LanguageModel; -import dev.langchain4j.model.language.StreamingLanguageModel; -import dev.langchain4j.model.output.Response; -import dev.langchain4j.model.qianfan.*; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; -import org.springframework.boot.autoconfigure.AutoConfigurations; -import org.springframework.boot.test.context.runner.ApplicationContextRunner; - -import java.util.concurrent.CompletableFuture; - -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @Author: fanjia - * @createTime: 2024年04月18日 12:54:25 - * @version: 1.0 - * @Description: - */ -@EnabledIfEnvironmentVariable(named = "QIANFAN_API_KEY", matches = ".+") -class AutoConfigIT { - - private static final String API_KEY = System.getenv("QIANFAN_API_KEY"); - private static final String SECRET_KEY = System.getenv("QIANFAN_SECRET_KEY"); - - ApplicationContextRunner contextRunner = new ApplicationContextRunner() - .withConfiguration(AutoConfigurations.of(AutoConfig.class)); - - @Test - void should_provide_chat_model() { - contextRunner - .withPropertyValues( - "langchain4j.qianfan.chat-model.api-key=" + API_KEY, - "langchain4j.qianfan.chat-model.secret_key="+SECRET_KEY, - "langchain4j.qianfan.chat-model.endpoint=ernie-3.5-8k-1222" - ) - .run(context -> { - - ChatLanguageModel chatLanguageModel = context.getBean(ChatLanguageModel.class); - assertThat(chatLanguageModel).isInstanceOf(QianfanChatModel.class); - assertThat(chatLanguageModel.generate("What is the capital of Germany?")).contains("柏林"); - - assertThat(context.getBean(QianfanChatModel.class)).isSameAs(chatLanguageModel); - }); - } - - @Test - void should_provide_streaming_chat_model() { - contextRunner - .withPropertyValues( - "langchain4j.qianfan.streamingChatModel.api-key=" + API_KEY, - "langchain4j.qianfan.streamingChatModel.secret_key="+SECRET_KEY, - "langchain4j.qianfan.streamingChatModel.endpoint=ernie-3.5-8k-1222" - ) - .run(context -> { - - StreamingChatLanguageModel streamingChatLanguageModel = context.getBean(StreamingChatLanguageModel.class); - assertThat(streamingChatLanguageModel).isInstanceOf(QianfanStreamingChatModel.class); - CompletableFuture> future = new CompletableFuture<>(); - streamingChatLanguageModel.generate("德国的首都是哪里?", new StreamingResponseHandler() { - - @Override - public void onNext(String token) { - } - - @Override - public void onComplete(Response response) { - future.complete(response); - } - - @Override - public void onError(Throwable error) { - } - }); - Response response = future.get(60, SECONDS); - assertThat(response.content().text()).isNotNull(); - - assertThat(context.getBean(QianfanStreamingChatModel.class)).isSameAs(streamingChatLanguageModel); - }); - } - - @Test - void should_provide_language_model() { - contextRunner - .withPropertyValues( - "langchain4j.qianfan.languageModel.api-key=" + API_KEY, - "langchain4j.qianfan.languageModel.secret_key="+SECRET_KEY, - "langchain4j.qianfan.languageModel.modelName=CodeLlama-7b-Instruct", - "langchain4j.qianfan.languageModel.logRequests=true", - "langchain4j.qianfan.languageModel.logResponses=true" - ) - .run(context -> { - - LanguageModel languageModel = context.getBean(LanguageModel.class); - assertThat(languageModel).isInstanceOf(QianfanLanguageModel.class); - assertThat(languageModel.generate("What is the capital of Germany?").content()).contains("Berlin"); - assertThat(context.getBean(QianfanLanguageModel.class)).isSameAs(languageModel); - }); - } - - @Test - void should_provide_streaming_language_model() { - contextRunner - .withPropertyValues( - "langchain4j.qianfan.streamingLanguageModel.api-key=" + API_KEY, - "langchain4j.qianfan.streamingLanguageModel.secret_key="+SECRET_KEY, - "langchain4j.qianfan.streamingLanguageModel.modelName=CodeLlama-7b-Instruct", - "langchain4j.qianfan.streamingLanguageModel.logRequests=true", - "langchain4j.qianfan.streamingLanguageModel.logResponses=true" - ) - .run(context -> { - - StreamingLanguageModel streamingLanguageModel = context.getBean(StreamingLanguageModel.class); - assertThat(streamingLanguageModel).isInstanceOf(QianfanStreamingLanguageModel.class); - CompletableFuture> future = new CompletableFuture<>(); - streamingLanguageModel.generate("What is the capital of Germany?", new StreamingResponseHandler() { - - @Override - public void onNext(String token) { - } - - @Override - public void onComplete(Response response) { - future.complete(response); - } - - @Override - public void onError(Throwable error) { - } - }); - Response response = future.get(60, SECONDS); - assertThat(response.content()).isNotNull(); - - assertThat(context.getBean(QianfanStreamingLanguageModel.class)).isSameAs(streamingLanguageModel); - }); - } - - @Test - void should_provide_embedding_model() { - contextRunner - .withPropertyValues( - "langchain4j.qianfan.embeddingModel.api-key=" + API_KEY, - "langchain4j.qianfan.embeddingModel.secret_key="+SECRET_KEY, - "langchain4j.qianfan.embeddingModel.modelName=bge-large-zh" - ) - .run(context -> { - - EmbeddingModel embeddingModel = context.getBean(EmbeddingModel.class); - assertThat(embeddingModel).isInstanceOf(QianfanEmbeddingModel.class); - assertThat(embeddingModel.embed("hi").content().dimension()).isEqualTo(1024); - - assertThat(context.getBean(QianfanEmbeddingModel.class)).isSameAs(embeddingModel); - }); - } -} \ No newline at end of file diff --git a/pom.xml b/pom.xml index b146c56c..e2d64f48 100644 --- a/pom.xml +++ b/pom.xml @@ -28,9 +28,7 @@ langchain4j-vertex-ai-gemini-spring-boot-starter langchain4j-elasticsearch-spring-boot-starter langchain4j-redis-spring-boot-starter - langchain4j-milvus-spring-boot-starter - langchain4j-reactor From be95def02ecac4dd40540280bbad2147d34bdb5d Mon Sep 17 00:00:00 2001 From: Martin7-1 Date: Tue, 24 Dec 2024 15:50:28 +0800 Subject: [PATCH 2/2] revert --- langchain4j-redis-spring-boot-starter/pom.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/langchain4j-redis-spring-boot-starter/pom.xml b/langchain4j-redis-spring-boot-starter/pom.xml index f98e9679..12485537 100644 --- a/langchain4j-redis-spring-boot-starter/pom.xml +++ b/langchain4j-redis-spring-boot-starter/pom.xml @@ -52,6 +52,20 @@ test + + dev.langchain4j + langchain4j-embeddings-all-minilm-l6-v2-q + test + + + + dev.langchain4j + langchain4j-spring-boot-tests + ${project.version} + tests + test-jar + test + com.redis.testcontainers