From 279265b6aaecbfa2133e042b005d19316992d8a7 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Fri, 23 Feb 2024 21:30:34 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E8=87=AA=E5=8A=A8=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spring-ai-spring-boot-autoconfigure/pom.xml | 27 +++++++++++++++ ...ashsCopeAliyunConnectionConfiguration.java | 22 +++++++++++++ .../DashsCopeAliyunConnectionProperties.java | 20 +++++++++++ .../DashsCopeQwenChatAutoConfiguration.java | 17 ++++++++++ .../qwen/DashsCopeQwenChatProperties.java | 33 +++++++++++++++++++ 5 files changed, 119 insertions(+) create mode 100644 spring-ai-spring-boot-autoconfigure/pom.xml create mode 100644 spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionConfiguration.java create mode 100644 spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionProperties.java create mode 100644 spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatAutoConfiguration.java create mode 100644 spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatProperties.java diff --git a/spring-ai-spring-boot-autoconfigure/pom.xml b/spring-ai-spring-boot-autoconfigure/pom.xml new file mode 100644 index 0000000..0d25b23 --- /dev/null +++ b/spring-ai-spring-boot-autoconfigure/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.xywenjie.spring-ai-extension + spring-ai-extension + 0.8.0-SNAPSHOT + + spring-ai-spring-boot-autoconfigure + jar + Spring AI Spring Boot Auto Configure + + + + org.springframework.boot + spring-boot-starter + + + org.xywenjie.spring-ai-extension + spring-ai-dashscope + ${project.parent.version} + true + + + \ No newline at end of file diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionConfiguration.java new file mode 100644 index 0000000..352a7fb --- /dev/null +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionConfiguration.java @@ -0,0 +1,22 @@ +package org.springframework.ai.autoconfigure.dashscope; + +import org.springframework.ai.dashscope.DashsCopeService; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; + +@Configuration +@EnableConfigurationProperties({DashsCopeAliyunConnectionProperties.class}) +public class DashsCopeAliyunConnectionConfiguration { + + @Bean + @ConditionalOnMissingBean + public DashsCopeService dashsCopeService(DashsCopeAliyunConnectionProperties connectionProperties){ + if(StringUtils.hasText(connectionProperties.getAccessToken())){ + return new DashsCopeService(connectionProperties.getAccessToken()); + } + return new DashsCopeService(System.getenv("DASHSCOPE_API_KEY")); + } +} diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionProperties.java new file mode 100644 index 0000000..7b3d129 --- /dev/null +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/DashsCopeAliyunConnectionProperties.java @@ -0,0 +1,20 @@ +package org.springframework.ai.autoconfigure.dashscope; + + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(DashsCopeAliyunConnectionProperties.CONFIG_PREFIX) +public class DashsCopeAliyunConnectionProperties { + + public static final String CONFIG_PREFIX = "spring.ai.dashscope.aliyun"; + + private String accessToken; + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } +} diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatAutoConfiguration.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatAutoConfiguration.java new file mode 100644 index 0000000..5cecaf3 --- /dev/null +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatAutoConfiguration.java @@ -0,0 +1,17 @@ +package org.springframework.ai.autoconfigure.dashscope.qwen; + +import org.springframework.ai.dashscope.DashsCopeService; +import org.springframework.ai.dashscope.qwen.QWenChatClient; +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; + +@AutoConfiguration +@EnableConfigurationProperties({DashsCopeQwenChatProperties.class}) +public class DashsCopeQwenChatAutoConfiguration { + + @Bean + public QWenChatClient qWenChatClient(DashsCopeService dashsCopeService){ + return new QWenChatClient(dashsCopeService); + } +} diff --git a/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatProperties.java b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatProperties.java new file mode 100644 index 0000000..0756d26 --- /dev/null +++ b/spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/dashscope/qwen/DashsCopeQwenChatProperties.java @@ -0,0 +1,33 @@ +package org.springframework.ai.autoconfigure.dashscope.qwen; + +import org.springframework.ai.dashscope.metadata.support.ChatModel; +import org.springframework.ai.dashscope.qwen.QWenChatOptions; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.NestedConfigurationProperty; + +@ConfigurationProperties(DashsCopeQwenChatProperties.CONFIG_PREFIX) +public class DashsCopeQwenChatProperties { + + public static final String CONFIG_PREFIX = "spring.ai.dashscope.qwen.chat"; + + private String model = ChatModel.QWen_72B_CHAT.getModelValue(); + + @NestedConfigurationProperty + private QWenChatOptions options = QWenChatOptions.builder().build(); + + public String getModel() { + return model; + } + + public void setModel(String model) { + this.model = model; + } + + public QWenChatOptions getOptions() { + return options; + } + + public void setOptions(QWenChatOptions options) { + this.options = options; + } +}