feat(server): KB prompt优化、字幕修复、S2S重连、助手配置API
- assistantProfileConfig: KB answer prompt改为分层策略(严格产品信息+灵活常识补充) - nativeVoiceGateway: S2S upstream自动重连(最多50次)、event 351字幕debounce(800ms取最长文本) - toolExecutor: 确定性query改写增强、KB查询传递session上下文 - contextKeywordTracker: 支持KB话题记忆优先enrichment - contentSafeGuard: 新增品牌安全内容过滤服务 - assistantProfileService: 新增助手配置CRUD服务 - routes/assistantProfile: 新增助手配置API路由 - knowledgeKeywords: 扩展KB关键词词典 - fastAsrCorrector: ASR纠错规则更新 - tests/: KB prompt测试、保护窗口测试、Viking性能测试 - docs/: 助手配置API文档、系统提示词目录
This commit is contained in:
91
test2/server/tests/test_viking_cold_start.js
Normal file
91
test2/server/tests/test_viking_cold_start.js
Normal file
@@ -0,0 +1,91 @@
|
||||
const path = require('path');
|
||||
const { performance } = require('perf_hooks');
|
||||
|
||||
require('dotenv').config({ path: path.join(__dirname, '../.env') });
|
||||
|
||||
const ToolExecutor = require('../services/toolExecutor');
|
||||
|
||||
const coldTestQueryTemplates = [
|
||||
{ name: 'Product - Q10 Unique', template: 'Q10辅酵素氧修护有什么独特功效 ' },
|
||||
{ name: 'Product - IB5 Unique', template: 'IB5口腔免疫喷雾如何正确使用 ' },
|
||||
{ name: 'Product - CC胶囊 Unique', template: 'CC胶囊的主要适用人群有哪些 ' },
|
||||
{ name: 'Company - 邓白氏 Unique', template: '德国PM邓白氏认证的具体含义是什么 ' },
|
||||
{ name: 'Technology - 火炉原理 Unique', template: '请详细阐述一下火炉原理的核心思想 ' }
|
||||
];
|
||||
|
||||
async function runColdStartTest() {
|
||||
console.log('='.repeat(80));
|
||||
console.log('VIKING COLD START PERFORMANCE TEST');
|
||||
console.log('(No Cache - Real API Calls)');
|
||||
console.log('='.repeat(80));
|
||||
console.log('');
|
||||
|
||||
const allResults = [];
|
||||
|
||||
for (const { name, template } of coldTestQueryTemplates) {
|
||||
console.log(`Testing (Cold): ${name}`);
|
||||
const latencies = [];
|
||||
const hits = [];
|
||||
|
||||
for (let i = 0; i < 3; i++) {
|
||||
const uniqueQuery = template + Math.random();
|
||||
const start = performance.now();
|
||||
let result;
|
||||
try {
|
||||
result = await ToolExecutor.searchKnowledge({ query: uniqueQuery, response_mode: 'answer' }, []);
|
||||
const latency = performance.now() - start;
|
||||
latencies.push(latency);
|
||||
hits.push(!!result.hit);
|
||||
console.log(` Attempt ${i + 1}: ${latency.toFixed(2)}ms, hit=${result.hit}, source=${result.source}`);
|
||||
} catch (e) {
|
||||
console.log(` Attempt ${i + 1} error: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (latencies.length > 0) {
|
||||
const avgLatency = latencies.reduce((a, b) => a + b, 0) / latencies.length;
|
||||
const minLatency = Math.min(...latencies);
|
||||
const maxLatency = Math.max(...latencies);
|
||||
const hitRate = hits.filter(h => h).length / hits.length;
|
||||
|
||||
allResults.push({
|
||||
name,
|
||||
template,
|
||||
avgLatency,
|
||||
minLatency,
|
||||
maxLatency,
|
||||
hitRate,
|
||||
latencies
|
||||
});
|
||||
|
||||
console.log(` → Avg: ${avgLatency.toFixed(2)}ms, Min: ${minLatency.toFixed(2)}ms, Max: ${maxLatency.toFixed(2)}ms, Hit Rate: ${(hitRate * 100).toFixed(1)}%\n`);
|
||||
}
|
||||
}
|
||||
|
||||
console.log('='.repeat(80));
|
||||
console.log('COLD START SUMMARY');
|
||||
console.log('='.repeat(80));
|
||||
|
||||
if (allResults.length > 0) {
|
||||
const totalAvg = allResults.reduce((a, b) => a + b.avgLatency, 0) / allResults.length;
|
||||
const totalMin = Math.min(...allResults.flatMap(r => r.latencies));
|
||||
const totalMax = Math.max(...allResults.flatMap(r => r.latencies));
|
||||
const totalHitRate = allResults.reduce((a, b) => a + b.hitRate, 0) / allResults.length;
|
||||
|
||||
console.log(`\nOverall Average Latency: ${totalAvg.toFixed(2)}ms`);
|
||||
console.log(`Overall Min Latency: ${totalMin.toFixed(2)}ms`);
|
||||
console.log(`Overall Max Latency: ${totalMax.toFixed(2)}ms`);
|
||||
console.log(`Overall Hit Rate: ${(totalHitRate * 100).toFixed(1)}%`);
|
||||
|
||||
console.log('\nFastest queries:');
|
||||
allResults.sort((a, b) => a.avgLatency - b.avgLatency).forEach((r, i) => {
|
||||
console.log(` ${i + 1}. ${r.name}: ${r.avgLatency.toFixed(2)}ms`);
|
||||
});
|
||||
}
|
||||
|
||||
console.log('\n' + '='.repeat(80));
|
||||
|
||||
return allResults;
|
||||
}
|
||||
|
||||
runColdStartTest().catch(console.error);
|
||||
Reference in New Issue
Block a user