From 9802f0137ffa1dd08fa8bd8f010d224391eab38a Mon Sep 17 00:00:00 2001 From: zhouwentao <1577701412@qq.com> Date: Tue, 11 Jun 2024 15:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- updateLogs/20240611.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 updateLogs/20240611.md diff --git a/updateLogs/20240611.md b/updateLogs/20240611.md new file mode 100644 index 0000000..e5d98ab --- /dev/null +++ b/updateLogs/20240611.md @@ -0,0 +1,36 @@ +### 抖音回复消息 接入AI +```shell +live-chat-client-codec/live-chat-client-codec-douyin/src/main/java/tech/ordinaryroad/live/chat/client/codec/douyin/api/DouyinApis.java +#源代码 +File jsFile = new File("D:\\workspace\\ordinaryroad-live-chat-client\\live-chat-client-codec\\live-chat-client-codec-douyin\\src\\main\\resources\\a-bogus.js"); +#改为从项目resources目录获取文件 +String bogus_path = DouyinApis.class.getClassLoader().getResource("a-bogus.js").getPath(); +File jsFile = new File(bogus_path); +``` + +#### 添加fastGPT的API调用工具 tech.ordinaryroad.live.chat.client.commons.util.AiChatUtil.java +```shell +# tech.ordinaryroad.live.chat.client.douyin.client.DouyinLiveChatClientTest.java +# 添加配置 屏蔽回复消息用户 +static List shieldUserIdList = new ArrayList<>();//屏蔽回复用户id +static List shieldNickNameList = new ArrayList<>();//屏蔽回复用户昵称 +### +# 判断是否回复方法 DouyinLiveChatClientTest.contentIsVaild +# return true/false 回复/不需要回复 +### +# 具体对接代码 +//TODO 接受到的用户消息,判断是否需要回复 +String content = msg.getContent(); +//先判断 该消息是否需要回复 +if (contentIsVaild(binaryFrameHandler,msg) && !(shieldUserIdList.contains(msg.getUid())) && !(shieldNickNameList.contains(msg.getUsername()))) { + //调用chat 获取回答消息 + String replyMessage = AiChatUtil.formatCompletionOutContent(AiChatUtil.chatCompletions(content)); + if(StringUtils.isNotBlank(replyMessage)){ + //发送 + client.sendDanmu(replyMessage, () -> { + log.warn("弹幕发送成功"); + }); + } +} +``` +####