From de0067ec1798523c45c37b81c39495d138c500c9 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Mon, 2 Dec 2024 08:08:04 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=E8=81=8A=E5=A4=A9?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8F=91=E9=80=81=E8=80=85ID=E5=B9=B6?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=8F=90=E5=8F=8A=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bun.lockb | Bin 164153 -> 164153 bytes controller/groupAgent/agent.ts | 20 +++++++++++++------- controller/groupAgent/chatHistory.ts | 21 ++++++++++++++++++--- controller/groupAgent/report.ts | 2 +- package.json | 2 +- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/bun.lockb b/bun.lockb index 4dc163abbb748ec8f5f1d633a1d2211e8f9b89a3..7332b94ec2ff279231b1c5cda4d1b317678fdc78 100755 GIT binary patch delta 170 zcmV;b09F6Ff(p5U3Xm=!mI-jH07&%ZN$6amFyFowRgl3%R1}CjEb~;ctDI{#u}+pe z0TPqZ8Y`2~Aqle?Jsglg21s_Rt^Y+zk(8;tTa5>`6s75qp`L6*y+as)+_@y2^a*_5 zwmKG%9Oct}hBI~q;Ucm&Jzh`k;U~XcBn0zYgLTcfbo-pxHpnA^G1^#9PB~E6%#xgLTcfb { larkCard, larkService, appInfo, - larkBody: { messageId, msgText, chatId, mentions, rawMsgText }, + larkBody: { messageId, msgText, chatId, mentions, rawMsgText, openId }, } = ctx const cardGender = larkCard.child("groupAgent") // 回复一个loading的卡片 @@ -28,12 +28,14 @@ const agent = async (ctx: Context.Data) => { // 更新卡片 updateCard(cardGender.genPendingCard("正在爬楼中,请稍等...")) // 获取聊天记录 - const chatHistory = await getChatHistory(ctx, { - chatId, - startTime, - endTime, - mentions, - }) + const { messages: chatHistory, mentions: historyMentions } = + await getChatHistory(ctx, { + chatId, + startTime, + endTime, + mentions, + senderOpenId: openId, + }) // 如果没有聊天记录,返回错误信息 if (chatHistory.length === 0) { logger.info("No chat history found") @@ -51,6 +53,10 @@ const agent = async (ctx: Context.Data) => { } } + // 获取发送者的名字 + const userName = historyMentions.get(openId || "") ?? "用户" + userInput = `${userName}:${userInput}` + // 调用大模型 try { await updateCard(cardGender.genPendingCard("LLM激情输出中,请稍等...")) diff --git a/controller/groupAgent/chatHistory.ts b/controller/groupAgent/chatHistory.ts index 61e2088..8201821 100644 --- a/controller/groupAgent/chatHistory.ts +++ b/controller/groupAgent/chatHistory.ts @@ -48,14 +48,19 @@ const getChatHistory = async ( chatId, startTime, endTime, + senderOpenId, mentions: targetUsers, }: { chatId: string startTime: string endTime: string + senderOpenId?: string mentions?: LarkEvent.Mention[] } -): Promise => { +): Promise<{ + messages: Message[] + mentions: Map +}> => { // 获取服务器的时区偏移量(以分钟为单位) const serverTimezoneOffset = new Date().getTimezoneOffset() // 上海时区的偏移量(UTC+8,以分钟为单位) @@ -76,7 +81,12 @@ const getChatHistory = async ( String(startTimeTimestamp), String(endTimeTimestamp) ) - if (chatHistory.length === 0) return [] + + if (chatHistory.length === 0) + return { + messages: [], + mentions: new Map(), + } const targetUsersSet = new Set( targetUsers @@ -88,6 +98,8 @@ const getChatHistory = async ( // 取出所有的被AT的人,以及发送者 const mentions: Map = new Map() const senders: Set = new Set() + // 先把提问者加进去 + if (senderOpenId) senders.add(senderOpenId) // 过滤出文本和post消息 const allowedMsgTypes = ["text", "post"] const filteredMsg: typeof chatHistory = [] @@ -194,7 +206,10 @@ const getChatHistory = async ( }) } - return messages + return { + messages, + mentions, + } } export default getChatHistory diff --git a/controller/groupAgent/report.ts b/controller/groupAgent/report.ts index 8838179..1ef2a94 100644 --- a/controller/groupAgent/report.ts +++ b/controller/groupAgent/report.ts @@ -49,7 +49,7 @@ const genReport = async ( const processStart = Date.now() // 获取聊天记录 - const chatHistory = await getChatHistory( + const { messages: chatHistory } = await getChatHistory( { larkService, logger } as Context.Data, { chatId, diff --git a/package.json b/package.json index 81a663e..b472a07 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "dependencies": { "@egg/hooks": "^1.2.0", - "@egg/lark-msg-tool": "^1.17.0", + "@egg/lark-msg-tool": "^1.18.0", "@egg/logger": "^1.6.0", "@egg/net-tool": "^1.19.0", "@egg/path-tool": "^1.4.1",