feat: 添加原始消息处理功能以支持提及用户

This commit is contained in:
zhaoyingbo 2024-12-02 03:16:43 +00:00
parent 99d9360bd5
commit 4a88bf6aa3

View File

@ -8,7 +8,7 @@ const agent = async (ctx: Context.Data) => {
requestId, requestId,
larkCard, larkCard,
larkService, larkService,
larkBody: { messageId, msgText, chatId, mentions }, larkBody: { messageId, msgText, chatId, mentions, rawMsgText },
} = ctx } = ctx
const cardGender = larkCard.child("groupAgent") const cardGender = larkCard.child("groupAgent")
// 回复一个loading的卡片 // 回复一个loading的卡片
@ -40,12 +40,20 @@ const agent = async (ctx: Context.Data) => {
} }
logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`) logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`)
// 根据Mention拼装原始消息
let userInput = rawMsgText
for (const mention of mentions ?? []) {
if (mention.id.user_id) {
userInput = userInput.replace(mention.key, mention.name)
}
}
// 调用大模型 // 调用大模型
try { try {
const llmRes = await llm.invoke( const llmRes = await llm.invoke(
"groupAgent", "groupAgent",
{ {
userInput: msgText, userInput,
chatHistory: JSON.stringify(chatHistory), chatHistory: JSON.stringify(chatHistory),
time: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" }), time: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" }),
}, },