feat: 全面优化系统 - 修复task1语法错误 + Bot超时保护 + 熔断重试 + Redis缓存 + SEO + 日志清理 + 内容质量评估
This commit is contained in:
@@ -548,18 +548,29 @@ async function callDeepSeek(prompt) {
|
||||
if (!jsonMatch) {
|
||||
throw new Error(`Could not parse JSON from response: ${text.substring(0, 200)}`);
|
||||
}
|
||||
let parsed;
|
||||
try {
|
||||
return JSON.parse(jsonMatch[0]);
|
||||
parsed = JSON.parse(jsonMatch[0]);
|
||||
} catch {
|
||||
const cleaned = jsonMatch[0]
|
||||
.replace(/,\s*}/g, "}")
|
||||
.replace(/,\s*]/g, "]");
|
||||
try {
|
||||
return JSON.parse(cleaned);
|
||||
parsed = JSON.parse(cleaned);
|
||||
} catch {
|
||||
throw new Error(`JSON parse failed after cleanup: ${jsonMatch[0].substring(0, 200)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 质量检查(仅对含 content 字段的结果)
|
||||
if (parsed.content) {
|
||||
const qa = assessContentQuality(parsed.content, parsed.title);
|
||||
if (!qa.pass) {
|
||||
console.warn(`${ts()} ⚠️ 质量不达标 (score=${qa.score}): ${qa.issues.join(", ")}`);
|
||||
}
|
||||
parsed._qualityScore = qa.score;
|
||||
}
|
||||
return parsed;
|
||||
}
|
||||
|
||||
async function getBotWithConfig(botKey) {
|
||||
@@ -1490,6 +1501,54 @@ async function runBotAutoLikes(botCharacters) {
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 内容质量评估 ============
|
||||
// 对 Bot 生成的内容进行简单质量检查,过滤低质量内容
|
||||
function assessContentQuality(content, title) {
|
||||
let score = 100;
|
||||
const issues = [];
|
||||
|
||||
// 1) 字数检查
|
||||
if (content.length < 100) { score -= 30; issues.push("内容过短(<100字)"); }
|
||||
else if (content.length < 150) { score -= 15; issues.push("内容偏短(<150字)"); }
|
||||
|
||||
// 2) AI 味检测:高频 AI 句式
|
||||
const aiPatterns = [
|
||||
/首先[,,].*其次[,,].*最后/,
|
||||
/从以下几个方面/,
|
||||
/综上所述/,
|
||||
/值得注意的是/,
|
||||
/不可否认/,
|
||||
/总而言之/,
|
||||
/让我们.*一起/,
|
||||
/在这个.*的时代/,
|
||||
];
|
||||
for (const pat of aiPatterns) {
|
||||
if (pat.test(content)) { score -= 15; issues.push(`AI句式: ${pat.source}`); }
|
||||
}
|
||||
|
||||
// 3) 重复标题检测(与内容前100字相似度)
|
||||
if (title && content) {
|
||||
const titleWords = new Set(title.split(""));
|
||||
const contentStart = content.substring(0, 100);
|
||||
let overlap = 0;
|
||||
for (const w of titleWords) {
|
||||
if (w.trim() && contentStart.includes(w)) overlap++;
|
||||
}
|
||||
const titleLen = [...titleWords].filter(w => w.trim()).length;
|
||||
if (titleLen > 0 && overlap / titleLen > 0.8) {
|
||||
score -= 20; issues.push("标题与内容高度重复");
|
||||
}
|
||||
}
|
||||
|
||||
// 4) 结尾是否有引导讨论的问题
|
||||
const lastSentence = content.split(/[。!?\n]/).filter(Boolean).pop() || "";
|
||||
if (!/[??]/.test(lastSentence) && !/大家|你们|你们觉得|怎么看/.test(lastSentence)) {
|
||||
score -= 5; issues.push("结尾缺少互动引导");
|
||||
}
|
||||
|
||||
return { score: Math.max(0, score), issues, pass: score >= 60 };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log(`${ts()} Bot Activity Engine starting...`);
|
||||
|
||||
@@ -1523,7 +1582,13 @@ async function main() {
|
||||
console.log(`${ts()} Bot Activity Engine done.`);
|
||||
}
|
||||
|
||||
main()
|
||||
// 全局超时保护:50 分钟
|
||||
const TIMEOUT_MS = 50 * 60 * 1000;
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error(`Bot Activity Engine timed out after ${TIMEOUT_MS / 60000} minutes`)), TIMEOUT_MS)
|
||||
);
|
||||
|
||||
Promise.race([main(), timeoutPromise])
|
||||
.catch(async (e) => {
|
||||
console.error(`${ts()} Fatal error:`, e);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user