From 824d3b78c745b3f176cfff7d0faa8962961ee3ee Mon Sep 17 00:00:00 2001 From: zhaoyuhang <1045078399@qq.com> Date: Sat, 1 Jul 2023 21:13:49 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E4=BD=BF=E7=94=A8id?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=9C=BA=E5=99=A8=E4=BA=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 4 +-- .../chatai/handler/ChatGLM2Handler.java | 25 ++++++++++--------- .../service/impl/ChatAIServiceImpl.java | 4 +-- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/mallchat-common/src/main/resources/application.yml b/mallchat-common/src/main/resources/application.yml index 2df7f5b..6f13a61 100644 --- a/mallchat-common/src/main/resources/application.yml +++ b/mallchat-common/src/main/resources/application.yml @@ -65,11 +65,11 @@ wx: aesKey: ${mallchat.wx.aesKey} # 接口配置里的EncodingAESKey值 chatai: chatgpt: - use: false + use: true AIUserId: 10452 key: xxxxx chatglm2: - use: false + use: true url: xxxxx minute: 3 # 每个用户每3分钟可以请求一次 AIUserId: 10451 diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/handler/ChatGLM2Handler.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/handler/ChatGLM2Handler.java index 13aecfd..11350ca 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/handler/ChatGLM2Handler.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/handler/ChatGLM2Handler.java @@ -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; diff --git a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/service/impl/ChatAIServiceImpl.java b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/service/impl/ChatAIServiceImpl.java index 37af88e..885c227 100644 --- a/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/service/impl/ChatAIServiceImpl.java +++ b/mallchat-custom-server/src/main/java/com/abin/mallchat/custom/chatai/service/impl/ChatAIServiceImpl.java @@ -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); } From 6dd7b21b39f92d54a4fa4cc1ab522d5b28442788 Mon Sep 17 00:00:00 2001 From: zhaoyuhang <1045078399@qq.com> Date: Sun, 2 Jul 2023 23:34:03 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=90=88=E5=B9=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mallchat-common/src/main/resources/application.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mallchat-common/src/main/resources/application.yml b/mallchat-common/src/main/resources/application.yml index 6f13a61..270d74f 100644 --- a/mallchat-common/src/main/resources/application.yml +++ b/mallchat-common/src/main/resources/application.yml @@ -38,7 +38,7 @@ spring: # 连接超时时间 timeout: 1800000 # # 设置密码 -# password: ${mallchat.redis.password} + password: ${mallchat.redis.password} lettuce: pool: # 最大阻塞等待时间,负数表示没有限制 @@ -67,9 +67,9 @@ chatai: chatgpt: use: true AIUserId: 10452 - key: xxxxx + key: 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 chatglm2: use: true - url: xxxxx + url: http://vastmiao.natapp1.cc minute: 3 # 每个用户每3分钟可以请求一次 - AIUserId: 10451 +