From 7bc5003674ca30c025c694d2c07a9bf1f2ea73f8 Mon Sep 17 00:00:00 2001 From: zhaoyingbo Date: Mon, 2 Dec 2024 09:00:44 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E5=89=AA=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E5=B9=B6=E6=B8=85=E7=90=86=E5=A4=A7=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E5=93=8D=E5=BA=94=E4=BB=A5=E4=BC=98=E5=8C=96=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/groupAgent/agent.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/controller/groupAgent/agent.ts b/controller/groupAgent/agent.ts index b994960..a1c18f4 100644 --- a/controller/groupAgent/agent.ts +++ b/controller/groupAgent/agent.ts @@ -45,7 +45,7 @@ const agent = async (ctx: Context.Data) => { logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`) // 根据Mention,拼装原始消息 - let userInput = rawMsgText + let userInput = rawMsgText.trim() for (const mention of mentions ?? []) { if (mention.name !== appInfo.app_name) { userInput = userInput.replace(mention.key, `@${mention.name}`) @@ -57,7 +57,7 @@ const agent = async (ctx: Context.Data) => { // 调用大模型 try { await updateCard(cardGender.genPendingCard("LLM激情输出中,请稍等...")) - const llmRes = await llm.invoke( + const llmRes = (await llm.invoke( "groupAgent", { userName: historyMentions.get(openId || "") ?? "用户", @@ -66,11 +66,14 @@ const agent = async (ctx: Context.Data) => { time: new Date().toLocaleString("zh-CN", { timeZone: "Asia/Shanghai" }), }, requestId - ) + )) as string logger.info( `LLM invoked successfully, see detail: http://langfuse.ai.srv/project/cm1j2tkj9001gukrgdvc1swuw/sessions/${requestId}` ) - await updateCard(cardGender.genSuccessCard(llmRes)) + const cleanedLlmRes = llmRes + .replace(/```(\w+)?\n([\s\S]*?)```/g, "$2") + .trim() + await updateCard(cardGender.genSuccessCard(cleanedLlmRes)) } catch (error: any) { logger.error(`Failed to invoke llm: ${error.message}`) await updateCard(cardGender.genErrorCard("LLM调用失败: " + error.message))