diff --git a/bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml b/bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml index b04e793e..6e543f17 100644 --- a/bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml +++ b/bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml @@ -53,6 +53,10 @@ org.apache.bigtop bigtop-manager-ai-qianfan + + org.apache.bigtop + bigtop-manager-ai-deepseek + org.apache.bigtop bigtop-manager-dao diff --git a/bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/GeneralAssistantFactory.java b/bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/GeneralAssistantFactory.java index bf4b5290..c7124a7a 100644 --- a/bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/GeneralAssistantFactory.java +++ b/bigtop-manager-ai/bigtop-manager-ai-assistant/src/main/java/org/apache/bigtop/manager/ai/assistant/GeneralAssistantFactory.java @@ -28,6 +28,7 @@ import org.apache.bigtop.manager.ai.core.factory.AIAssistant; import org.apache.bigtop.manager.ai.core.provider.SystemPromptProvider; import org.apache.bigtop.manager.ai.dashscope.DashScopeAssistant; +import org.apache.bigtop.manager.ai.deepseek.DeepSeekAssistant; import org.apache.bigtop.manager.ai.openai.OpenAIAssistant; import org.apache.bigtop.manager.ai.qianfan.QianFanAssistant; @@ -64,6 +65,7 @@ private AIAssistant.Builder initializeBuilder(PlatformType platformType) { case OPENAI -> OpenAIAssistant.builder(); case DASH_SCOPE -> DashScopeAssistant.builder(); case QIANFAN -> QianFanAssistant.builder(); + case DEEPSEEK -> DeepSeekAssistant.builder(); }; } diff --git a/bigtop-manager-ai/bigtop-manager-ai-core/src/main/java/org/apache/bigtop/manager/ai/core/enums/PlatformType.java b/bigtop-manager-ai/bigtop-manager-ai-core/src/main/java/org/apache/bigtop/manager/ai/core/enums/PlatformType.java index ec7487ea..fc3cc792 100644 --- a/bigtop-manager-ai/bigtop-manager-ai-core/src/main/java/org/apache/bigtop/manager/ai/core/enums/PlatformType.java +++ b/bigtop-manager-ai/bigtop-manager-ai-core/src/main/java/org/apache/bigtop/manager/ai/core/enums/PlatformType.java @@ -29,7 +29,8 @@ public enum PlatformType { OPENAI("openai"), DASH_SCOPE("dashscope"), - QIANFAN("qianfan"); + QIANFAN("qianfan"), + DEEPSEEK("deepseek"); private final String value; diff --git a/bigtop-manager-ai/bigtop-manager-ai-core/src/test/java/org/apache/bigtop/manager/ai/core/enums/PlatformTypeTest.java b/bigtop-manager-ai/bigtop-manager-ai-core/src/test/java/org/apache/bigtop/manager/ai/core/enums/PlatformTypeTest.java index 863242b9..cb2bc5ea 100644 --- a/bigtop-manager-ai/bigtop-manager-ai-core/src/test/java/org/apache/bigtop/manager/ai/core/enums/PlatformTypeTest.java +++ b/bigtop-manager-ai/bigtop-manager-ai-core/src/test/java/org/apache/bigtop/manager/ai/core/enums/PlatformTypeTest.java @@ -31,10 +31,11 @@ public class PlatformTypeTest { @Test public void testGetPlatforms() { List senders = PlatformType.getPlatforms(); - assertEquals(3, senders.size()); + assertEquals(4, senders.size()); assertTrue(senders.contains("openai")); assertTrue(senders.contains("dashscope")); assertTrue(senders.contains("qianfan")); + assertTrue(senders.contains("deepseek")); } @Test @@ -42,6 +43,7 @@ public void testGetPlatformType() { assertEquals(PlatformType.OPENAI, PlatformType.getPlatformType("openai")); assertEquals(PlatformType.DASH_SCOPE, PlatformType.getPlatformType("dashscope")); assertEquals(PlatformType.QIANFAN, PlatformType.getPlatformType("qianfan")); + assertEquals(PlatformType.DEEPSEEK, PlatformType.getPlatformType("deepseek")); assertNull(PlatformType.getPlatformType("")); assertNull(PlatformType.getPlatformType(null)); assertNull(PlatformType.getPlatformType("unknown")); diff --git a/bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml b/bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml new file mode 100644 index 00000000..f62ecd31 --- /dev/null +++ b/bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.bigtop + bigtop-manager-ai + ${revision} + + + bigtop-manager-ai-deepseek + ${project.artifactId} + Bigtop Manager AI DeepSeek + + + + org.apache.bigtop + bigtop-manager-ai-core + ${revision} + + + + dev.langchain4j + langchain4j-open-ai + + + diff --git a/bigtop-manager-ai/bigtop-manager-ai-deepseek/src/main/java/org/apache/bigtop/manager/ai/deepseek/DeepSeekAssistant.java b/bigtop-manager-ai/bigtop-manager-ai-deepseek/src/main/java/org/apache/bigtop/manager/ai/deepseek/DeepSeekAssistant.java new file mode 100644 index 00000000..25557ba7 --- /dev/null +++ b/bigtop-manager-ai/bigtop-manager-ai-deepseek/src/main/java/org/apache/bigtop/manager/ai/deepseek/DeepSeekAssistant.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.bigtop.manager.ai.deepseek; + +import org.apache.bigtop.manager.ai.core.AbstractAIAssistant; +import org.apache.bigtop.manager.ai.core.enums.PlatformType; +import org.apache.bigtop.manager.ai.core.factory.AIAssistant; + +import dev.langchain4j.internal.ValidationUtils; +import dev.langchain4j.memory.ChatMemory; +import dev.langchain4j.model.chat.ChatLanguageModel; +import dev.langchain4j.model.chat.StreamingChatLanguageModel; +import dev.langchain4j.model.openai.OpenAiChatModel; +import dev.langchain4j.model.openai.OpenAiStreamingChatModel; +import dev.langchain4j.service.AiServices; + +public class DeepSeekAssistant extends AbstractAIAssistant { + + private static final String BASE_URL = "https://api.deepseek.com/v1"; + + public DeepSeekAssistant(ChatMemory chatMemory, AIAssistant.Service aiServices) { + super(chatMemory, aiServices); + } + + @Override + public PlatformType getPlatform() { + return PlatformType.DEEPSEEK; + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractAIAssistant.Builder { + + @Override + public ChatLanguageModel getChatLanguageModel() { + String model = ValidationUtils.ensureNotNull(config.getModel(), "model"); + String apiKey = + ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey"); + return OpenAiChatModel.builder() + .apiKey(apiKey) + .baseUrl(BASE_URL) + .modelName(model) + .build(); + } + + @Override + public StreamingChatLanguageModel getStreamingChatLanguageModel() { + String model = ValidationUtils.ensureNotNull(config.getModel(), "model"); + String apiKey = + ValidationUtils.ensureNotNull(config.getCredentials().get("apiKey"), "apiKey"); + return OpenAiStreamingChatModel.builder() + .apiKey(apiKey) + .baseUrl(BASE_URL) + .modelName(model) + .build(); + } + + public AIAssistant build() { + AIAssistant.Service aiService = AiServices.builder(AIAssistant.Service.class) + .chatLanguageModel(getChatLanguageModel()) + .streamingChatLanguageModel(getStreamingChatLanguageModel()) + .chatMemory(getChatMemory()) + .toolProvider(toolProvider) + .systemMessageProvider(threadId -> { + if (threadId != null) { + return systemPrompt; + } + return null; + }) + .build(); + return new DeepSeekAssistant(getChatMemory(), aiService); + } + } +} diff --git a/bigtop-manager-ai/pom.xml b/bigtop-manager-ai/pom.xml index d1ee182e..971bdf68 100644 --- a/bigtop-manager-ai/pom.xml +++ b/bigtop-manager-ai/pom.xml @@ -34,6 +34,7 @@ bigtop-manager-ai-openai bigtop-manager-ai-dashscope bigtop-manager-ai-qianfan + bigtop-manager-ai-deepseek bigtop-manager-ai-core bigtop-manager-ai-assistant diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/LLMConfigServiceImpl.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/LLMConfigServiceImpl.java index 1ca5558e..5e67c1c4 100644 --- a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/LLMConfigServiceImpl.java +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/service/impl/LLMConfigServiceImpl.java @@ -339,7 +339,8 @@ private Boolean testFuncCalling(String platformName, String model, Map${project.version} + + org.apache.bigtop + bigtop-manager-ai-deepseek + ${project.version} + + org.apache.bigtop bigtop-manager-ai-assistant