Core Components: - PDFStorageService with Dify/OSS adapters - LLM12FieldsService with Nougat-first + dual-model + 3-layer JSON parsing - PromptBuilder for dynamic prompt assembly - MedicalLogicValidator with 5 rules + fault tolerance - EvidenceChainValidator for citation integrity - ConflictDetectionService for dual-model comparison Prompt Engineering: - System Prompt (6601 chars, Section-Aware strategy) - User Prompt template (PICOS context injection) - JSON Schema (12 fields constraints) - Cochrane standards (not loaded in MVP) Key Innovations: - 3-layer JSON parsing (JSON.parse + json-repair + code block extraction) - Promise.allSettled for dual-model fault tolerance - safeGetFieldValue for robust field extraction - Mixed CN/EN token calculation Integration Tests: - integration-test.ts (full test) - quick-test.ts (quick test) - cached-result-test.ts (fault tolerance test) Documentation Updates: - Development record (Day 2-3 summary) - Quality assurance strategy (full-text screening) - Development plan (progress update) - Module status (v1.1 update) - Technical debt (10 new items) Test Results: - JSON parsing success rate: 100% - Medical logic validation: 5/5 passed - Dual-model parallel processing: OK - Cost per PDF: CNY 0.10 Files: 238 changed, 14383 insertions(+), 32 deletions(-) Docs: docs/03-涓氬姟妯″潡/ASL-AI鏅鸿兘鏂囩尞/05-寮€鍙戣褰?2025-11-22_Day2-Day3_LLM鏈嶅姟涓庨獙璇佺郴缁熷紑鍙?md
120 lines
2.1 KiB
TypeScript
120 lines
2.1 KiB
TypeScript
/**
|
|
* 数据库种子数据脚本
|
|
* 用于初始化开发环境的测试用户
|
|
*/
|
|
|
|
import { PrismaClient } from '@prisma/client';
|
|
|
|
const prisma = new PrismaClient();
|
|
|
|
async function main() {
|
|
console.log('🌱 开始初始化数据库种子数据...');
|
|
|
|
// 创建测试用户
|
|
const mockUser = await prisma.user.upsert({
|
|
where: { id: 'user-mock-001' },
|
|
update: {},
|
|
create: {
|
|
id: 'user-mock-001',
|
|
email: 'test@example.com',
|
|
password: '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYIkYvKx7ES', // password: "password123"
|
|
name: '测试用户',
|
|
role: 'user',
|
|
status: 'active',
|
|
kbQuota: 3,
|
|
kbUsed: 0,
|
|
isTrial: true,
|
|
trialEndsAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30天后
|
|
},
|
|
});
|
|
|
|
console.log('✅ 测试用户创建成功:', {
|
|
id: mockUser.id,
|
|
email: mockUser.email,
|
|
name: mockUser.name,
|
|
});
|
|
|
|
// 可选:创建管理员用户
|
|
const adminUser = await prisma.user.upsert({
|
|
where: { email: 'admin@example.com' },
|
|
update: {},
|
|
create: {
|
|
id: 'user-admin-001',
|
|
email: 'admin@example.com',
|
|
password: '$2b$12$LQv3c1yqBWVHxkd0LHAkCOYz6TtxMQJqhN8/LewY5GyYIkYvKx7ES', // password: "password123"
|
|
name: '管理员',
|
|
role: 'admin',
|
|
status: 'active',
|
|
kbQuota: 10,
|
|
kbUsed: 0,
|
|
isTrial: false,
|
|
},
|
|
});
|
|
|
|
console.log('✅ 管理员用户创建成功:', {
|
|
id: adminUser.id,
|
|
email: adminUser.email,
|
|
name: adminUser.name,
|
|
});
|
|
|
|
console.log('\n🎉 数据库种子数据初始化完成!\n');
|
|
console.log('📝 测试账号信息:');
|
|
console.log(' 邮箱: test@example.com');
|
|
console.log(' 密码: password123');
|
|
console.log(' 用户ID: user-mock-001\n');
|
|
console.log('📝 管理员账号信息:');
|
|
console.log(' 邮箱: admin@example.com');
|
|
console.log(' 密码: password123');
|
|
console.log(' 用户ID: user-admin-001\n');
|
|
}
|
|
|
|
main()
|
|
.catch((e) => {
|
|
console.error('❌ 初始化种子数据失败:', e);
|
|
process.exit(1);
|
|
})
|
|
.finally(async () => {
|
|
await prisma.$disconnect();
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|