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("弹幕发送成功"); + }); + } +} +``` +####