AI默认切换成DeepSeek v3模型,提供更优的速度和质量

This commit is contained in:
JEECG
2025-01-14 21:51:39 +08:00
parent d9737c891f
commit 8fc27bb261
7 changed files with 64 additions and 68 deletions

View File

@ -9,6 +9,7 @@ import com.unfbx.chatgpt.entity.chat.Message;
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 class ChatServiceImpl implements ChatService {
@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 class ChatServiceImpl implements ChatService {
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------------
}