Commit 3d0eb77148c5869c42699ba1f2831e4ed89f01ab

Authored by YunaiV
1 parent c789418a

feat:【AI 大模型】引入 spring-ai-starter-model-deepseek 依赖

yudao-module-ai/pom.xml
... ... @@ -86,6 +86,11 @@
86 86 </dependency>
87 87 <dependency>
88 88 <groupId>org.springframework.ai</groupId>
  89 + <artifactId>spring-ai-starter-model-deepseek</artifactId>
  90 + <version>${spring-ai.version}</version>
  91 + </dependency>
  92 + <dependency>
  93 + <groupId>org.springframework.ai</groupId>
89 94 <artifactId>spring-ai-starter-model-ollama</artifactId>
90 95 <version>${spring-ai.version}</version>
91 96 </dependency>
... ... @@ -95,11 +100,24 @@
95 100 <version>${spring-ai.version}</version>
96 101 </dependency>
97 102 <dependency>
  103 + <!-- 智谱 GLM -->
  104 + <groupId>org.springframework.ai</groupId>
  105 + <artifactId>spring-ai-starter-model-zhipuai</artifactId>
  106 + <version>${spring-ai.version}</version>
  107 + </dependency>
  108 + <dependency>
  109 + <groupId>org.springframework.ai</groupId>
  110 + <artifactId>spring-ai-starter-model-minimax</artifactId>
  111 + <version>${spring-ai.version}</version>
  112 + </dependency>
  113 +
  114 + <dependency>
98 115 <!-- 通义千问 -->
99 116 <groupId>com.alibaba.cloud.ai</groupId>
100 117 <artifactId>spring-ai-alibaba-starter-dashscope</artifactId>
101 118 <version>${alibaba-ai.version}</version>
102 119 </dependency>
  120 +
