Completed features: - Created Dify dataset (Dify_test0102) with 2 processed documents - Linked test0102 project with Dify dataset ID - Extended intent detection to recognize query_protocol intent - Implemented queryDifyKnowledge method (semantic search Top 5) - Integrated hybrid retrieval (REDCap data + Dify documents) - Fixed AI hallucination bugs (intent detection + API field path) - Developed debugging scripts - Completed end-to-end testing (5 scenarios passed) - Generated comprehensive documentation (600+ lines) - Updated development plans and module status Technical highlights: - Single project single knowledge base architecture - Smart routing based on user intent - Prevent AI hallucination by injecting real data/documents - Session memory for multi-turn conversations - Reused LLMFactory for DeepSeek-V3 integration Bug fixes: - Fixed intent detection missing keywords - Fixed Dify API response field path error Testing: All scenarios verified in WeChat production environment Status: Fully tested and deployed
93 lines
3.3 KiB
TypeScript
93 lines
3.3 KiB
TypeScript
/**
|
||
* 检查项目配置脚本
|
||
* 用于查看数据库中是否已配置 notification_config
|
||
*/
|
||
|
||
import { PrismaClient } from '@prisma/client';
|
||
|
||
const prisma = new PrismaClient();
|
||
|
||
async function checkProjectConfig() {
|
||
console.log('🔍 检查项目配置...\n');
|
||
|
||
try {
|
||
// 查询所有项目
|
||
const projects = await prisma.$queryRaw<Array<{
|
||
id: string;
|
||
name: string;
|
||
redcap_project_id: string;
|
||
notification_config: any;
|
||
status: string;
|
||
}>>`
|
||
SELECT id, name, redcap_project_id, notification_config, status
|
||
FROM iit_schema.projects
|
||
ORDER BY created_at DESC
|
||
`;
|
||
|
||
if (projects.length === 0) {
|
||
console.log('❌ 数据库中没有项目记录');
|
||
console.log('\n💡 建议:请先运行 test-redcap-integration.ts 创建测试项目');
|
||
return;
|
||
}
|
||
|
||
console.log(`✅ 找到 ${projects.length} 个项目:\n`);
|
||
|
||
projects.forEach((project, index) => {
|
||
console.log(`\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━`);
|
||
console.log(`项目 ${index + 1}:`);
|
||
console.log(` 名称: ${project.name}`);
|
||
console.log(` REDCap项目ID: ${project.redcap_project_id}`);
|
||
console.log(` 状态: ${project.status}`);
|
||
console.log(` 数据库ID: ${project.id}`);
|
||
|
||
if (project.notification_config) {
|
||
const config = project.notification_config;
|
||
console.log(` \n 📧 通知配置:`);
|
||
|
||
if (config.wechat_user_id) {
|
||
console.log(` ✅ 企业微信UserID: ${config.wechat_user_id}`);
|
||
console.log(` 📤 通知发送给: ${config.wechat_user_id}`);
|
||
} else {
|
||
console.log(` ⚠️ 未配置 wechat_user_id`);
|
||
console.log(` 📤 通知发送给: ${process.env.WECHAT_TEST_USER_ID || '未配置环境变量'} (环境变量)`);
|
||
}
|
||
|
||
// 显示完整配置
|
||
console.log(` \n 完整配置: ${JSON.stringify(config, null, 2)}`);
|
||
} else {
|
||
console.log(` \n ⚠️ notification_config 为空`);
|
||
console.log(` 📤 通知发送给: ${process.env.WECHAT_TEST_USER_ID || '未配置环境变量'} (环境变量)`);
|
||
}
|
||
});
|
||
|
||
console.log('\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n');
|
||
console.log('📋 配置优先级说明:');
|
||
console.log(' 1️⃣ 项目配置 (notification_config.wechat_user_id) - 优先');
|
||
console.log(' 2️⃣ 环境变量 (WECHAT_TEST_USER_ID) - 回退');
|
||
console.log(' 3️⃣ 如果都没有 - 不发送通知\n');
|
||
|
||
console.log('💡 当前环境变量:');
|
||
console.log(` WECHAT_TEST_USER_ID = ${process.env.WECHAT_TEST_USER_ID || '未配置'}\n`);
|
||
|
||
console.log('🔧 如何添加项目配置:');
|
||
console.log(` UPDATE iit_schema.projects`);
|
||
console.log(` SET notification_config = jsonb_set(`);
|
||
console.log(` COALESCE(notification_config, '{}'::jsonb),`);
|
||
console.log(` '{wechat_user_id}',`);
|
||
console.log(` '"FengZhiBo"'`);
|
||
console.log(` )`);
|
||
console.log(` WHERE redcap_project_id = '16';\n`);
|
||
|
||
} catch (error: any) {
|
||
console.error('❌ 检查失败:', error.message);
|
||
} finally {
|
||
await prisma.$disconnect();
|
||
}
|
||
}
|
||
|
||
// 运行检查
|
||
checkProjectConfig().catch(console.error);
|
||
|
||
|
||
|