mirror of
				https://github.com/YunaiV/ruoyi-vue-pro.git
				synced 2025-10-31 18:49:06 +08:00 
			
		
		
		
	feat:【AI 大模型】引入 spring-ai-starter-model-deepseek 依赖
This commit is contained in:
		| @ -84,6 +84,11 @@ | |||||||
|             <artifactId>spring-ai-starter-model-azure-openai</artifactId> |             <artifactId>spring-ai-starter-model-azure-openai</artifactId> | ||||||
|             <version>${spring-ai.version}</version> |             <version>${spring-ai.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |         <dependency> | ||||||
|  |             <groupId>org.springframework.ai</groupId> | ||||||
|  |             <artifactId>spring-ai-starter-model-deepseek</artifactId> | ||||||
|  |             <version>${spring-ai.version}</version> | ||||||
|  |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>org.springframework.ai</groupId> |             <groupId>org.springframework.ai</groupId> | ||||||
|             <artifactId>spring-ai-starter-model-ollama</artifactId> |             <artifactId>spring-ai-starter-model-ollama</artifactId> | ||||||
| @ -94,18 +99,6 @@ | |||||||
|             <artifactId>spring-ai-starter-model-stability-ai</artifactId> |             <artifactId>spring-ai-starter-model-stability-ai</artifactId> | ||||||
|             <version>${spring-ai.version}</version> |             <version>${spring-ai.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |  | ||||||
|             <!-- 通义千问 --> |  | ||||||
|             <groupId>com.alibaba.cloud.ai</groupId> |  | ||||||
|             <artifactId>spring-ai-alibaba-starter-dashscope</artifactId> |  | ||||||
|             <version>${alibaba-ai.version}</version> |  | ||||||
|         </dependency> |  | ||||||
|         <dependency> |  | ||||||
|             <!-- 文心一言 --> |  | ||||||
|             <groupId>org.springaicommunity</groupId> |  | ||||||
|             <artifactId>qianfan-spring-boot-starter</artifactId> |  | ||||||
|             <version>1.0.0</version> |  | ||||||
|         </dependency> |  | ||||||
|         <dependency> |         <dependency> | ||||||
|             <!-- 智谱 GLM --> |             <!-- 智谱 GLM --> | ||||||
|             <groupId>org.springframework.ai</groupId> |             <groupId>org.springframework.ai</groupId> | ||||||
| @ -117,6 +110,20 @@ | |||||||
|             <artifactId>spring-ai-starter-model-minimax</artifactId> |             <artifactId>spring-ai-starter-model-minimax</artifactId> | ||||||
|             <version>${spring-ai.version}</version> |             <version>${spring-ai.version}</version> | ||||||
|         </dependency> |         </dependency> | ||||||
|  |  | ||||||
|  |         <dependency> | ||||||
|  |             <!-- 通义千问 --> | ||||||
|  |             <groupId>com.alibaba.cloud.ai</groupId> | ||||||
|  |             <artifactId>spring-ai-alibaba-starter-dashscope</artifactId> | ||||||
|  |             <version>${alibaba-ai.version}</version> | ||||||
|  |         </dependency> | ||||||
|  |  | ||||||
|  |         <dependency> | ||||||
|  |             <!-- 文心一言 --> | ||||||
|  |             <groupId>org.springaicommunity</groupId> | ||||||
|  |             <artifactId>qianfan-spring-boot-starter</artifactId> | ||||||
|  |             <version>1.0.0</version> | ||||||
|  |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|             <!-- 月之暗灭 --> |             <!-- 月之暗灭 --> | ||||||
|             <groupId>org.springaicommunity</groupId> |             <groupId>org.springaicommunity</groupId> | ||||||
|  | |||||||
| @ -5,7 +5,6 @@ import cn.hutool.extra.spring.SpringUtil; | |||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactory; | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactory; | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactoryImpl; | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactoryImpl; | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.baichuan.BaiChuanChatModel; | import cn.iocoder.yudao.module.ai.framework.ai.core.model.baichuan.BaiChuanChatModel; | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek.DeepSeekChatModel; |  | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.doubao.DouBaoChatModel; | import cn.iocoder.yudao.module.ai.framework.ai.core.model.doubao.DouBaoChatModel; | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.hunyuan.HunYuanChatModel; | import cn.iocoder.yudao.module.ai.framework.ai.core.model.hunyuan.HunYuanChatModel; | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.midjourney.api.MidjourneyApi; | import cn.iocoder.yudao.module.ai.framework.ai.core.model.midjourney.api.MidjourneyApi; | ||||||
| @ -52,33 +51,6 @@ public class AiAutoConfiguration { | |||||||
|  |  | ||||||
|     // ========== 各种 AI Client 创建 ========== |     // ========== 各种 AI Client 创建 ========== | ||||||
|  |  | ||||||
|     @Bean |  | ||||||
|     @ConditionalOnProperty(value = "yudao.ai.deepseek.enable", havingValue = "true") |  | ||||||
|     public DeepSeekChatModel deepSeekChatModel(YudaoAiProperties yudaoAiProperties) { |  | ||||||
|         YudaoAiProperties.DeepSeekProperties properties = yudaoAiProperties.getDeepseek(); |  | ||||||
|         return buildDeepSeekChatModel(properties); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     public DeepSeekChatModel buildDeepSeekChatModel(YudaoAiProperties.DeepSeekProperties properties) { |  | ||||||
|         if (StrUtil.isEmpty(properties.getModel())) { |  | ||||||
|             properties.setModel(DeepSeekChatModel.MODEL_DEFAULT); |  | ||||||
|         } |  | ||||||
|         OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() |  | ||||||
|                 .openAiApi(OpenAiApi.builder() |  | ||||||
|                         .baseUrl(DeepSeekChatModel.BASE_URL) |  | ||||||
|                         .apiKey(properties.getApiKey()) |  | ||||||
|                         .build()) |  | ||||||
|                 .defaultOptions(OpenAiChatOptions.builder() |  | ||||||
|                         .model(properties.getModel()) |  | ||||||
|                         .temperature(properties.getTemperature()) |  | ||||||
|                         .maxTokens(properties.getMaxTokens()) |  | ||||||
|                         .topP(properties.getTopP()) |  | ||||||
|                         .build()) |  | ||||||
|                 .toolCallingManager(getToolCallingManager()) |  | ||||||
|                 .build(); |  | ||||||
|         return new DeepSeekChatModel(openAiChatModel); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Bean |     @Bean | ||||||
|     @ConditionalOnProperty(value = "yudao.ai.doubao.enable", havingValue = "true") |     @ConditionalOnProperty(value = "yudao.ai.doubao.enable", havingValue = "true") | ||||||
|     public DouBaoChatModel douBaoChatClient(YudaoAiProperties yudaoAiProperties) { |     public DouBaoChatModel douBaoChatClient(YudaoAiProperties yudaoAiProperties) { | ||||||
|  | |||||||
| @ -13,12 +13,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; | |||||||
| @Data | @Data | ||||||
| public class YudaoAiProperties { | public class YudaoAiProperties { | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * DeepSeek |  | ||||||
|      */ |  | ||||||
|     @SuppressWarnings("SpellCheckingInspection") |  | ||||||
|     private DeepSeekProperties deepseek; |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * 字节豆包 |      * 字节豆包 | ||||||
|      */ |      */ | ||||||
| @ -60,19 +54,6 @@ public class YudaoAiProperties { | |||||||
|     @SuppressWarnings("SpellCheckingInspection") |     @SuppressWarnings("SpellCheckingInspection") | ||||||
|     private SunoProperties suno; |     private SunoProperties suno; | ||||||
|  |  | ||||||
|     @Data |  | ||||||
|     public static class DeepSeekProperties { |  | ||||||
|  |  | ||||||
|         private String enable; |  | ||||||
|         private String apiKey; |  | ||||||
|  |  | ||||||
|         private String model; |  | ||||||
|         private Double temperature; |  | ||||||
|         private Integer maxTokens; |  | ||||||
|         private Double topP; |  | ||||||
|  |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Data |     @Data | ||||||
|     public static class DouBaoProperties { |     public static class DouBaoProperties { | ||||||
|  |  | ||||||
|  | |||||||
| @ -1,45 +0,0 @@ | |||||||
| package cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek; |  | ||||||
|  |  | ||||||
| import lombok.RequiredArgsConstructor; |  | ||||||
| import lombok.extern.slf4j.Slf4j; |  | ||||||
| import org.springframework.ai.chat.model.ChatModel; |  | ||||||
| import org.springframework.ai.chat.model.ChatResponse; |  | ||||||
| import org.springframework.ai.chat.prompt.ChatOptions; |  | ||||||
| import org.springframework.ai.chat.prompt.Prompt; |  | ||||||
| import org.springframework.ai.openai.OpenAiChatModel; |  | ||||||
| import reactor.core.publisher.Flux; |  | ||||||
|  |  | ||||||
| /** |  | ||||||
|  * DeepSeek {@link ChatModel} 实现类 |  | ||||||
|  * |  | ||||||
|  * @author fansili |  | ||||||
|  */ |  | ||||||
| @Slf4j |  | ||||||
| @RequiredArgsConstructor |  | ||||||
| public class DeepSeekChatModel implements ChatModel { |  | ||||||
|  |  | ||||||
|     public static final String BASE_URL = "https://api.deepseek.com"; |  | ||||||
|  |  | ||||||
|     public static final String MODEL_DEFAULT = "deepseek-chat"; |  | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * 兼容 OpenAI 接口,进行复用 |  | ||||||
|      */ |  | ||||||
|     private final OpenAiChatModel openAiChatModel; |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public ChatResponse call(Prompt prompt) { |  | ||||||
|         return openAiChatModel.call(prompt); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public Flux<ChatResponse> stream(Prompt prompt) { |  | ||||||
|         return openAiChatModel.stream(prompt); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     @Override |  | ||||||
|     public ChatOptions getDefaultOptions() { |  | ||||||
|         return openAiChatModel.getDefaultOptions(); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
| } |  | ||||||
| @ -1,6 +1,5 @@ | |||||||
| package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat; | package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat; | ||||||
|  |  | ||||||
| import cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek.DeepSeekChatModel; |  | ||||||
| import org.junit.jupiter.api.Disabled; | import org.junit.jupiter.api.Disabled; | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
| import org.springframework.ai.chat.messages.Message; | import org.springframework.ai.chat.messages.Message; | ||||||
| @ -8,9 +7,9 @@ import org.springframework.ai.chat.messages.SystemMessage; | |||||||
| import org.springframework.ai.chat.messages.UserMessage; | import org.springframework.ai.chat.messages.UserMessage; | ||||||
| import org.springframework.ai.chat.model.ChatResponse; | import org.springframework.ai.chat.model.ChatResponse; | ||||||
| import org.springframework.ai.chat.prompt.Prompt; | import org.springframework.ai.chat.prompt.Prompt; | ||||||
| import org.springframework.ai.openai.OpenAiChatModel; | import org.springframework.ai.deepseek.DeepSeekChatModel; | ||||||
| import org.springframework.ai.openai.OpenAiChatOptions; | import org.springframework.ai.deepseek.DeepSeekChatOptions; | ||||||
| import org.springframework.ai.openai.api.OpenAiApi; | import org.springframework.ai.deepseek.api.DeepSeekApi; | ||||||
| import reactor.core.publisher.Flux; | import reactor.core.publisher.Flux; | ||||||
|  |  | ||||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||||
| @ -23,19 +22,16 @@ import java.util.List; | |||||||
|  */ |  */ | ||||||
| public class DeepSeekChatModelTests { | public class DeepSeekChatModelTests { | ||||||
|  |  | ||||||
|     private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder() |     private final DeepSeekChatModel chatModel = DeepSeekChatModel.builder() | ||||||
|             .openAiApi(OpenAiApi.builder() |             .deepSeekApi(DeepSeekApi.builder() | ||||||
|                     .baseUrl(DeepSeekChatModel.BASE_URL) |                     .apiKey("sk-eaf4172a057344dd9bc64b1f806b6axx") // apiKey | ||||||
|                     .apiKey("sk-e52047409b144d97b791a6a46a2d") // apiKey |  | ||||||
|                     .build()) |                     .build()) | ||||||
|             .defaultOptions(OpenAiChatOptions.builder() |             .defaultOptions(DeepSeekChatOptions.builder() | ||||||
|                     .model("deepseek-chat") // 模型 |                     .model("deepseek-chat") // 模型 | ||||||
|                     .temperature(0.7) |                     .temperature(0.7) | ||||||
|                     .build()) |                     .build()) | ||||||
|             .build(); |             .build(); | ||||||
|  |  | ||||||
|     private final DeepSeekChatModel chatModel = new DeepSeekChatModel(openAiChatModel); |  | ||||||
|  |  | ||||||
|     @Test |     @Test | ||||||
|     @Disabled |     @Disabled | ||||||
|     public void testCall() { |     public void testCall() { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV