Compare commits
5 Commits
d2168377a7
...
a94be10d02
Author | SHA1 | Date | |
---|---|---|---|
a94be10d02 | |||
277963436b | |||
8385b12886 | |||
7e00a5ee59 | |||
1dbfca4057 |
20
bun.lock
20
bun.lock
@ -5,9 +5,9 @@
|
||||
"name": "egg_server",
|
||||
"dependencies": {
|
||||
"@egg/hooks": "^1.2.0",
|
||||
"@egg/lark-msg-tool": "^1.21.0",
|
||||
"@egg/logger": "^1.6.0",
|
||||
"@egg/net-tool": "^1.32.2",
|
||||
"@egg/lark-msg-tool": "^1.21.2",
|
||||
"@egg/logger": "^1.7.1",
|
||||
"@egg/net-tool": "^1.32.4",
|
||||
"@egg/path-tool": "^1.4.1",
|
||||
"@langchain/core": "^0.3.42",
|
||||
"@langchain/langgraph": "^0.2.56",
|
||||
@ -101,11 +101,11 @@
|
||||
|
||||
"@egg/hooks": ["@egg/hooks@1.2.0", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Fhooks/-/1.2.0/hooks-1.2.0.tgz", { "dependencies": { "lodash": "*" } }, "sha512-pH9SViGCvdNHdXIpeqqgGODYPxq0HF+b0obKxcC11O1TT6QEpDRWgImZPRdFz0SwxG9VKjJFD+MuZpXmzar+kg=="],
|
||||
|
||||
"@egg/lark-msg-tool": ["@egg/lark-msg-tool@1.21.0", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Flark-msg-tool/-/1.21.0/lark-msg-tool-1.21.0.tgz", { "dependencies": { "@egg/logger": "^1.6.0", "winston": "*" } }, "sha512-+Vz56wgb9BBiAowmXCdcsLMKTQoBrXADalDAbI9PiLswIw6gAgQtoy8bixIiyGuKM0QB8McVBbvzc04ukJhUKw=="],
|
||||
"@egg/lark-msg-tool": ["@egg/lark-msg-tool@1.21.4", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Flark-msg-tool/-/1.21.4/lark-msg-tool-1.21.4.tgz", { "dependencies": { "@egg/logger": "^1.9.0", "winston": "*" } }, "sha512-ylKcAkuoJkTy99RYM4YRS6HfahtRDaW7XCavHPydvWDH6SYhvOurDMWZnrteR+Qef0oo2Id4Ekyu69laW+q9Yg=="],
|
||||
|
||||
"@egg/logger": ["@egg/logger@1.6.0", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Flogger/-/1.6.0/logger-1.6.0.tgz", { "dependencies": { "winston": "*", "winston-daily-rotate-file": "*" } }, "sha512-BgtK74YK/7q/K3iUs3FGp3B+v4/IJlD9bgrJ/S7iHwgtgMgzl/4avZ5sXNHoZ7xPRhEuOh0ie7Br3MAWFnuuYg=="],
|
||||
"@egg/logger": ["@egg/logger@1.9.0", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Flogger/-/1.9.0/logger-1.9.0.tgz", { "dependencies": { "winston": "*" } }, "sha512-rV/p4JnbsyVYdHWzvJpv/W3AWV3Mz5z0KU6iNH5JQAp2As6Rs70Sr8YKSY9f8+qpbyvS9BHX6vuf1BOM9fyI6Q=="],
|
||||
|
||||
"@egg/net-tool": ["@egg/net-tool@1.32.2", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Fnet-tool/-/1.32.2/net-tool-1.32.2.tgz", { "dependencies": { "@egg/logger": "^1.6.0", "@gitbeaker/rest": "*", "winston": "*" } }, "sha512-e0iWiVob2DTIKfIDNCgBH9zp7B/MquWvHKmb7DH1lJa6YeyA0Nhp8h3EYZBUTwrUzUyaY83qqMXBJYgjg5zkKA=="],
|
||||
"@egg/net-tool": ["@egg/net-tool@1.32.6", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Fnet-tool/-/1.32.6/net-tool-1.32.6.tgz", { "dependencies": { "@egg/logger": "^1.9.0", "@gitbeaker/rest": "*", "winston": "*" } }, "sha512-FN0OVsBxsATunJNyKXnL7Z0k9sXlOX7nxE+cfz2jRYalO+bPgAbWyy/6kos0c6xwkmMouZgi+E/XaEi1ZW7amA=="],
|
||||
|
||||
"@egg/path-tool": ["@egg/path-tool@1.4.1", "https://git.yingbo.im:333/api/packages/zhaoyingbo/npm/%40egg%2Fpath-tool/-/1.4.1/path-tool-1.4.1.tgz", {}, "sha512-PZE5kMRidZh3ahhmQJQG62wcApbCdmZihKQXYI5eAOhIbwm0hgB1sOUsais94sS9uEBQ+QpH0Om7sZ9w84rumw=="],
|
||||
|
||||
@ -401,8 +401,6 @@
|
||||
|
||||
"file-entry-cache": ["file-entry-cache@8.0.0", "", { "dependencies": { "flat-cache": "^4.0.0" } }, "sha512-XXTUwCvisa5oacNGRP9SfNtYBNAMi+RPwBFmblZEF7N7swHYQS6/Zfk7SRwx4D5j3CH211YNRco1DEMNVfZCnQ=="],
|
||||
|
||||
"file-stream-rotator": ["file-stream-rotator@0.6.1", "", { "dependencies": { "moment": "^2.29.1" } }, "sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ=="],
|
||||
|
||||
"fill-range": ["fill-range@7.1.1", "", { "dependencies": { "to-regex-range": "^5.0.1" } }, "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg=="],
|
||||
|
||||
"find-up": ["find-up@5.0.0", "", { "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" } }, "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng=="],
|
||||
@ -599,8 +597,6 @@
|
||||
|
||||
"minimist": ["minimist@1.2.8", "", {}, "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA=="],
|
||||
|
||||
"moment": ["moment@2.30.1", "", {}, "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how=="],
|
||||
|
||||
"ms": ["ms@2.1.3", "", {}, "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA=="],
|
||||
|
||||
"mustache": ["mustache@4.2.0", "", { "bin": { "mustache": "bin/mustache" } }, "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="],
|
||||
@ -617,8 +613,6 @@
|
||||
|
||||
"nwsapi": ["nwsapi@2.2.18", "", {}, "sha512-p1TRH/edngVEHVbwqWnxUViEmq5znDvyB+Sik5cmuLpGOIfDf/39zLiq3swPF8Vakqn+gvNiOQAZu8djYlQILA=="],
|
||||
|
||||
"object-hash": ["object-hash@3.0.0", "", {}, "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="],
|
||||
|
||||
"object-inspect": ["object-inspect@1.13.4", "", {}, "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew=="],
|
||||
|
||||
"one-time": ["one-time@1.0.0", "", { "dependencies": { "fn.name": "1.x.x" } }, "sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g=="],
|
||||
@ -803,8 +797,6 @@
|
||||
|
||||
"winston": ["winston@3.17.0", "", { "dependencies": { "@colors/colors": "^1.6.0", "@dabh/diagnostics": "^2.0.2", "async": "^3.2.3", "is-stream": "^2.0.0", "logform": "^2.7.0", "one-time": "^1.0.0", "readable-stream": "^3.4.0", "safe-stable-stringify": "^2.3.1", "stack-trace": "0.0.x", "triple-beam": "^1.3.0", "winston-transport": "^4.9.0" } }, "sha512-DLiFIXYC5fMPxaRg832S6F5mJYvePtmO5G9v9IgUFPhXm9/GkXarH/TUrBAVzhTCzAj9anE/+GjrgXp/54nOgw=="],
|
||||
|
||||
"winston-daily-rotate-file": ["winston-daily-rotate-file@5.0.0", "", { "dependencies": { "file-stream-rotator": "^0.6.1", "object-hash": "^3.0.0", "triple-beam": "^1.4.1", "winston-transport": "^4.7.0" }, "peerDependencies": { "winston": "^3" } }, "sha512-JDjiXXkM5qvwY06733vf09I2wnMXpZEhxEVOSPenZMii+g7pcDcTBt2MRugnoi8BwVSuCT2jfRXBUy+n1Zz/Yw=="],
|
||||
|
||||
"winston-transport": ["winston-transport@4.9.0", "", { "dependencies": { "logform": "^2.7.0", "readable-stream": "^3.6.2", "triple-beam": "^1.3.0" } }, "sha512-8drMJ4rkgaPo1Me4zD/3WLfI/zPdA9o2IipKODunnGDcuqbHwjsbB79ylv04LCGGzU0xQ6vTznOMpQGaLhhm6A=="],
|
||||
|
||||
"word-wrap": ["word-wrap@1.2.5", "", {}, "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA=="],
|
||||
|
@ -30,13 +30,14 @@ const initAppConfig = async () => {
|
||||
for (const env of envList) {
|
||||
APP_CONFIG[env.key] = env.value
|
||||
}
|
||||
logger.info(`Get env list: ${JSON.stringify(APP_CONFIG)}`)
|
||||
logger.info("获取环境变量列表", { envList: APP_CONFIG })
|
||||
|
||||
// 获取所有应用信息
|
||||
const appList = await pbClient.collection<AppInfoModel>("app").getFullList()
|
||||
for (const app of appList) {
|
||||
APP_MAP[app.name] = app
|
||||
}
|
||||
logger.info(`Get app list: ${JSON.stringify(APP_MAP)}`)
|
||||
logger.info("获取应用列表", { appList: APP_MAP })
|
||||
}
|
||||
|
||||
export default initAppConfig
|
||||
|
@ -45,7 +45,7 @@ const openFunc = async (
|
||||
const { logger, larkBody, larkService, larkCard, db } = ctx
|
||||
const cardGender = larkCard.child("gitlabAgent")
|
||||
if (!projectId) {
|
||||
logger.error(`项目ID格式错误,项目ID:${projectId}`)
|
||||
logger.error("项目ID格式错误", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genErrorCard("项目ID格式错误,请检查项目ID是否正确")
|
||||
@ -57,7 +57,7 @@ const openFunc = async (
|
||||
ctx.gitlabService
|
||||
)
|
||||
if (!project) {
|
||||
logger.error(`项目不存在,项目ID:${projectId}`)
|
||||
logger.error("项目不存在", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genErrorCard(
|
||||
@ -70,7 +70,7 @@ const openFunc = async (
|
||||
[func]: true,
|
||||
})
|
||||
if (!newProj) {
|
||||
logger.error(`更新项目失败,项目ID:${projectId}`)
|
||||
logger.error("更新项目失败", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genErrorCard("操作失败,请稍后再试")
|
||||
@ -94,7 +94,7 @@ const closeFunc = async (
|
||||
const { logger, larkBody, larkService, larkCard, db } = ctx
|
||||
const cardGender = larkCard.child("gitlabAgent")
|
||||
if (!projectId) {
|
||||
logger.error(`项目ID格式错误,项目ID:${projectId}`)
|
||||
logger.error("项目ID格式错误", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genErrorCard("项目ID格式错误,请检查项目ID是否正确")
|
||||
@ -103,7 +103,7 @@ const closeFunc = async (
|
||||
}
|
||||
const project = await db.gitlabProject.getByProjectId(projectId)
|
||||
if (!project) {
|
||||
logger.error(`项目不存在,项目ID:${projectId}`)
|
||||
logger.error("项目不存在", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genSuccessCard(
|
||||
@ -116,7 +116,7 @@ const closeFunc = async (
|
||||
[func]: false,
|
||||
})
|
||||
if (!newProj) {
|
||||
logger.error(`更新项目失败,项目ID:${projectId}`)
|
||||
logger.error("更新项目失败", { projectId })
|
||||
await larkService.message.replyCard(
|
||||
larkBody.messageId,
|
||||
cardGender.genErrorCard("操作失败,请稍后再试")
|
||||
|
@ -18,7 +18,7 @@ const agent = async (ctx: Context) => {
|
||||
)
|
||||
// 使用大模型解析用户输入
|
||||
const { startTime, endTime } = await llm.timeParser(msgText, requestId)
|
||||
logger.info(`Parsed time: startTime: ${startTime}, endTime: ${endTime}`)
|
||||
logger.info("解析的时间范围", { startTime, endTime })
|
||||
// 更新卡片
|
||||
await message.updateOrReply(
|
||||
cardGender.genPendingCard("正在爬楼中,请稍等...")
|
||||
@ -35,7 +35,7 @@ const agent = async (ctx: Context) => {
|
||||
excludedMessageIds: [loadingMessageId, messageId],
|
||||
excludeMentions: [appInfo.appName],
|
||||
})
|
||||
logger.debug(`Chat history: ${JSON.stringify(chatHistory)}`)
|
||||
logger.debug("获取的聊天记录", { count: chatHistory.length })
|
||||
|
||||
// 根据Mention,拼装原始消息
|
||||
let userInput = rawMsgText.trim()
|
||||
@ -62,13 +62,14 @@ const agent = async (ctx: Context) => {
|
||||
},
|
||||
requestId
|
||||
)) as string
|
||||
logger.info(
|
||||
`LLM invoked successfully, see detail: http://langfuse.ai.srv/project/cm1j2tkj9001gukrgdvc1swuw/sessions/${requestId}`
|
||||
)
|
||||
logger.info("LLM调用成功", {
|
||||
requestId,
|
||||
url: `http://langfuse.ai.srv/project/cm1j2tkj9001gukrgdvc1swuw/sessions/${requestId}`,
|
||||
})
|
||||
const cleanedLlmRes = cleanLLMRes(llmRes)
|
||||
await message.updateOrReply(cardGender.genSuccessCard(cleanedLlmRes))
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to invoke llm: ${error.message}`)
|
||||
logger.error("LLM调用失败", { error: error.message })
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard("LLM调用失败: " + error.message)
|
||||
)
|
||||
|
@ -165,9 +165,13 @@ const getChatHistory = async (
|
||||
[...senders].filter((sender) => !mentions.has(sender))
|
||||
)
|
||||
|
||||
logger.debug(`Mentions: ${JSON.stringify([...mentions.entries()])}`)
|
||||
logger.debug(`Senders: ${JSON.stringify([...senders])}`)
|
||||
logger.debug(`No mention senders: ${JSON.stringify([...noMentionSenders])}`)
|
||||
logger.debug("获取聊天消息提及用户信息", {
|
||||
mentions: [...mentions.entries()],
|
||||
})
|
||||
logger.debug("获取消息发送者信息", { senders: [...senders] })
|
||||
logger.debug("获取未被提及的发送者信息", {
|
||||
noMentionSenders: [...noMentionSenders],
|
||||
})
|
||||
|
||||
// 从接口获取用户名
|
||||
if (noMentionSenders.size !== 0) {
|
||||
@ -175,13 +179,13 @@ const getChatHistory = async (
|
||||
const {
|
||||
data: { items },
|
||||
} = await larkService.user.batchGet([...noMentionSenders])
|
||||
logger.debug(`Get user info: ${JSON.stringify(items)}`)
|
||||
logger.debug("获取用户详细信息", { items })
|
||||
for (const item of items) {
|
||||
mentions.set(item.open_id, item.name)
|
||||
}
|
||||
} catch (error) {
|
||||
// 报错了可以不处理,只是没有名字而已
|
||||
logger.error(`Failed to get user info: ${error}`)
|
||||
logger.error("获取用户信息失败", { error })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,7 +26,7 @@ const genSummary = async (
|
||||
appInfo,
|
||||
larkService: { message },
|
||||
} = ctx
|
||||
logger.info(`genSummary ${timeScope} by ${trigger}`)
|
||||
logger.info("生成摘要", { timeScope, trigger })
|
||||
const cardGender = larkCard.child("groupAgent")
|
||||
try {
|
||||
if (trigger === "manual") {
|
||||
@ -128,7 +128,7 @@ const genSummary = async (
|
||||
const genAllReport = async (timeScope: "daily" | "weekly" = "daily") => {
|
||||
const ctx = await genContextManually()
|
||||
const { logger, db } = ctx
|
||||
logger.info(`genAllReport ${timeScope}`)
|
||||
logger.info("生成所有群聊总结", { timeScope })
|
||||
try {
|
||||
// 获取所有需要自动总结的群组
|
||||
const chatList = await db.chat.getNeedSummaryChats("all")
|
||||
@ -163,7 +163,7 @@ const gen4Test = async (ctx: Context, timeScope: "daily" | "weekly") => {
|
||||
larkBody: { chatId },
|
||||
} = ctx
|
||||
try {
|
||||
logger.info(`timeScope: ${timeScope}`)
|
||||
logger.info("手动生成日报或者周报", { timeScope })
|
||||
// 总结
|
||||
await genSummary(ctx, timeScope, "manual")
|
||||
} catch (error: any) {
|
||||
|
@ -100,13 +100,13 @@ const agent = async (ctx: Context): Promise<Intent> => {
|
||||
if (parsedIntent) {
|
||||
try {
|
||||
IntentSchema.parse(parsedIntent)
|
||||
logger.debug("Intent is valid: " + JSON.stringify(parsedIntent))
|
||||
logger.debug("意图验证有效", { intent: parsedIntent })
|
||||
return parsedIntent
|
||||
} catch (e: any) {
|
||||
logger.error("Invalid intent: " + String(e.errors))
|
||||
logger.error("意图验证失败", { error: String(e.errors) })
|
||||
}
|
||||
} else {
|
||||
logger.error("Parsed intent is null")
|
||||
logger.error("意图解析为空", { rawIntent })
|
||||
}
|
||||
|
||||
attempts++
|
||||
|
@ -96,7 +96,12 @@ const insert2Sheet = async (
|
||||
],
|
||||
])
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed to insert2Sheet: ${error}`)
|
||||
logger.error("表格数据插入失败", {
|
||||
error: error.message,
|
||||
link,
|
||||
sheetToken,
|
||||
range,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -222,7 +227,11 @@ const agent = async (ctx: Context, link: string, userDescription: string) => {
|
||||
)
|
||||
)
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed gen report: ${error}`)
|
||||
logger.error("简报生成失败", {
|
||||
error: error.message,
|
||||
link,
|
||||
userDescription,
|
||||
})
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard(`简报生成失败: ${error.message}`)
|
||||
)
|
||||
@ -233,7 +242,7 @@ const agent = async (ctx: Context, link: string, userDescription: string) => {
|
||||
* 解析表格信息
|
||||
* @param {Context} ctx - 上下文对象
|
||||
* @param {string} sheetUrl - 表格链接
|
||||
* @returns {Promise<{sheetToken: string, range: string}>} - 返回表格信息
|
||||
* @returns {Promise<{ sheetToken: string; range: string }>} - 返回表格信息
|
||||
* @throws {Error} - 当解析失败时抛出错误
|
||||
*/
|
||||
const parseSheetInfo = async (
|
||||
@ -306,7 +315,7 @@ const setSheet = async (ctx: Context, sheetUrl: string) => {
|
||||
cardGender.genSuccessCard("简报汇总表创建成功")
|
||||
)
|
||||
} catch (error: any) {
|
||||
logger.error(`Failed setSheet: ${error}`)
|
||||
logger.error("简报汇总表设置失败", { error: error.message, sheetUrl })
|
||||
await larkService.message.updateOrReply(
|
||||
cardGender.genErrorCard(`简报汇总表设置失败: ${error.message}`)
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ const agent = async (ctx: Context, query: string) => {
|
||||
const answer = await generateAnswer(ctx, searchRes)
|
||||
await message.updateOrReply(cardGender.genSuccessCard(answer))
|
||||
} catch (error: any) {
|
||||
logger.error(`searchAgent error: ${error}`)
|
||||
logger.error("检索Agent调用失败", { error: error.message })
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard(`检索失败: ${error.message}`)
|
||||
)
|
||||
|
@ -32,7 +32,7 @@ const create = async ({
|
||||
|
||||
const token = `${fileToken}|${tableId}|${viewId}`
|
||||
|
||||
logger.info(`create KV bitable successfully: ${{ link, token }}`)
|
||||
logger.info("创建KV模板成功", { link, token })
|
||||
|
||||
return {
|
||||
code: 0,
|
||||
@ -95,7 +95,7 @@ const createFromEvent = async (ctx: Context) => {
|
||||
cardGender.genTempCard("createKVSuccess", createRes.data) as string
|
||||
)
|
||||
} catch (e: any) {
|
||||
logger.error(`create KV bitable failed: ${e.message}`)
|
||||
logger.error("创建KV模板失败", { error: e.message })
|
||||
larkService.message.sendCard2Chat(
|
||||
chatId,
|
||||
cardGender.genErrorCard(`创建失败:${e.message}`) as string
|
||||
|
@ -22,13 +22,13 @@ const startOrStopGame = async (
|
||||
} = ctx
|
||||
const cardGender = larkCard.child("soupAgent")
|
||||
if (!chatId) {
|
||||
logger.error("chatId is required")
|
||||
logger.error("缺少聊天ID", { chatId })
|
||||
return
|
||||
}
|
||||
// 获取正在进行中的游戏
|
||||
const activeGame = await db.soupGame.getActiveOneByChatId(chatId)
|
||||
if (!activeGame) {
|
||||
logger.info(`chatId: ${chatId} has no active game`)
|
||||
logger.info("没有找到活跃的游戏", { chatId })
|
||||
}
|
||||
// 停止游戏
|
||||
if (!value) {
|
||||
@ -40,10 +40,10 @@ const startOrStopGame = async (
|
||||
return
|
||||
}
|
||||
// 有进行中的游戏,关闭游戏
|
||||
logger.info(`chatId: ${chatId} is closing the game`)
|
||||
logger.info("正在关闭游戏", { chatId })
|
||||
const res = await db.soupGame.close(activeGame.id)
|
||||
if (!res) {
|
||||
logger.error(`chatId: ${chatId} failed to close the game`)
|
||||
logger.error("游戏关闭失败", { chatId })
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard(SoupGameMessage.startFailed)
|
||||
)
|
||||
@ -78,17 +78,17 @@ const startOrStopGame = async (
|
||||
|
||||
// 开始游戏,有进行中的游戏
|
||||
if (activeGame) {
|
||||
logger.info(`chatId: ${chatId} has an active game`)
|
||||
logger.info("已存在进行中的游戏", { chatId })
|
||||
await message.updateOrReply(
|
||||
cardGender.genSuccessCard(SoupGameMessage.hasStarted)
|
||||
)
|
||||
return
|
||||
}
|
||||
logger.info(`chatId: ${chatId} is starting a new game`)
|
||||
logger.info("开始新游戏", { chatId })
|
||||
// 没有进行中的游戏,开始新游戏
|
||||
const game = await attachService.startSoup()
|
||||
if (!game) {
|
||||
logger.error(`chatId: ${chatId} failed to start a new game`)
|
||||
logger.error("新游戏启动失败", { chatId })
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard(SoupGameMessage.startFailed)
|
||||
)
|
||||
@ -103,13 +103,13 @@ const startOrStopGame = async (
|
||||
}
|
||||
const res = await db.soupGame.create(newSoupGame)
|
||||
if (!res) {
|
||||
logger.error(`chatId: ${chatId} failed to create a new game`)
|
||||
logger.error("游戏创建失败", { chatId })
|
||||
await message.updateOrReply(
|
||||
cardGender.genErrorCard(SoupGameMessage.startFailed)
|
||||
)
|
||||
return
|
||||
}
|
||||
logger.info(`chatId: ${chatId} created a new game`)
|
||||
logger.info("新游戏创建成功", { chatId, gameId: res.id })
|
||||
// 回复用户模型的消息
|
||||
await message.updateOrReply(
|
||||
cardGender.genCard("markdownSuccessCard", {
|
||||
@ -137,7 +137,7 @@ const chat2Soup = async (ctx: Context) => {
|
||||
message.setReplyMessage(messageId, "text")
|
||||
const activeGame = await db.soupGame.getActiveOneByChatId(chatId)
|
||||
if (!activeGame) {
|
||||
logger.info(`chatId: ${chatId} has no active game`)
|
||||
logger.info("没有找到活跃的游戏", { chatId })
|
||||
return
|
||||
}
|
||||
await message.updateOrReply("模型生成中...")
|
||||
@ -148,7 +148,7 @@ const chat2Soup = async (ctx: Context) => {
|
||||
history: "",
|
||||
})
|
||||
if (!res) {
|
||||
logger.error(`chatId: ${chatId} failed to get soup result`)
|
||||
logger.error("获取汤面结果失败", { chatId })
|
||||
await message.updateOrReply(SoupGameMessage.chatFailed)
|
||||
return
|
||||
}
|
||||
|
@ -47,13 +47,26 @@ class PbToolBase<T extends RecordModel> {
|
||||
*
|
||||
* @template R - 返回结果类型
|
||||
* @param fn - 需要执行的异步函数
|
||||
* @param operation - 操作名称,用于日志记录
|
||||
* @returns 成功时返回执行结果,失败时返回 null 并记录错误
|
||||
*/
|
||||
protected managePbError = async <R>(fn: () => Promise<R>) => {
|
||||
protected managePbError = async <R>(
|
||||
fn: () => Promise<R>,
|
||||
operation: string
|
||||
) => {
|
||||
try {
|
||||
return await fn()
|
||||
const result = await fn()
|
||||
this.logger.debug(`PocketBase ${operation} 成功`, {
|
||||
collection: this.dbName,
|
||||
operation,
|
||||
})
|
||||
return result
|
||||
} catch (err: any) {
|
||||
this.logger.error(`pocketbase error: ${err.message}`)
|
||||
this.logger.error(`PocketBase ${operation} 失败`, {
|
||||
collection: this.dbName,
|
||||
operation,
|
||||
error: err.message,
|
||||
})
|
||||
return null
|
||||
}
|
||||
}
|
||||
@ -70,8 +83,10 @@ class PbToolBase<T extends RecordModel> {
|
||||
* ```
|
||||
*/
|
||||
public create = async (data: Partial<T>) => {
|
||||
return this.managePbError<T>(() =>
|
||||
this.pbClient.collection(this.dbName).create(data)
|
||||
this.logger.info(`创建记录`, { collection: this.dbName, data })
|
||||
return this.managePbError<T>(
|
||||
() => this.pbClient.collection(this.dbName).create(data),
|
||||
"create"
|
||||
)
|
||||
}
|
||||
|
||||
@ -89,8 +104,10 @@ class PbToolBase<T extends RecordModel> {
|
||||
* ```
|
||||
*/
|
||||
public get = async <R extends T = T>(id: string, options?: RecordOptions) => {
|
||||
return this.managePbError<R>(() =>
|
||||
this.pbClient.collection(this.dbName).getOne(id, options)
|
||||
this.logger.info(`获取记录`, { collection: this.dbName, id, options })
|
||||
return this.managePbError<R>(
|
||||
() => this.pbClient.collection(this.dbName).getOne(id, options),
|
||||
"get"
|
||||
)
|
||||
}
|
||||
|
||||
@ -113,8 +130,10 @@ class PbToolBase<T extends RecordModel> {
|
||||
data: Partial<T>,
|
||||
options?: RecordOptions
|
||||
) => {
|
||||
return this.managePbError<R>(() =>
|
||||
this.pbClient.collection(this.dbName).update(id, data, options)
|
||||
this.logger.info(`更新记录`, { collection: this.dbName, id, data, options })
|
||||
return this.managePbError<R>(
|
||||
() => this.pbClient.collection(this.dbName).update(id, data, options),
|
||||
"update"
|
||||
)
|
||||
}
|
||||
|
||||
@ -131,8 +150,10 @@ class PbToolBase<T extends RecordModel> {
|
||||
* ```
|
||||
*/
|
||||
public delete = async (id: string, options?: CommonOptions) => {
|
||||
return this.managePbError(() =>
|
||||
this.pbClient.collection(this.dbName).delete(id, options)
|
||||
this.logger.info(`删除记录`, { collection: this.dbName, id, options })
|
||||
return this.managePbError(
|
||||
() => this.pbClient.collection(this.dbName).delete(id, options),
|
||||
"delete"
|
||||
)
|
||||
}
|
||||
|
||||
@ -152,8 +173,15 @@ class PbToolBase<T extends RecordModel> {
|
||||
* ```
|
||||
*/
|
||||
public list = async <R extends T = T>(options?: RecordFullListOptions) => {
|
||||
return this.managePbError<R[]>(() =>
|
||||
this.pbClient.collection(this.dbName).getFullList(options)
|
||||
this.logger.info(`获取记录列表`, {
|
||||
collection: this.dbName,
|
||||
filter: options?.filter,
|
||||
sort: options?.sort,
|
||||
options,
|
||||
})
|
||||
return this.managePbError<R[]>(
|
||||
() => this.pbClient.collection(this.dbName).getFullList(options),
|
||||
"list"
|
||||
)
|
||||
}
|
||||
|
||||
@ -174,8 +202,15 @@ class PbToolBase<T extends RecordModel> {
|
||||
filter: string,
|
||||
options?: RecordListOptions
|
||||
) => {
|
||||
return this.managePbError<R>(() =>
|
||||
this.pbClient.collection(this.dbName).getFirstListItem(filter, options)
|
||||
this.logger.info(`获取第一条匹配记录`, {
|
||||
collection: this.dbName,
|
||||
filter,
|
||||
options,
|
||||
})
|
||||
return this.managePbError<R>(
|
||||
() =>
|
||||
this.pbClient.collection(this.dbName).getFirstListItem(filter, options),
|
||||
"getFirstOne"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -87,12 +87,12 @@ class ChatDB extends PbToolBase<ChatModel> {
|
||||
public getByCtx = async ({ larkService, larkBody }: Context) => {
|
||||
const { chatId } = larkBody
|
||||
if (!chatId) {
|
||||
this.logger.error(`chatId is empty`)
|
||||
this.logger.error("chatId 为空")
|
||||
return null
|
||||
}
|
||||
const chat = await this.getOneByChatId(chatId)
|
||||
if (chat) return chat
|
||||
this.logger.info(`chat ${chatId} not found, try to get from lark`)
|
||||
this.logger.info("群聊不在数据库里,尝试从飞书获取", { chatId })
|
||||
const chatInfo = await larkService.chat.getChatInfo(chatId)
|
||||
if (!chatInfo || chatInfo.code !== 0) return null
|
||||
const { name, avatar, chat_mode } = chatInfo.data
|
||||
|
33
index.ts
33
index.ts
@ -27,8 +27,14 @@ const bunServer = Bun.serve({
|
||||
path.exact("/sheet") ||
|
||||
path.startsWith("/micro_app")
|
||||
) {
|
||||
logger.info(`${req.method} ${req.url}`)
|
||||
logger.debug(`req body: ${ctx.text}`)
|
||||
// 使用结构化日志,适合JSON模式
|
||||
logger.info("收到请求", {
|
||||
method: req.method,
|
||||
url: req.url,
|
||||
})
|
||||
logger.debug("请求体内容", {
|
||||
body: ctx.text,
|
||||
})
|
||||
}
|
||||
// 逻辑处理
|
||||
try {
|
||||
@ -44,20 +50,29 @@ const bunServer = Bun.serve({
|
||||
if (path.startsWith("/v1")) return manageModelProxyReq(ctx)
|
||||
// 健康检查
|
||||
if (path.full("/health")) return genResp.healthCheck()
|
||||
// 错误模拟
|
||||
if (path.startsWith("/mock/400")) return genResp.badRequest("模拟错误400")
|
||||
if (path.startsWith("/mock/403")) return genResp.forbidden("模拟错误403")
|
||||
if (path.startsWith("/mock/404")) return genResp.notFound("模拟错误404")
|
||||
if (path.startsWith("/mock/500"))
|
||||
return genResp.serverError("模拟错误500")
|
||||
|
||||
// 其他
|
||||
return genResp.healthCheck("hello, there is egg, glade to serve you!")
|
||||
} catch (error: any) {
|
||||
// 错误处理
|
||||
logger.error(error.message)
|
||||
logger.error("服务器错误", {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
})
|
||||
return genResp.serverError(error.message || "server error")
|
||||
}
|
||||
},
|
||||
error(error) {
|
||||
logger.error(`Error: ${error}`)
|
||||
logger.error(`Stack: ${error.stack}`)
|
||||
return new Response("Internal Error", { status: 500 })
|
||||
},
|
||||
port: 3000,
|
||||
})
|
||||
|
||||
logger.info(`Listening on ${bunServer.hostname}:${bunServer.port}`)
|
||||
// 使用结构化日志记录服务启动信息
|
||||
logger.info("服务器启动", {
|
||||
hostname: bunServer.hostname,
|
||||
port: bunServer.port,
|
||||
})
|
||||
|
@ -38,9 +38,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@egg/hooks": "^1.2.0",
|
||||
"@egg/lark-msg-tool": "^1.21.0",
|
||||
"@egg/logger": "^1.6.0",
|
||||
"@egg/net-tool": "^1.32.2",
|
||||
"@egg/lark-msg-tool": "^1.21.4",
|
||||
"@egg/logger": "^1.9.0",
|
||||
"@egg/net-tool": "^1.32.6",
|
||||
"@egg/path-tool": "^1.4.1",
|
||||
"@langchain/core": "^0.3.42",
|
||||
"@langchain/langgraph": "^0.2.56",
|
||||
|
@ -14,7 +14,7 @@ const manageAction = async (ctx: Context) => {
|
||||
const { cardGroup } = actionValue as {
|
||||
cardGroup: keyof typeof GROUP_MAP
|
||||
}
|
||||
logger.info(`Got lark action cardGroup: ${cardGroup}`)
|
||||
logger.info("获取到飞书卡片Action", { cardGroup })
|
||||
if (!cardGroup) return
|
||||
const func = GROUP_MAP[cardGroup] as (ctx: Context) => Promise<any>
|
||||
if (!func) return
|
||||
|
@ -15,11 +15,11 @@ const filterIllegalMsg = async (ctx: Context): Promise<boolean> => {
|
||||
const { body, logger, larkService, larkBody } = ctx
|
||||
const { chatId, msgType, msgText } = larkBody
|
||||
// 没有chatId的消息不处理
|
||||
logger.info(`bot req chatId: ${chatId}`)
|
||||
logger.info("接收到机器人请求", { chatId })
|
||||
if (!chatId) return true
|
||||
|
||||
// 获取msgType
|
||||
logger.info(`bot req msgType: ${msgType}`)
|
||||
logger.info("处理机器人消息类型", { msgType })
|
||||
// 放行纯文本消息
|
||||
if (msgType === "text") {
|
||||
// 过滤艾特全体成员的消息
|
||||
@ -32,14 +32,14 @@ const filterIllegalMsg = async (ctx: Context): Promise<boolean> => {
|
||||
|
||||
// 发表情包就直接发回去
|
||||
if (msgType === "sticker") {
|
||||
logger.info(`got a sticker message, chatId: ${chatId}`)
|
||||
logger.info("收到表情包消息", { chatId })
|
||||
const content = body?.event?.message?.content
|
||||
larkService.message.send("chat_id", chatId, "sticker", content)
|
||||
}
|
||||
|
||||
// 非表情包其他的信息都不处理
|
||||
else {
|
||||
logger.info(`got a illegal message, chatId: ${chatId}`)
|
||||
logger.info("收到不支持的消息类型", { chatId, msgType })
|
||||
larkService.message.sendText2Chat(
|
||||
chatId,
|
||||
"哇!这是什么东东?我只懂普通文本啦![可爱]"
|
||||
@ -62,13 +62,13 @@ const manageIntent = async (ctx: Context) => {
|
||||
larkBody: { msgText, chatId },
|
||||
larkCard,
|
||||
} = ctx
|
||||
logger.info(`bot req text: ${msgText}`)
|
||||
logger.info("收到文本消息内容", { msgText })
|
||||
await message.updateOrReply(
|
||||
larkCard.genPendingCard("正在理解您的意图,请稍等...")
|
||||
)
|
||||
try {
|
||||
const intentRes = await intentAgent.agent(ctx)
|
||||
logger.info(`intentRes: ${JSON.stringify(intentRes)}`)
|
||||
logger.info("意图分析结果", { intentRes })
|
||||
// 链接总结
|
||||
if (intentAgent.isBriefing(intentRes)) {
|
||||
reportAgent
|
||||
@ -145,7 +145,7 @@ const manageIntent = async (ctx: Context) => {
|
||||
break
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(`manageIntent error: ${error}`)
|
||||
logger.error("意图分析处理失败", { error })
|
||||
await message.updateOrReply(larkCard.genErrorCard(`意图分析失败`))
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import { manageEventMsg } from "./eventMsg"
|
||||
* @returns {Promise<Response>} 返回响应对象
|
||||
*/
|
||||
export const manageBotReq = async (ctx: Context): Promise<Response> => {
|
||||
const { body, larkBody } = ctx
|
||||
const { body, larkBody, logger } = ctx
|
||||
|
||||
// 检查请求体是否为空
|
||||
if (!body) {
|
||||
@ -17,7 +17,7 @@ export const manageBotReq = async (ctx: Context): Promise<Response> => {
|
||||
|
||||
// 验证机器人
|
||||
if (body.type === "url_verification") {
|
||||
ctx.logger.info(`bot challenge: ${body.challenge}`)
|
||||
logger.info("机器人验证", { challenge: body.challenge })
|
||||
return Response.json({ challenge: body.challenge })
|
||||
}
|
||||
|
||||
|
@ -10,10 +10,10 @@ import { Context } from "../../types"
|
||||
*/
|
||||
const manageLogin = async (ctx: Context) => {
|
||||
const { req, genResp, logger, requestId } = ctx
|
||||
logger.info("micro app login")
|
||||
const url = new URL(req.url)
|
||||
const code = url.searchParams.get("code")
|
||||
const appName = url.searchParams.get("app_name")
|
||||
logger.info("小程序登录", { code, appName })
|
||||
if (!code) {
|
||||
return genResp.badRequest("code not found")
|
||||
}
|
||||
@ -38,7 +38,7 @@ const manageLogin = async (ctx: Context) => {
|
||||
message,
|
||||
} = await larkService.user.code2Login(code)
|
||||
|
||||
logger.debug(`get user session: ${JSON.stringify(data)}`)
|
||||
logger.debug("获取到用户信息", { data })
|
||||
|
||||
if (resCode !== 0) {
|
||||
return genResp.serverError(message)
|
||||
@ -54,9 +54,13 @@ const manageLogin = async (ctx: Context) => {
|
||||
*/
|
||||
const manageBatchUser = async (ctx: Context) => {
|
||||
const { body, genResp, logger, requestId } = ctx
|
||||
logger.info("batch get user info")
|
||||
if (!body) return genResp.badRequest("req body is empty")
|
||||
const { user_ids, user_id_type, app_name } = body
|
||||
logger.info("批量获取用户信息", {
|
||||
ids: user_ids,
|
||||
type: user_id_type,
|
||||
app: app_name,
|
||||
})
|
||||
if (!user_ids) {
|
||||
return genResp.badRequest("user_ids not found")
|
||||
}
|
||||
@ -83,7 +87,7 @@ const manageBatchUser = async (ctx: Context) => {
|
||||
user_id_type
|
||||
)
|
||||
|
||||
logger.debug(`batch get user info: ${JSON.stringify(data)}`)
|
||||
logger.debug("批量获取用户信息成功", { data })
|
||||
|
||||
if (code !== 0) {
|
||||
return genResp.serverError(message)
|
||||
|
@ -9,7 +9,7 @@ export const manageModelProxyReq = async (ctx: Context) => {
|
||||
const { req, headers, logger, path } = ctx
|
||||
if (!path.exact("/v1/models")) {
|
||||
const auth = headers.get("Authorization")
|
||||
logger.info(`Start Model Proxy, Authorization: ${auth}`)
|
||||
logger.info("开始模型代理转发", { Authorization: auth })
|
||||
if (!auth || auth !== "Bearer sk-21a2ce1c2ee94bc2933798eac1bbcadc") {
|
||||
return ctx.genResp.forbidden("Authorization required")
|
||||
}
|
||||
@ -46,7 +46,7 @@ export const manageModelProxyReq = async (ctx: Context) => {
|
||||
const { readable, writable } = new TransformStream()
|
||||
response.body
|
||||
?.pipeTo(writable)
|
||||
.catch((err) => logger.error("Stream error:", err))
|
||||
.catch((err) => logger.error("流式响应传输失败", { error: err.message }))
|
||||
|
||||
return new Response(readable, {
|
||||
status: response.status,
|
||||
|
@ -125,7 +125,7 @@ const translateHTML = async (ctx: Context, rawHtml: string) => {
|
||||
|
||||
const uniqueTexts = [...new Set(needTranslateText)]
|
||||
|
||||
logger.debug(`uniqueTexts: ${uniqueTexts}`)
|
||||
logger.debug("需要翻译的文本", { uniqueTexts })
|
||||
|
||||
// 翻译,拆分为多个请求以避免超长
|
||||
const chunkSize = 20
|
||||
@ -214,7 +214,7 @@ const writeHtml = async (html: string, version: number) => {
|
||||
const byteMonitor = async () => {
|
||||
const ctx = await genContextManually()
|
||||
const { logger, larkService, appInfo } = ctx
|
||||
logger.info("byteMonitor start")
|
||||
logger.info("开始翻译bytes.dev页面")
|
||||
try {
|
||||
const latestId = await getLatestId()
|
||||
if (!latestId) throw new Error("getLatestId empty")
|
||||
@ -229,12 +229,10 @@ const byteMonitor = async () => {
|
||||
`页面链接:https://mi-chat-fe.cnbj1.mi-fds.com/mi-chat-fe/bytes/${newId}.html`,
|
||||
"byteMonitor 更新"
|
||||
)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
const errorMessage = `byteMonitor error: ${error}`
|
||||
logger.error(errorMessage)
|
||||
} catch (error: any) {
|
||||
logger.error("bytes翻译失败", { error: error.message })
|
||||
} finally {
|
||||
logger.info("byteMonitor finished")
|
||||
logger.info("bytes翻译结束")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ const diffPbContent = async (title: string): Promise<boolean> => {
|
||||
*/
|
||||
const fmMonitor = async (): Promise<void> => {
|
||||
const { larkService, logger, appInfo } = await genContextManually()
|
||||
logger.info("fmMonitor start")
|
||||
logger.info("观棋有语监控开始")
|
||||
try {
|
||||
const title = await getLatestTitle()
|
||||
if (!title) throw new Error("getLatestTitle empty")
|
||||
@ -48,10 +48,10 @@ const fmMonitor = async (): Promise<void> => {
|
||||
title,
|
||||
"fmMonitor 节目更新"
|
||||
)
|
||||
logger.info("fmMonitor success")
|
||||
} catch (error) {
|
||||
logger.info("观棋有语监控成功")
|
||||
} catch (error: any) {
|
||||
logger.info("观棋有语监控失败", { error: error.message })
|
||||
const errorMessage = `fmMonitor error: ${error}`
|
||||
logger.error(errorMessage)
|
||||
await larkService.message.sendText2Chat(appInfo.errChatId, errorMessage)
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ const getScheduleStatus = () => {
|
||||
*/
|
||||
const sendZhongNotify = async () => {
|
||||
const { larkService, logger, appInfo } = await genContextManually()
|
||||
logger.info("sendZhongNotify start")
|
||||
logger.info("钟哥每日提醒开始")
|
||||
try {
|
||||
const status = getScheduleStatus()
|
||||
await larkService.message.sendText2Chat(
|
||||
@ -26,10 +26,10 @@ const sendZhongNotify = async () => {
|
||||
`钟哥今天是${status}哦~`,
|
||||
"zhongNotify 每日提醒"
|
||||
)
|
||||
logger.info("sendZhongNotify success")
|
||||
} catch (error) {
|
||||
logger.info("钟哥每日提醒发送成功")
|
||||
} catch (error: any) {
|
||||
logger.error("钟哥每日提醒发送失败", { error: error.message })
|
||||
const errorMessage = `sendZhongNotify error: ${error}`
|
||||
logger.error(errorMessage)
|
||||
await larkService.message.sendText2Chat(appInfo.errChatId, errorMessage)
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import initAppConfig from "../../constant/config"
|
||||
import DB from "../../db"
|
||||
import pbClient from "../../db/pbClient"
|
||||
import { genContextManually } from "../../utils/genContext"
|
||||
|
||||
await initAppConfig()
|
||||
|
||||
const ctx = await genContextManually()
|
||||
|
||||
const dbInstance = new DB(pbClient, ctx.logger)
|
||||
const dbInstance = new DB(ctx.logger)
|
||||
|
||||
const res = await dbInstance.apiKey.getWithApp("uwnpzb9hvoft28h")
|
||||
|
||||
|
@ -50,14 +50,14 @@ const invoke = async (
|
||||
try {
|
||||
result = await attemptInvoke()
|
||||
break
|
||||
} catch (e) {
|
||||
logger.error(`🚀 ~ invoke ~ attemptInvoke ~ e: ${e}`)
|
||||
} catch (e: any) {
|
||||
logger.error(`调用LLM模型失败`, { promptName, error: e.message })
|
||||
attempts++
|
||||
}
|
||||
} while (attempts < 3)
|
||||
|
||||
if (!result) {
|
||||
logger.error("Failed to invoke after 3 attempts")
|
||||
logger.error("多次调用LLM模型失败", { promptName, attempts: 3 })
|
||||
return ""
|
||||
}
|
||||
|
||||
@ -92,8 +92,8 @@ const timeParser = async (userInput: string, requestId: string) => {
|
||||
requestId
|
||||
)) as string
|
||||
return JSON.parse(res.replaceAll("`", ""))
|
||||
} catch (e) {
|
||||
logger.error(`🚀 ~ timeParser ~ invokeParser ~ e: ${e}`)
|
||||
} catch (e: any) {
|
||||
logger.error("时间解析失败", { userInput, error: e.message })
|
||||
// 如果解析失败,则返回空字符串
|
||||
return { s: "", e: "" }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user