feat: 实现LLM趋势告警历史上下文判断功能
新增功能: - 在LLM趋势分析中集成历史告警上下文,提供最近3次已触发告警的记录 - LLM自动判断本次分析是否与历史告警相似,避免重复通知 - 新增shouldNotify和notifyReason字段,支持智能通知决策 技术改进: - 扩展TrendAnalysisResponse类型,增加通知决策字段 - 数据库服务新增getRecentTriggeredAnalyses()方法 - LLM客户端新增analyzeTrendWithHistory()和相关方法 - 趋势分析服务集成历史上下文获取和通知决策逻辑 测试验证: - 创建test-db-history-method.ts验证数据库方法 - 创建test-llm-history-context.ts测试历史上下文功能 - 通过TypeScript类型检查和构建验证 这个功能可以有效减少重复告警,提升告警质量,避免通知疲劳。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
commit
ccf523543a
52 files changed
+7763
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import { AlertService } from './src/utils/alert.js';
|
||||
|
||||
/**
|
||||
* 测试飞书汇总报告功能
|
||||
*/
|
||||
async function testFeishuSummary() {
|
||||
console.log('========================================');
|
||||
console.log('测试飞书汇总报告功能');
|
||||
console.log('========================================\n');
|
||||
|
||||
// 检查环境变量
|
||||
const webhookUrl = process.env.WEBHOOK_URL;
|
||||
if (!webhookUrl) {
|
||||
console.error('❌ 错误: 未设置 WEBHOOK_URL 环境变量');
|
||||
console.log('请在 .env 文件中配置 Webhook 地址');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log('✅ 飞书 Webhook 已配置');
|
||||
console.log(`Webhook URL: ${webhookUrl}\n`);
|
||||
|
||||
// 创建告警服务实例
|
||||
const alertService = new AlertService();
|
||||
await alertService.init();
|
||||
|
||||
// 模拟汇总数据
|
||||
const summaryData = {
|
||||
runCount: 60,
|
||||
totalPrices: 1250,
|
||||
totalChanges: 15,
|
||||
riseCount: 8,
|
||||
fallCount: 7,
|
||||
currentPrice: {
|
||||
usSilver: '32.50',
|
||||
londonSilver: '32.20',
|
||||
spread: 0.300
|
||||
},
|
||||
recentChanges: [
|
||||
{
|
||||
timestamp: Date.now() - 3600000, // 1小时前
|
||||
changeType: 'RISE',
|
||||
currentSpread: 0.250
|
||||
},
|
||||
{
|
||||
timestamp: Date.now() - 1800000, // 30分钟前
|
||||
changeType: 'FALL',
|
||||
currentSpread: -0.150
|
||||
},
|
||||
{
|
||||
timestamp: Date.now() - 900000, // 15分钟前
|
||||
changeType: 'RISE',
|
||||
currentSpread: 0.300
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
console.log('发送测试报告...\n');
|
||||
|
||||
try {
|
||||
await alertService.sendFeishuSummary(webhookUrl, summaryData);
|
||||
console.log('\n✅ 测试完成!请检查飞书是否收到消息');
|
||||
} catch (error) {
|
||||
console.error('\n❌ 测试失败:', error);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// 运行测试
|
||||
testFeishuSummary();
|
||||
Reference in new issue
Block a user