78 lines
2.5 KiB
TypeScript
78 lines
2.5 KiB
TypeScript
|
|
/**
|
|||
|
|
* 更新数据库中的 User Prompt Template
|
|||
|
|
* 将旧版本(包含"要求"和"输出格式")更新为新版本(只包含任务描述和变量)
|
|||
|
|
*
|
|||
|
|
* 使用方法:
|
|||
|
|
* cd backend
|
|||
|
|
* npx ts-node scripts/update-prompt-templates.ts
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
import prisma from '../src/utils/prisma';
|
|||
|
|
import { promptConfigService } from '../src/services/promptConfigService';
|
|||
|
|
|
|||
|
|
async function updatePromptTemplates() {
|
|||
|
|
try {
|
|||
|
|
console.log('🔄 开始更新数据库中的 User Prompt Template...\n');
|
|||
|
|
|
|||
|
|
const types: ('summary' | 'outline' | 'content')[] = ['summary', 'outline', 'content'];
|
|||
|
|
|
|||
|
|
for (const promptType of types) {
|
|||
|
|
console.log(`\n📝 处理类型: ${promptType}`);
|
|||
|
|
|
|||
|
|
// 获取数据库中的配置
|
|||
|
|
const config = await prisma.aIPromptConfig.findUnique({
|
|||
|
|
where: { promptType },
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
if (!config) {
|
|||
|
|
console.log(` ⚠️ 数据库中没有 ${promptType} 类型的配置,跳过`);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 获取新的默认配置
|
|||
|
|
const defaultConfig = promptConfigService.getPromptConfig(promptType);
|
|||
|
|
const newUserPromptTemplate = defaultConfig.userPromptTemplate;
|
|||
|
|
|
|||
|
|
// 检查是否需要更新
|
|||
|
|
const oldUserPromptTemplate = config.userPromptTemplate || '';
|
|||
|
|
|
|||
|
|
// 检查是否包含"要求"或"输出格式"(旧版本的特征)
|
|||
|
|
const hasOldFormat = oldUserPromptTemplate.includes('要求:') ||
|
|||
|
|
oldUserPromptTemplate.includes('输出格式');
|
|||
|
|
|
|||
|
|
if (!hasOldFormat && oldUserPromptTemplate.trim() === newUserPromptTemplate.trim()) {
|
|||
|
|
console.log(` ✅ ${promptType} 已经是新版本,无需更新`);
|
|||
|
|
continue;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log(` 📋 旧版本 User Prompt Template:`);
|
|||
|
|
console.log(` ${oldUserPromptTemplate.substring(0, 100)}...`);
|
|||
|
|
console.log(` 📋 新版本 User Prompt Template:`);
|
|||
|
|
console.log(` ${newUserPromptTemplate}`);
|
|||
|
|
|
|||
|
|
// 更新数据库
|
|||
|
|
await prisma.aIPromptConfig.update({
|
|||
|
|
where: { promptType },
|
|||
|
|
data: {
|
|||
|
|
userPromptTemplate: newUserPromptTemplate,
|
|||
|
|
version: config.version + 1,
|
|||
|
|
},
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log(` ✅ ${promptType} 已更新到新版本`);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('\n✅ 所有配置更新完成!');
|
|||
|
|
console.log('\n💡 提示:服务器会自动重新加载配置到内存缓存');
|
|||
|
|
|
|||
|
|
} catch (error: any) {
|
|||
|
|
console.error('❌ 更新失败:', error.message);
|
|||
|
|
process.exit(1);
|
|||
|
|
} finally {
|
|||
|
|
await prisma.$disconnect();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 执行更新
|
|||
|
|
updatePromptTemplates();
|