import { LLMClient } from './src/utils/llm-client.js'; import type { PriceDataPoint } from './src/types/index.js'; /** * 测试小幅波动场景(波动 < 0.2) */ async function testLowVolatility() { console.log('========================================'); console.log('测试小幅波动场景(波动 < 0.2)'); console.log('========================================\n'); // 检查环境变量 const apiKey = process.env.LLM_API_KEY; if (!apiKey) { console.error('❌ 错误:未配置 LLM_API_KEY 环境变量'); process.exit(1); } const config = { apiBase: process.env.LLM_API_BASE || 'https://api.openai.com/v1', apiKey: apiKey, model: process.env.LLM_MODEL || 'gpt-4o-mini', timeout: 120000 }; console.log('配置信息:'); console.log(` API Base: ${config.apiBase}`); console.log(` Model: ${config.model}`); console.log(` Timeout: ${config.timeout}ms\n`); const llmClient = new LLMClient(config); // 准备小幅波动的测试数据(波动幅度约 0.12) const testData: PriceDataPoint[] = []; const now = Date.now(); const basePrice = 22.0; for (let i = 30; i >= 0; i--) { const timestamp = new Date(now - i * 60000).toISOString(); // 创建小幅波动:价格在 22.0 到 22.12 之间波动 const price = basePrice + Math.sin(i * 0.5) * 0.06 + Math.random() * 0.02; const changeFromPrevious = i < 30 ? price - testData[testData.length - 1].price : undefined; const volatility = i > 0 && testData.length > 0 ? Math.abs(changeFromPrevious!) / price : undefined; testData.push({ price, timestamp, changeFromPrevious, volatility }); } // 计算实际波动幅度 const prices = testData.slice(-10).map(p => p.price); const maxPrice = Math.max(...prices); const minPrice = Math.min(...prices); const range = maxPrice - minPrice; console.log(`测试数据特征:`); console.log(` 最近 10 分钟最高价: ${maxPrice.toFixed(3)}`); console.log(` 最近 10 分钟最低价: ${minPrice.toFixed(3)}`); console.log(` 波动幅度: ${range.toFixed(3)} ${range < 0.2 ? '(< 0.2)' : '(≥ 0.2)'}`); console.log(`\n预期:LLM 应判定为 ${range < 0.2 ? 'sideways/uptrend/downtrend(非 volatile)' : 'volatile'}\n`); console.log('开始 LLM 分析...\n'); try { const result = await llmClient.analyzeTrend(testData); console.log('========================================'); console.log('分析结果'); console.log('========================================'); console.log(`趋势类型: ${result.trend}`); console.log(`置信度: ${(result.confidence * 100).toFixed(0)}%`); console.log(`风险评估: ${result.risk}`); console.log(`\n趋势总结:`); console.log(` ${result.summary}`); console.log(`\n关键信号:`); result.signals.forEach((signal, index) => { console.log(` ${index + 1}. ${signal}`); }); console.log('========================================\n'); // 验证结果 const isCorrect = result.trend !== 'volatile' || range > 0.2; if (isCorrect) { console.log('✅ 测试通过!LLM 正确应用了 0.2 的波动阈值'); } else { console.log('❌ 测试失败!LLM 误判为 volatile,但实际波动幅度 < 0.2'); } } catch (error) { console.error('\n❌ 测试失败:'); console.error(error); process.exit(1); } } testLowVolatility();