Commit 3d0eb77148c5869c42699ba1f2831e4ed89f01ab
1 parent
c789418a
feat:【AI 大模型】引入 spring-ai-starter-model-deepseek 依赖
Showing
5 changed files
with
25 additions
and
114 deletions
yudao-module-ai/pom.xml
| @@ -86,6 +86,11 @@ | @@ -86,6 +86,11 @@ | ||
| 86 | </dependency> | 86 | </dependency> |
| 87 | <dependency> | 87 | <dependency> |
| 88 | <groupId>org.springframework.ai</groupId> | 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 | <artifactId>spring-ai-starter-model-ollama</artifactId> | 94 | <artifactId>spring-ai-starter-model-ollama</artifactId> |
| 90 | <version>${spring-ai.version}</version> | 95 | <version>${spring-ai.version}</version> |
| 91 | </dependency> | 96 | </dependency> |
| @@ -95,11 +100,24 @@ | @@ -95,11 +100,24 @@ | ||
| 95 | <version>${spring-ai.version}</version> | 100 | <version>${spring-ai.version}</version> |
| 96 | </dependency> | 101 | </dependency> |
| 97 | <dependency> | 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 | <groupId>com.alibaba.cloud.ai</groupId> | 116 | <groupId>com.alibaba.cloud.ai</groupId> |
| 100 | <artifactId>spring-ai-alibaba-starter-dashscope</artifactId> | 117 | <artifactId>spring-ai-alibaba-starter-dashscope</artifactId> |
| 101 | <version>${alibaba-ai.version}</version> | 118 | <version>${alibaba-ai.version}</version> |
| 102 | </dependency> | 119 | </dependency> |
| 120 | + | ||
| 103 | <dependency> | 121 | <dependency> |
| 104 | <!-- 文心一言 --> | 122 | <!-- 文心一言 --> |
| 105 | <groupId>org.springaicommunity</groupId> | 123 | <groupId>org.springaicommunity</groupId> |
| @@ -107,17 +125,6 @@ | @@ -107,17 +125,6 @@ | ||
| 107 | <version>1.0.0</version> | 125 | <version>1.0.0</version> |
| 108 | </dependency> | 126 | </dependency> |
| 109 | <dependency> | 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 | <groupId>org.springaicommunity</groupId> | 129 | <groupId>org.springaicommunity</groupId> |
| 123 | <artifactId>moonshot-spring-boot-starter</artifactId> | 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,7 +5,6 @@ import cn.hutool.extra.spring.SpringUtil; | ||
| 5 | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactory; | 5 | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactory; |
| 6 | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactoryImpl; | 6 | import cn.iocoder.yudao.module.ai.framework.ai.core.AiModelFactoryImpl; |
| 7 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.baichuan.BaiChuanChatModel; | 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 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.doubao.DouBaoChatModel; | 8 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.doubao.DouBaoChatModel; |
| 10 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.hunyuan.HunYuanChatModel; | 9 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.hunyuan.HunYuanChatModel; |
| 11 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.midjourney.api.MidjourneyApi; | 10 | import cn.iocoder.yudao.module.ai.framework.ai.core.model.midjourney.api.MidjourneyApi; |
| @@ -53,33 +52,6 @@ public class AiAutoConfiguration { | @@ -53,33 +52,6 @@ public class AiAutoConfiguration { | ||
| 53 | // ========== 各种 AI Client 创建 ========== | 52 | // ========== 各种 AI Client 创建 ========== |
| 54 | 53 | ||
| 55 | @Bean | 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 | @ConditionalOnProperty(value = "yudao.ai.doubao.enable", havingValue = "true") | 55 | @ConditionalOnProperty(value = "yudao.ai.doubao.enable", havingValue = "true") |
| 84 | public DouBaoChatModel douBaoChatClient(YudaoAiProperties yudaoAiProperties) { | 56 | public DouBaoChatModel douBaoChatClient(YudaoAiProperties yudaoAiProperties) { |
| 85 | YudaoAiProperties.DouBaoProperties properties = yudaoAiProperties.getDoubao(); | 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,12 +14,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties; | ||
| 14 | public class YudaoAiProperties { | 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 | @SuppressWarnings("SpellCheckingInspection") | 19 | @SuppressWarnings("SpellCheckingInspection") |
| @@ -61,19 +55,6 @@ public class YudaoAiProperties { | @@ -61,19 +55,6 @@ public class YudaoAiProperties { | ||
| 61 | private SunoProperties suno; | 55 | private SunoProperties suno; |
| 62 | 56 | ||
| 63 | @Data | 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 | public static class DouBaoProperties { | 58 | public static class DouBaoProperties { |
| 78 | 59 | ||
| 79 | private String enable; | 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 | package cn.iocoder.yudao.module.ai.framework.ai.core.model.chat; | 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 | import org.junit.jupiter.api.Disabled; | 3 | import org.junit.jupiter.api.Disabled; |
| 5 | import org.junit.jupiter.api.Test; | 4 | import org.junit.jupiter.api.Test; |
| 6 | import org.springframework.ai.chat.messages.Message; | 5 | import org.springframework.ai.chat.messages.Message; |
| @@ -8,9 +7,9 @@ import org.springframework.ai.chat.messages.SystemMessage; | @@ -8,9 +7,9 @@ import org.springframework.ai.chat.messages.SystemMessage; | ||
| 8 | import org.springframework.ai.chat.messages.UserMessage; | 7 | import org.springframework.ai.chat.messages.UserMessage; |
| 9 | import org.springframework.ai.chat.model.ChatResponse; | 8 | import org.springframework.ai.chat.model.ChatResponse; |
| 10 | import org.springframework.ai.chat.prompt.Prompt; | 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 | import reactor.core.publisher.Flux; | 13 | import reactor.core.publisher.Flux; |
| 15 | 14 | ||
| 16 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
| @@ -23,19 +22,16 @@ import java.util.List; | @@ -23,19 +22,16 @@ import java.util.List; | ||
| 23 | */ | 22 | */ |
| 24 | public class DeepSeekChatModelTests { | 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 | .build()) | 28 | .build()) |
| 31 | - .defaultOptions(OpenAiChatOptions.builder() | 29 | + .defaultOptions(DeepSeekChatOptions.builder() |
| 32 | .model("deepseek-chat") // 模型 | 30 | .model("deepseek-chat") // 模型 |
| 33 | .temperature(0.7) | 31 | .temperature(0.7) |
| 34 | .build()) | 32 | .build()) |
| 35 | .build(); | 33 | .build(); |
| 36 | 34 | ||
| 37 | - private final DeepSeekChatModel chatModel = new DeepSeekChatModel(openAiChatModel); | ||
| 38 | - | ||
| 39 | @Test | 35 | @Test |
| 40 | @Disabled | 36 | @Disabled |
| 41 | public void testCall() { | 37 | public void testCall() { |