From 0fa069ad59058a85003feae16d09c9b8b732b9eb Mon Sep 17 00:00:00 2001
From: lhpqaq <657407891@qq.com>
Date: Sat, 25 Jan 2025 13:33:44 +0800
Subject: [PATCH 1/3] BIGTOP-4340: Add DeepSeek LLM Platform
---
.../bigtop-manager-ai-assistant/pom.xml | 4 +
.../ai/assistant/GeneralAssistantFactory.java | 2 +
.../manager/ai/core/enums/PlatformType.java | 3 +-
.../bigtop-manager-ai-deepseek/pom.xml | 44 +++++++++
.../ai/deepseek/DeepSeekAssistant.java | 92 +++++++++++++++++++
bigtop-manager-ai/pom.xml | 1 +
.../service/impl/LLMConfigServiceImpl.java | 5 +-
.../main/resources/ddl/MySQL-DDL-CREATE.sql | 9 +-
.../resources/ddl/PostgreSQL-DDL-CREATE.sql | 7 +-
pom.xml | 6 ++
10 files changed, 167 insertions(+), 6 deletions(-)
create mode 100644 bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml
create mode 100644 bigtop-manager-ai/bigtop-manager-ai-deepseek/src/main/java/org/apache/bigtop/manager/ai/deepseek/DeepSeekAssistant.java
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-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..eabce0ad 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
@@ -303,7 +303,7 @@ private PlatformType getPlatformType(String platformName) {
private Boolean testAuthorization(String platformName, String model, Map credentials) {
Boolean result = testFuncCalling(platformName, model, credentials);
- log.info("Test func calling result: {}", result);
+ log.info(" result: {}", result);
GeneralAssistantConfig generalAssistantConfig = getAIAssistantConfig(platformName, model, credentials);
AIAssistant aiAssistant = aiAssistantFactory.createForTest(generalAssistantConfig, null);
try {
@@ -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
From 79de73d175b52e26ed96083ee4a2639736de9555 Mon Sep 17 00:00:00 2001
From: lhpqaq <657407891@qq.com>
Date: Sat, 25 Jan 2025 13:35:17 +0800
Subject: [PATCH 2/3] fix log
---
.../manager/server/service/impl/LLMConfigServiceImpl.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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 eabce0ad..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
@@ -303,7 +303,7 @@ private PlatformType getPlatformType(String platformName) {
private Boolean testAuthorization(String platformName, String model, Map credentials) {
Boolean result = testFuncCalling(platformName, model, credentials);
- log.info(" result: {}", result);
+ log.info("Test func calling result: {}", result);
GeneralAssistantConfig generalAssistantConfig = getAIAssistantConfig(platformName, model, credentials);
AIAssistant aiAssistant = aiAssistantFactory.createForTest(generalAssistantConfig, null);
try {
From 7e760e292afafc4bca5634bb4c07dd3a3d306800 Mon Sep 17 00:00:00 2001
From: lhpqaq <657407891@qq.com>
Date: Sun, 26 Jan 2025 13:51:14 +0800
Subject: [PATCH 3/3] add ut
---
.../apache/bigtop/manager/ai/core/enums/PlatformTypeTest.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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"));