103 121 <dependency>
104 122 <!-- 文心一言 -->
105 123 <groupId>org.springaicommunity</groupId>
... ... @@ -107,17 +125,6 @@
107 125 <version>1.0.0</version>
108 126 </dependency>
109 127 <dependency>
110   - <!-- 智谱 GLM -->
111   - <groupId>org.springframework.ai</groupId>
112   - <artifactId>spring-ai-starter-model-zhipuai</artifactId>
113   - <version>${spring-ai.version}</version>
114   - </dependency>
115   - <dependency>
116   - <groupId>org.springframework.ai</groupId>
117   - <artifactId>spring-ai-starter-model-minimax</artifactId>
118   - <version>${spring-ai.version}</version>
119   - </dependency>
120   - <dependency>
121 128 <!-- 月之暗灭 -->
122 129 <groupId>org.springaicommunity</groupId>
123 130 <artifactId>moonshot-spring-boot-starter</artifactId>
... ...
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/config/AiAutoConfiguration.java
... ... @@ -5,7 +5,6 @@ import cn.hutool.extra.spring.SpringUtil;
5 5 import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactory;
6 6 import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactoryImpl;
7 7 import cn.iocoder.yudao.module.ai.framework.ai.core.model.baichuan.BaiChuanChatModel;
8   -import cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek.DeepSeekChatModel;
9 8 import cn.iocoder.yudao.module.ai.framework.ai.core.model.doubao.DouBaoChatModel;
10 9 import cn.iocoder.yudao.module.ai.framework.ai.core.model.hunyuan.HunYuanChatModel;
11 10 import cn.iocoder.yudao.module.ai.framework.ai.core.model.midjourney.api.MidjourneyApi;
... ... @@ -53,33 +52,6 @@ public class AiAutoConfiguration {
53 52 // ========== 各种 AI Client 创建 ==========
54 53  
55 54 @Bean
56   - @ConditionalOnProperty(value = "yudao.ai.deepseek.enable", havingValue = "true")
57   - public DeepSeekChatModel deepSeekChatModel(YudaoAiProperties yudaoAiProperties) {
58   - YudaoAiProperties.DeepSeekProperties properties = yudaoAiProperties.getDeepseek();
59   - return buildDeepSeekChatModel(properties);
60   - }
61   -
62   - public DeepSeekChatModel buildDeepSeekChatModel(YudaoAiProperties.DeepSeekProperties properties) {
63   - if (StrUtil.isEmpty(properties.getModel())) {
64   - properties.setModel(DeepSeekChatModel.MODEL_DEFAULT);
65   - }
66   - OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
67   - .openAiApi(OpenAiApi.builder()
68   - .baseUrl(DeepSeekChatModel.BASE_URL)
69   - .apiKey(properties.getApiKey())
70   - .build())
71   - .defaultOptions(OpenAiChatOptions.builder()
72   - .model(properties.getModel())
73   - .temperature(properties.getTemperature())
74   - .maxTokens(properties.getMaxTokens())
75   - .topP(properties.getTopP())
76   - .build())
77   - .toolCallingManager(getToolCallingManager())
78   - .build();
79   - return new DeepSeekChatModel(openAiChatModel);
80   - }
81   -
82   - @Bean
83 55 @ConditionalOnProperty(value = "yudao.ai.doubao.enable", havingValue = "true")
84 56 public DouBaoChatModel douBaoChatClient(YudaoAiProperties yudaoAiProperties) {
85 57 YudaoAiProperties.DouBaoProperties properties = yudaoAiProperties.getDoubao();
... ...
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/config/YudaoAiProperties.java
... ... @@ -14,12 +14,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
14 14 public class YudaoAiProperties {
15 15  
16 16 /**
17   - * DeepSeek
18   - */
19   - @SuppressWarnings("SpellCheckingInspection")
20   - private DeepSeekProperties deepseek;
21   -
22   - /**
23 17 * 字节豆包
24 18 */
25 19 @SuppressWarnings("SpellCheckingInspection")
... ... @@ -61,19 +55,6 @@ public class YudaoAiProperties {
61 55 private SunoProperties suno;
62 56  
63 57 @Data
64   - public static class DeepSeekProperties {
65   -
66   - private String enable;
67   - private String apiKey;
68   -
69   - private String model;
70   - private Double temperature;
71   - private Integer maxTokens;
72   - private Double topP;
73   -
74   - }
75   -
76   - @Data
77 58 public static class DouBaoProperties {
78 59  
79 60 private String enable;
... ...
yudao-module-ai/src/main/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/deepseek/DeepSeekChatModel.java deleted
1   -package cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek;
2   -
3   -import lombok.RequiredArgsConstructor;
4   -import lombok.extern.slf4j.Slf4j;
5   -import org.springframework.ai.chat.model.ChatModel;
6   -import org.springframework.ai.chat.model.ChatResponse;
7   -import org.springframework.ai.chat.prompt.ChatOptions;
8   -import org.springframework.ai.chat.prompt.Prompt;
9   -import org.springframework.ai.openai.OpenAiChatModel;
10   -import reactor.core.publisher.Flux;
11   -
12   -/**
13   - * DeepSeek {@link ChatModel} 实现类
14   - *
15   - * @author fansili
16   - */
17   -@Slf4j
18   -@RequiredArgsConstructor
19   -public class DeepSeekChatModel implements ChatModel {
20   -
21   - public static final String BASE_URL = "https://api.deepseek.com";
22   -
23   - public static final String MODEL_DEFAULT = "deepseek-chat";
24   -
25   - /**
26   - * 兼容 OpenAI 接口,进行复用
27   - */
28   - private final OpenAiChatModel openAiChatModel;
29   -
30   - @Override
31   - public ChatResponse call(Prompt prompt) {
32   - return openAiChatModel.call(prompt);
33   - }
34   -
35   - @Override
36   - public Flux<ChatResponse> stream(Prompt prompt) {
37   - return openAiChatModel.stream(prompt);
38   - }
39   -
40   - @Override
41   - public ChatOptions getDefaultOptions() {
42   - return openAiChatModel.getDefaultOptions();
43   - }
44   -
45   -}
yudao-module-ai/src/test/java/cn/iocoder/yudao/module/ai/framework/ai/core/model/chat/DeepSeekChatModelTests.java
1 1 package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat;
2 2  
3   -import cn.iocoder.yudao.module.ai.framework.ai.core.model.deepseek.DeepSeekChatModel;
4 3 import org.junit.jupiter.api.Disabled;
5 4 import org.junit.jupiter.api.Test;
6 5 import org.springframework.ai.chat.messages.Message;
... ... @@ -8,9 +7,9 @@ import org.springframework.ai.chat.messages.SystemMessage;
8 7 import org.springframework.ai.chat.messages.UserMessage;
9 8 import org.springframework.ai.chat.model.ChatResponse;
10 9 import org.springframework.ai.chat.prompt.Prompt;
11   -import org.springframework.ai.openai.OpenAiChatModel;
12   -import org.springframework.ai.openai.OpenAiChatOptions;
13   -import org.springframework.ai.openai.api.OpenAiApi;
  10 +import org.springframework.ai.deepseek.DeepSeekChatModel;
  11 +import org.springframework.ai.deepseek.DeepSeekChatOptions;
  12 +import org.springframework.ai.deepseek.api.DeepSeekApi;
14 13 import reactor.core.publisher.Flux;
15 14  
16 15 import java.util.ArrayList;
... ... @@ -23,19 +22,16 @@ import java.util.List;
23 22 */
24 23 public class DeepSeekChatModelTests {
25 24  
26   - private final OpenAiChatModel openAiChatModel = OpenAiChatModel.builder()
27   - .openAiApi(OpenAiApi.builder()
28   - .baseUrl(DeepSeekChatModel.BASE_URL)
29   - .apiKey("sk-e52047409b144d97b791a6a46a2d") // apiKey
  25 + private final DeepSeekChatModel chatModel = DeepSeekChatModel.builder()
  26 + .deepSeekApi(DeepSeekApi.builder()
  27 + .apiKey("sk-eaf4172a057344dd9bc64b1f806b6axx") // apiKey
30 28 .build())
31   - .defaultOptions(OpenAiChatOptions.builder()
  29 + .defaultOptions(DeepSeekChatOptions.builder()
32 30 .model("deepseek-chat") // 模型
33 31 .temperature(0.7)
34 32 .build())
35 33 .build();
36 34  
37   - private final DeepSeekChatModel chatModel = new DeepSeekChatModel(openAiChatModel);
38   -
39 35 @Test
40 36 @Disabled
41 37 public void testCall() {
... ...