This is an automated email from the ASF dual-hosted git repository.

wuzhiguo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git


The following commit(s) were added to refs/heads/main by this push:
     new 59103b4b BIGTOP-4340: Add DeepSeek LLM Platform (#160)
59103b4b is described below

commit 59103b4b6ae0175bf7a312dced0da0afd0593f0c
Author: haopeng <[email protected]>
AuthorDate: Sun Jan 26 14:49:28 2025 +0800

    BIGTOP-4340: Add DeepSeek LLM Platform (#160)
---
 .../bigtop-manager-ai-assistant/pom.xml            |  4 +
 .../ai/assistant/GeneralAssistantFactory.java      |  2 +
 .../bigtop/manager/ai/core/enums/PlatformType.java |  3 +-
 .../manager/ai/core/enums/PlatformTypeTest.java    |  4 +-
 .../pom.xml                                        | 32 ++------
 .../manager/ai/deepseek/DeepSeekAssistant.java     | 92 ++++++++++++++++++++++
 bigtop-manager-ai/pom.xml                          |  1 +
 .../server/service/impl/LLMConfigServiceImpl.java  |  3 +-
 .../src/main/resources/ddl/MySQL-DDL-CREATE.sql    |  9 ++-
 .../main/resources/ddl/PostgreSQL-DDL-CREATE.sql   |  7 +-
 pom.xml                                            |  6 ++
 11 files changed, 130 insertions(+), 33 deletions(-)

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 @@
             <groupId>org.apache.bigtop</groupId>
             <artifactId>bigtop-manager-ai-qianfan</artifactId>
         </dependency>
+        <dependency>
+            <groupId>org.apache.bigtop</groupId>
+            <artifactId>bigtop-manager-ai-deepseek</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.apache.bigtop</groupId>
             <artifactId>bigtop-manager-dao</artifactId>
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.exception.AssistantConfigNotSetExceptio
 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 @@ public class GeneralAssistantFactory extends 
AbstractAIAssistantFactory {
             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 @@ import java.util.stream.Collectors;
 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<String> 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 class PlatformTypeTest {
         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-assistant/pom.xml 
b/bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml
similarity index 60%
copy from bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml
copy to bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml
index b04e793e..f62ecd31 100644
--- a/bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml
+++ b/bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml
@@ -23,44 +23,22 @@
         <groupId>org.apache.bigtop</groupId>
         <artifactId>bigtop-manager-ai</artifactId>
         <version>${revision}</version>
-        <relativePath>../pom.xml</relativePath>
     </parent>
 
-    <artifactId>bigtop-manager-ai-assistant</artifactId>
+    <artifactId>bigtop-manager-ai-deepseek</artifactId>
     <name>${project.artifactId}</name>
-    <description>Bigtop Manager AI Assistant</description>
+    <description>Bigtop Manager AI DeepSeek</description>
 
     <dependencies>
-        <dependency>
-            <groupId>org.apache.bigtop</groupId>
-            <artifactId>bigtop-manager-ai-openai</artifactId>
-        </dependency>
         <dependency>
             <groupId>org.apache.bigtop</groupId>
             <artifactId>bigtop-manager-ai-core</artifactId>
+            <version>${revision}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.bigtop</groupId>
-            <artifactId>bigtop-manager-ai-dashscope</artifactId>
-            <exclusions>
-                <exclusion>
-                    <groupId>org.slf4j</groupId>
-                    <artifactId>slf4j-simple</artifactId>
-                </exclusion>
-            </exclusions>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.bigtop</groupId>
-            <artifactId>bigtop-manager-ai-qianfan</artifactId>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.bigtop</groupId>
-            <artifactId>bigtop-manager-dao</artifactId>
-        </dependency>
+
         <dependency>
             <groupId>dev.langchain4j</groupId>
-            <artifactId>langchain4j-reactor</artifactId>
+            <artifactId>langchain4j-open-ai</artifactId>
         </dependency>
     </dependencies>
-
 </project>
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 @@
         <module>bigtop-manager-ai-openai</module>
         <module>bigtop-manager-ai-dashscope</module>
         <module>bigtop-manager-ai-qianfan</module>
+        <module>bigtop-manager-ai-deepseek</module>
         <module>bigtop-manager-ai-core</module>
         <module>bigtop-manager-ai-assistant</module>
     </modules>
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 @@ public class LLMConfigServiceImpl implements 
LLMConfigService {
         try {
             return aiAssistant.ask("What is the flag of " + 
TEST_KEY).contains(TEST_FLAG);
         } catch (Exception e) {
-            throw new ApiException(ApiExceptionEnum.CREDIT_INCORRECT, 
e.getMessage());
+            log.error("Test function calling failed", e);
+            return false;
         }
     }
 
diff --git a/bigtop-manager-server/src/main/resources/ddl/MySQL-DDL-CREATE.sql 
b/bigtop-manager-server/src/main/resources/ddl/MySQL-DDL-CREATE.sql
index e9f91e53..28a75131 100644
--- a/bigtop-manager-server/src/main/resources/ddl/MySQL-DDL-CREATE.sql
+++ b/bigtop-manager-server/src/main/resources/ddl/MySQL-DDL-CREATE.sql
@@ -348,7 +348,8 @@ INSERT INTO llm_platform (credential, name, support_models)
 VALUES
 ('{"apiKey": "API Key"}', 'OpenAI', 
'gpt-3.5-turbo,gpt-4,gpt-4o,gpt-3.5-turbo-16k,gpt-4-turbo-preview,gpt-4-32k,gpt-4o-mini'),
 ('{"apiKey": "API Key"}', 'DashScope', 
'qwen-1.8b-chat,qwen-max,qwen-plus,qwen-turbo'),
-('{"apiKey": "API Key", "secretKey": "Secret Key"}', 
'QianFan','Yi-34B-Chat,ERNIE-4.0-8K,ERNIE-3.5-128K,ERNIE-Speed-8K,Llama-2-7B-Chat,Fuyu-8B');
+('{"apiKey": "API Key", "secretKey": "Secret Key"}', 
'QianFan','Yi-34B-Chat,ERNIE-4.0-8K,ERNIE-3.5-128K,ERNIE-Speed-8K,Llama-2-7B-Chat,Fuyu-8B'),
+('{"apiKey": "API Key"}','DeepSeek','deepseek-chat,deepseek-reasoner');
 
 UPDATE `llm_platform`
 SET `desc` = 'Get your API Key in https://platform.openai.com/api-keys'
@@ -360,4 +361,8 @@ WHERE `name` = 'DashScope';
 
 UPDATE `llm_platform`
 SET `desc` = 'Get API Key and Secret Key in 
https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application/v1'
-WHERE `name` = 'QianFan';
\ No newline at end of file
+WHERE `name` = 'QianFan';
+
+UPDATE `llm_platform`
+SET `desc` = 'Get your API Key in https://platform.deepseek.com'
+WHERE `name` = 'DeepSeek';
\ No newline at end of file
diff --git 
a/bigtop-manager-server/src/main/resources/ddl/PostgreSQL-DDL-CREATE.sql 
b/bigtop-manager-server/src/main/resources/ddl/PostgreSQL-DDL-CREATE.sql
index a8180144..7f745b96 100644
--- a/bigtop-manager-server/src/main/resources/ddl/PostgreSQL-DDL-CREATE.sql
+++ b/bigtop-manager-server/src/main/resources/ddl/PostgreSQL-DDL-CREATE.sql
@@ -360,7 +360,8 @@ INSERT INTO llm_platform (credential, name, support_models)
 VALUES
 ('{"apiKey": "API 
Key"}','OpenAI','gpt-3.5-turbo,gpt-4,gpt-4o,gpt-3.5-turbo-16k,gpt-4-turbo-preview,gpt-4-32k,gpt-4o-mini'),
 ('{"apiKey": "API 
Key"}','DashScope','qwen-1.8b-chat,qwen-max,qwen-plus,qwen-turbo'),
-('{"apiKey": "API Key", "secretKey": "Secret 
Key"}','QianFan','Yi-34B-Chat,ERNIE-4.0-8K,ERNIE-3.5-128K,ERNIE-Speed-8K,Llama-2-7B-Chat,Fuyu-8B');
+('{"apiKey": "API Key", "secretKey": "Secret 
Key"}','QianFan','Yi-34B-Chat,ERNIE-4.0-8K,ERNIE-3.5-128K,ERNIE-Speed-8K,Llama-2-7B-Chat,Fuyu-8B'),
+('{"apiKey": "API Key"}','DeepSeek','deepseek-chat,deepseek-reasoner');
 
 UPDATE llm_platform
 SET "desc" = 'Get your API Key in https://platform.openai.com/api-keys'
@@ -373,3 +374,7 @@ WHERE "name" = 'DashScope';
 UPDATE llm_platform
 SET "desc" = 'Get API Key and Secret Key in 
https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application/v1'
 WHERE "name" = 'QianFan';
+
+UPDATE llm_platform
+SET "desc" = 'Get your API Key in https://platform.deepseek.com'
+WHERE "name" = 'DeepSeek';
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index f6875303..86bbd6e9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -154,6 +154,12 @@
                 <version>${project.version}</version>
             </dependency>
 
+            <dependency>
+                <groupId>org.apache.bigtop</groupId>
+                <artifactId>bigtop-manager-ai-deepseek</artifactId>
+                <version>${project.version}</version>
+            </dependency>
+
             <dependency>
                 <groupId>org.apache.bigtop</groupId>
                 <artifactId>bigtop-manager-ai-assistant</artifactId>

Reply via email to