Skip to content

Commit

Permalink
BIGTOP-4340: Add DeepSeek LLM Platform
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Jan 25, 2025
1 parent 22c4336 commit 0fa069a
Show file tree
Hide file tree
Showing 10 changed files with 167 additions and 6 deletions.
4 changes: 4 additions & 0 deletions bigtop-manager-ai/bigtop-manager-ai-assistant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
public enum PlatformType {
OPENAI("openai"),
DASH_SCOPE("dashscope"),
QIANFAN("qianfan");
QIANFAN("qianfan"),
DEEPSEEK("deepseek");

private final String value;

Expand Down
44 changes: 44 additions & 0 deletions bigtop-manager-ai/bigtop-manager-ai-deepseek/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.bigtop</groupId>
<artifactId>bigtop-manager-ai</artifactId>
<version>${revision}</version>
</parent>

<artifactId>bigtop-manager-ai-deepseek</artifactId>
<name>${project.artifactId}</name>
<description>Bigtop Manager AI DeepSeek</description>

<dependencies>
<dependency>
<groupId>org.apache.bigtop</groupId>
<artifactId>bigtop-manager-ai-core</artifactId>
<version>${revision}</version>
</dependency>

<dependency>
<groupId>dev.langchain4j</groupId>
<artifactId>langchain4j-open-ai</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
1 change: 1 addition & 0 deletions bigtop-manager-ai/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ private PlatformType getPlatformType(String platformName) {

private Boolean testAuthorization(String platformName, String model, Map<String, String> 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 {
Expand Down Expand Up @@ -339,7 +339,8 @@ private Boolean testFuncCalling(String platformName, String model, Map<String, S
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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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';
WHERE `name` = 'QianFan';

UPDATE `llm_platform`
SET `desc` = 'Get your API Key in https://platform.deepseek.com'
WHERE `name` = 'DeepSeek';
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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';
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 0fa069a

Please sign in to comment.