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))