From 8fc27bb26106491bd59a666dd8372a4dd2a829ed Mon Sep 17 00:00:00 2001
From: JEECG <445654970@qq.com>
Date: Tue, 14 Jan 2025 21:51:39 +0800
Subject: [PATCH] =?UTF-8?q?AI=E9=BB=98=E8=AE=A4=E5=88=87=E6=8D=A2=E6=88=90?=
=?UTF-8?q?DeepSeek=20v3=E6=A8=A1=E5=9E=8B=EF=BC=8C=E6=8F=90=E4=BE=9B?=
=?UTF-8?q?=E6=9B=B4=E4=BC=98=E7=9A=84=E9=80=9F=E5=BA=A6=E5=92=8C=E8=B4=A8?=
=?UTF-8?q?=E9=87=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../gpt/service/impl/ChatServiceImpl.java | 19 +++++++----
.../src/main/resources/application-dev.yml | 32 +++++++------------
.../src/main/resources/application-dm8.yml | 31 +++++++-----------
.../main/resources/application-kingbase8.yml | 21 ++++--------
.../src/main/resources/application-prod.yml | 7 ++++
.../src/main/resources/application-test.yml | 18 +++++++----
jeecg-boot/pom.xml | 4 +--
7 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/gpt/service/impl/ChatServiceImpl.java b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/gpt/service/impl/ChatServiceImpl.java
index d116520e4f..1a7fe752c2 100644
--- a/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/gpt/service/impl/ChatServiceImpl.java
+++ b/jeecg-boot/jeecg-module-demo/src/main/java/org/jeecg/modules/demo/gpt/service/impl/ChatServiceImpl.java
@@ -9,6 +9,7 @@
import com.unfbx.chatgpt.exception.BaseException;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
+import org.jeecg.chatgpt.prop.AiChatProperties;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
@@ -58,6 +59,11 @@ public class ChatServiceImpl implements ChatService {
private OpenAiStreamClient openAiStreamClient = null;
+ /**
+ * ai聊天配置
+ * for [QQYUN-10943]【AI 重要】jeecg-boot-starter-chatgpt 支持deepseek等国产模型
+ */
+ private AiChatProperties aiChatProperties;
//update-begin---author:chenrui ---date:20240131 for:[QQYUN-8212]fix 没有配置启动报错------------
/**
@@ -66,17 +72,17 @@ public class ChatServiceImpl implements ChatService {
* @author chenrui
* @date 2024/2/3 23:08
*/
- private OpenAiStreamClient ensureClient(){
+ private void ensureClient(){
if (null == this.openAiStreamClient){
//update-begin---author:chenrui ---date:20240625 for:[TV360X-1570]给于更友好的提示,提示未配置ai------------
try {
this.openAiStreamClient = SpringContextUtils.getBean(OpenAiStreamClient.class);
+ this.aiChatProperties = SpringContextUtils.getBean(AiChatProperties.class);
} catch (Exception ignored) {
sendErrorMsg("如果您想使用AI助手,请先设置相应配置!");
}
//update-end---author:chenrui ---date:20240625 for:[TV360X-1570]给于更友好的提示,提示未配置ai------------
}
- return this.openAiStreamClient;
}
//update-end---author:chenrui ---date:20240131 for:[QQYUN-8212]fix 没有配置启动报错------------
@@ -138,6 +144,7 @@ public void closeChat() {
@Override
public void sendMessage(String topicId, String message) {
+ ensureClient();
String uid = getUserId();
if (StrUtil.isBlank(message)) {
log.info("参数异常,message为null");
@@ -164,18 +171,16 @@ public void sendMessage(String topicId, String message) {
throw new JeecgBootException("聊天消息推送失败uid:[{}],没有创建连接,请重试。~");
}
//update-begin---author:chenrui ---date:20240625 for:[TV360X-1570]给于更友好的提示,提示未配置ai------------
- OpenAiStreamClient client = ensureClient();
- if (null != client) {
+ if (null != openAiStreamClient) {
OpenAISSEEventSourceListener openAIEventSourceListener = new OpenAISSEEventSourceListener(topicId, sseEmitter);
ChatCompletion completion = ChatCompletion
.builder()
.messages(msgHistory)
- .model(ChatCompletion.Model.GPT_3_5_TURBO.getName())
+ .model(aiChatProperties.getModel())
.build();
- client.streamChatCompletion(completion, openAIEventSourceListener);
+ openAiStreamClient.streamChatCompletion(completion, openAIEventSourceListener);
redisTemplate.opsForHash().put(cacheKey, CACHE_KEY_MSG_CONTEXT, JSONUtil.toJsonStr(msgHistory));
//update-end---author:chenrui ---date:20240223 for:[QQYUN-8225]聊天记录保存------------
- Result.ok(completion.tokens());
}
//update-end---author:chenrui ---date:20240625 for:[TV360X-1570]给于更友好的提示,提示未配置ai------------
}
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
index 34c7a54f3f..a3d064975b 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dev.yml
@@ -199,6 +199,13 @@ mybatis-plus:
minidao:
base-package: org.jeecg.modules.jmreport.*,org.jeecg.modules.drag.*
jeecg:
+ # AI集成
+ ai-chat:
+ enabled: true
+ model: deepseek-chat
+ apiKey: ??
+ apiHost: https://api.deepseek.com
+ timeout: 60
# 平台上线安全配置
firewall:
# 数据源安全 (开启后,Online报表和图表的数据源为必填)
@@ -240,11 +247,6 @@ jeecg:
SMS_465391221:
# 注册账号短信模板编码
SMS_175430166:
- # ElasticSearch 6设置
- elasticsearch:
- cluster-name: jeecg-ES
- cluster-nodes: 127.0.0.1:9200
- check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传
@@ -280,26 +282,16 @@ jeecg:
password:
type: STANDALONE
enabled: true
- # ai-chat
- ai-chat:
- # 是否开启;必须。
- enabled: false
- # openAi接口秘钥,填写自己的apiKey;必须。
- apiKey: "????"
- # openAi域名,有代理就填代理的域名。默认:openAI官方apiHost
- apiHost: "https://api.openai.com"
- # 超时时间单位:s。默认 60s
- timeout: 60
- # 本地代理地址
-# proxy:
-# host: "http://127.0.0.1"
-# port: "7890"
# 百度开放API配置
baidu-api:
app-id: ??
api-key: ??
secret-key: ??
-
+ # ElasticSearch 6设置
+ elasticsearch:
+ cluster-name: jeecg-ES
+ cluster-nodes: 127.0.0.1:9200
+ check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dm8.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dm8.yml
index b47c07b5ba..b739fb5fa7 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dm8.yml
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-dm8.yml
@@ -160,6 +160,13 @@ mybatis-plus:
minidao:
base-package: org.jeecg.modules.jmreport.*,org.jeecg.modules.drag.*
jeecg:
+ # AI集成
+ ai-chat:
+ enabled: true
+ model: deepseek-chat
+ apiKey: ??
+ apiHost: https://api.deepseek.com
+ timeout: 60
# 平台上线安全配置
firewall:
# 数据源安全 (开启后,Online报表和图表的数据源为必填)
@@ -189,11 +196,6 @@ jeecg:
secretKey: ??
endpoint: oss-cn-beijing.aliyuncs.com
bucketName: jeecgdev
- # ElasticSearch 6设置
- elasticsearch:
- cluster-name: jeecg-ES
- cluster-nodes: 127.0.0.1:9200
- check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://fileview.jeecg.com
# minio文件上传
@@ -229,20 +231,11 @@ jeecg:
password:
type: STANDALONE
enabled: true
- # ai-chat
- ai-chat:
- # 是否开启;必须。
- enabled: false
- # openAi接口秘钥,填写自己的apiKey;必须。
- apiKey: "????"
- # openAi域名,有代理就填代理的域名。默认:openAI官方apiHost
- apiHost: "https://api.openai.com"
- # 超时时间单位:s。默认 60s
- timeout: 60
- # 本地代理地址
-# proxy:
-# host: "http://127.0.0.1"
-# port: "7890"
+ # ElasticSearch 6设置
+ elasticsearch:
+ cluster-name: jeecg-ES
+ cluster-nodes: 127.0.0.1:9200
+ check-enabled: false
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-kingbase8.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-kingbase8.yml
index b75b9748ca..8069e6f1e6 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-kingbase8.yml
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-kingbase8.yml
@@ -174,6 +174,13 @@ mybatis-plus:
minidao:
base-package: org.jeecg.modules.jmreport.*,org.jeecg.modules.drag.*
jeecg:
+ # AI集成
+ ai-chat:
+ enabled: true
+ model: deepseek-chat
+ apiKey: ??
+ apiHost: https://api.deepseek.com
+ timeout: 60
# 平台上线安全配置
firewall:
# 数据源安全 (开启后,Online报表和图表的数据源为必填)
@@ -243,20 +250,6 @@ jeecg:
password:
type: STANDALONE
enabled: true
- # ai-chat
- ai-chat:
- # 是否开启;必须。
- enabled: false
- # openAi接口秘钥,填写自己的apiKey;必须。
- apiKey: "????"
- # openAi域名,有代理就填代理的域名。默认:openAI官方apiHost
- apiHost: "https://api.openai.com"
- # 超时时间单位:s。默认 60s
- timeout: 60
- # 本地代理地址
-# proxy:
-# host: "http://127.0.0.1"
-# port: "7890"
#cas单点登录
cas:
prefixUrl: http://cas.example.org:8443/cas
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml
index 2b7539de4e..e51b09493b 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-prod.yml
@@ -199,6 +199,13 @@ mybatis-plus:
minidao:
base-package: org.jeecg.modules.jmreport.*,org.jeecg.modules.drag.*
jeecg:
+ # AI集成
+ ai-chat:
+ enabled: true
+ model: deepseek-chat
+ apiKey: ??
+ apiHost: https://api.deepseek.com
+ timeout: 60
# 平台上线安全配置
firewall:
# 数据源安全 (开启后,Online报表和图表的数据源为必填)
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml
index 3549c6d0fb..94019a7f4f 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-start/src/main/resources/application-test.yml
@@ -199,6 +199,13 @@ mybatis-plus:
minidao:
base-package: org.jeecg.modules.jmreport.*,org.jeecg.modules.drag.*
jeecg:
+ # AI集成
+ ai-chat:
+ enabled: true
+ model: deepseek-chat
+ apiKey: ??
+ apiHost: https://api.deepseek.com
+ timeout: 60
# 平台上线安全配置
firewall:
# 数据源安全 (开启后,Online报表和图表的数据源为必填)
@@ -241,11 +248,6 @@ jeecg:
SMS_465391221:
# 注册账号短信模板编码
SMS_175430166:
- # ElasticSearch 设置
- elasticsearch:
- cluster-name: jeecg-ES
- cluster-nodes: 192.168.1.188:9200
- check-enabled: false
# 在线预览文件服务器地址配置
file-view-domain: http://127.0.0.1:8012
# minio文件上传
@@ -286,7 +288,11 @@ jeecg:
app-id: ??
api-key: ??
secret-key: ??
-
+ # ElasticSearch 设置
+ elasticsearch:
+ cluster-name: jeecg-ES
+ cluster-nodes: 192.168.1.188:9200
+ check-enabled: false
#Mybatis输出sql日志
logging:
level:
diff --git a/jeecg-boot/pom.xml b/jeecg-boot/pom.xml
index abeaf7cba7..26be88bd6f 100644
--- a/jeecg-boot/pom.xml
+++ b/jeecg-boot/pom.xml
@@ -414,11 +414,11 @@
jimubi-spring-boot-starter
${jimureport-spring-boot-starter.version}
-
+
org.jeecgframework.boot
jeecg-boot-starter-chatgpt
- ${jeecgboot.version}
+ 3.7.3