Skip to content

Commit

Permalink
提交自动配置功能
Browse files Browse the repository at this point in the history
  • Loading branch information
XYWENJIE committed Feb 23, 2024
1 parent 7340c69 commit 279265b
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
27 changes: 27 additions & 0 deletions spring-ai-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xywenjie.spring-ai-extension</groupId>
<artifactId>spring-ai-extension</artifactId>
<version>0.8.0-SNAPSHOT</version>
</parent>
<artifactId>spring-ai-spring-boot-autoconfigure</artifactId>
<packaging>jar</packaging>
<name>Spring AI Spring Boot Auto Configure</name>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.xywenjie.spring-ai-extension</groupId>
<artifactId>spring-ai-dashscope</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 279265b

Please sign in to comment.