Merge remote-tracking branch 'origin/chat'

This commit is contained in:
zhaoyuhang
2023-07-02 23:37:38 +08:00
3 changed files with 20 additions and 19 deletions

View File

@@ -65,11 +65,11 @@ wx:
aesKey: ${mallchat.wx.aesKey} # 接口配置里的EncodingAESKey值
chatai:
chatgpt:
use: false
use: true
AIUserId: 10452
key: xxxxx
key: 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
chatglm2:
use: false
url: xxxxx
use: true
url: http://vastmiao.natapp1.cc
minute: 3 # 每个用户每3分钟可以请求一次
AIUserId: 10451

View File

@@ -2,6 +2,7 @@ package com.abin.mallchat.custom.chatai.handler;
import cn.hutool.http.HttpResponse;
import com.abin.mallchat.common.chat.domain.entity.Message;
import com.abin.mallchat.common.chat.domain.entity.msg.MessageExtra;
import com.abin.mallchat.common.common.constant.RedisKey;
import com.abin.mallchat.common.common.utils.RedisUtils;
import com.abin.mallchat.custom.chatai.properties.ChatGLM2Properties;
@@ -10,6 +11,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.Arrays;
import java.util.Date;
@@ -69,11 +71,11 @@ public class ChatGLM2Handler extends AbstractChatAIHandler {
.prompt(content)
.timeout(glm2Properties.getTimeout())
.send();
text = ChatGLM2Utils.parseText(response);
} catch (Exception e) {
e.printStackTrace();
return getErrorText();
}
text = ChatGLM2Utils.parseText(response);
if (StringUtils.isNotBlank(text)) {
RedisUtils.set(RedisKey.getKey(USER_GLM2_TIME_LAST, uid), new Date(), glm2Properties.getMinute(), TimeUnit.MINUTES);
}
@@ -116,17 +118,16 @@ public class ChatGLM2Handler extends AbstractChatAIHandler {
return false;
}
/* 前端传@信息后取消注释 */
// MessageExtra extra = message.getExtra();
// if (extra == null) {
// return false;
// }
// if (CollectionUtils.isEmpty(extra.getAtUidList())) {
// return false;
// }
// if (!extra.getAtUidList().contains(glm2Properties.getAIUserId())) {
// return false;
// }
MessageExtra extra = message.getExtra();
if (extra == null) {
return false;
}
if (CollectionUtils.isEmpty(extra.getAtUidList())) {
return false;
}
if (!extra.getAtUidList().contains(glm2Properties.getAIUserId())) {
return false;
}
if (StringUtils.isBlank(message.getContent())) {
return false;

View File

@@ -17,8 +17,8 @@ public class ChatAIServiceImpl implements IChatAIService {
if (extra == null) {
return;
}
AbstractChatAIHandler chatAI = ChatAIHandlerFactory.getChatAIHandlerByName(message.getContent());
// AbstractChatAIHandler chatAI = ChatAIHandlerFactory.getChatAIHandlerById(extra.getAtUidList());
// AbstractChatAIHandler chatAI = ChatAIHandlerFactory.getChatAIHandlerByName(message.getContent());
AbstractChatAIHandler chatAI = ChatAIHandlerFactory.getChatAIHandlerById(extra.getAtUidList());
if (chatAI != null) {
chatAI.chat(message);
}