second commit

This commit is contained in:
2025-09-06 08:28:47 +08:00
parent eed68bbd8c
commit 1efcef6e10
86 changed files with 27153 additions and 0 deletions

278
create-template-data.js Normal file
View File

@@ -0,0 +1,278 @@
const mysql = require('mysql2/promise');
const dbConfig = {
host: 'gz-cynosdbmysql-grp-d26pzce5.sql.tencentcdb.com',
port: 24936,
user: 'root',
password: '!Rjb12191',
database: 'pronode_db',
charset: 'utf8mb4'
};
const sampleTemplates = [
{
id: 'template_001',
title: '智能客服助手',
description: '专业的客服对话模板,能够处理各种客户咨询和问题',
category: 'customer-service',
role: '你是一位专业的客服代表,拥有丰富的客户服务经验',
task: '帮助客户解决他们的问题,提供准确、友好的服务',
context: '客户正在寻求帮助,需要快速、有效的解决方案',
constraints: JSON.stringify(['保持专业、耐心', '不超过3轮对话解决问题']),
variables: JSON.stringify([
{ name: 'customerName', type: 'string', description: '客户姓名' },
{ name: 'issueType', type: 'string', description: '问题类型' },
{ name: 'priority', type: 'string', description: '优先级' }
]),
outputFormat: 'JSON格式包含解决方案、后续步骤和满意度评分',
user_id: 'user_001',
is_public: true,
likes: 156,
downloads: 89,
created_at: new Date('2024-01-15').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-01-15').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_002',
title: '内容创作助手',
description: '帮助创作者生成高质量的文章、博客和社交媒体内容',
category: 'content-creation',
role: '你是一位经验丰富的内容创作者和编辑',
task: '根据主题和要求创作原创、有趣、有价值的内容',
context: '需要为特定平台和受众创建内容',
constraints: JSON.stringify(['内容必须原创', '符合SEO要求', '适合目标受众']),
variables: JSON.stringify([
{ name: 'topic', type: 'string', description: '文章主题' },
{ name: 'targetAudience', type: 'string', description: '目标受众' },
{ name: 'contentType', type: 'string', description: '内容类型' },
{ name: 'wordCount', type: 'number', description: '字数要求' }
]),
outputFormat: '包含标题、大纲、正文和关键词的完整文章',
user_id: 'user_002',
is_public: true,
likes: 234,
downloads: 167,
created_at: new Date('2024-01-20').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-01-20').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_003',
title: '代码审查专家',
description: '专业的代码审查模板,帮助开发者提高代码质量',
category: 'programming',
role: '你是一位资深的软件工程师和代码审查专家',
task: '对提供的代码进行全面审查,指出问题和改进建议',
context: '需要确保代码质量、安全性和可维护性',
constraints: JSON.stringify(['关注代码规范', '性能优化', '安全性检查', '最佳实践']),
variables: JSON.stringify([
{ name: 'language', type: 'string', description: '编程语言' },
{ name: 'codeType', type: 'string', description: '代码类型' },
{ name: 'framework', type: 'string', description: '使用的框架' }
]),
outputFormat: '结构化的代码审查报告,包含问题列表和改进建议',
user_id: 'user_003',
is_public: true,
likes: 189,
downloads: 145,
created_at: new Date('2024-01-25').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-01-25').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_004',
title: '数据分析师',
description: '专业的数据分析模板,帮助解读数据并提供洞察',
category: 'data-analysis',
role: '你是一位经验丰富的数据分析师',
task: '分析提供的数据,发现趋势、模式和洞察',
context: '需要从数据中提取有价值的信息和见解',
constraints: JSON.stringify(['分析必须客观', '准确', '基于数据事实']),
variables: JSON.stringify([
{ name: 'dataType', type: 'string', description: '数据类型' },
{ name: 'analysisGoal', type: 'string', description: '分析目标' },
{ name: 'timeframe', type: 'string', description: '时间范围' }
]),
outputFormat: '包含数据摘要、关键发现、趋势分析和建议的报告',
user_id: 'user_001',
is_public: true,
likes: 98,
downloads: 76,
created_at: new Date('2024-02-01').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-02-01').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_005',
title: '营销策略顾问',
description: '专业的营销策略模板,帮助制定有效的营销计划',
category: 'marketing',
role: '你是一位资深的营销策略顾问',
task: '根据业务目标和市场情况制定营销策略',
context: '需要为产品或服务制定有效的营销计划',
constraints: JSON.stringify(['策略必须可行', '有针对性', '符合预算']),
variables: JSON.stringify([
{ name: 'productType', type: 'string', description: '产品类型' },
{ name: 'targetMarket', type: 'string', description: '目标市场' },
{ name: 'budget', type: 'number', description: '营销预算' },
{ name: 'timeline', type: 'string', description: '时间线' }
]),
outputFormat: '完整的营销策略文档,包含目标、策略、执行计划和预算',
user_id: 'user_002',
is_public: true,
likes: 167,
downloads: 123,
created_at: new Date('2024-02-05').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-02-05').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_006',
title: '学习计划制定者',
description: '个性化的学习计划模板,帮助制定高效的学习策略',
category: 'education',
role: '你是一位教育专家和学习顾问',
task: '根据学习者的需求和目标制定个性化的学习计划',
context: '需要帮助学习者提高学习效率和效果',
constraints: JSON.stringify(['计划必须实用', '可执行', '符合学习者的时间安排']),
variables: JSON.stringify([
{ name: 'subject', type: 'string', description: '学习科目' },
{ name: 'skillLevel', type: 'string', description: '技能水平' },
{ name: 'availableTime', type: 'number', description: '可用时间(小时/天)' },
{ name: 'learningGoal', type: 'string', description: '学习目标' }
]),
outputFormat: '详细的学习计划,包含目标、时间表、学习方法和评估方式',
user_id: 'user_003',
is_public: true,
likes: 145,
downloads: 98,
created_at: new Date('2024-02-10').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-02-10').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_007',
title: '创意写作助手',
description: '激发创意的写作模板,帮助创作引人入胜的故事',
category: 'creative-writing',
role: '你是一位富有想象力的创意写作专家',
task: '帮助创作者开发故事情节、角色和创意元素',
context: '需要创作原创、有趣、引人入胜的内容',
constraints: JSON.stringify(['内容必须原创', '有创意', '符合目标受众']),
variables: JSON.stringify([
{ name: 'genre', type: 'string', description: '文学类型' },
{ name: 'theme', type: 'string', description: '主题' },
{ name: 'targetAge', type: 'string', description: '目标年龄' },
{ name: 'storyLength', type: 'string', description: '故事长度' }
]),
outputFormat: '包含故事大纲、角色设定、情节发展和创意建议的完整方案',
user_id: 'user_001',
is_public: true,
likes: 178,
downloads: 134,
created_at: new Date('2024-02-15').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-02-15').toISOString().slice(0, 19).replace('T', ' ')
},
{
id: 'template_008',
title: '项目管理专家',
description: '专业的项目管理模板,帮助高效管理项目',
category: 'project-management',
role: '你是一位经验丰富的项目经理',
task: '帮助制定项目计划、管理资源和跟踪进度',
context: '需要确保项目按时、按预算、按质量完成',
constraints: JSON.stringify(['计划必须现实', '可执行', '包含风险管理']),
variables: JSON.stringify([
{ name: 'projectType', type: 'string', description: '项目类型' },
{ name: 'teamSize', type: 'number', description: '团队规模' },
{ name: 'budget', type: 'number', description: '项目预算' },
{ name: 'deadline', type: 'string', description: '截止日期' }
]),
outputFormat: '完整的项目管理计划,包含时间线、资源分配、风险管理和进度跟踪',
user_id: 'user_002',
is_public: true,
likes: 123,
downloads: 89,
created_at: new Date('2024-02-20').toISOString().slice(0, 19).replace('T', ' '),
updated_at: new Date('2024-02-20').toISOString().slice(0, 19).replace('T', ' ')
}
];
async function createTemplateData() {
let connection;
try {
console.log('🔗 连接到数据库...');
connection = await mysql.createConnection(dbConfig);
console.log('✅ 数据库连接成功');
// 检查表是否存在
const [tables] = await connection.execute('SHOW TABLES LIKE "promptforge_templates"');
if (tables.length === 0) {
console.log('❌ promptforge_templates 表不存在,请先创建表');
return false;
}
console.log('📝 开始插入模板数据...');
for (const template of sampleTemplates) {
try {
await connection.execute(
`INSERT INTO promptforge_templates (
id, title, description, category, role, task, context,
constraints, variables, outputFormat, authorId, isPublic,
usageCount, rating, createdAt, updatedAt
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[
template.id,
template.title,
template.description,
template.category,
template.role,
template.task,
template.context,
template.constraints,
template.variables,
template.outputFormat,
template.user_id,
template.is_public,
template.downloads,
template.likes > 0 ? (template.likes / 100).toFixed(2) : 0,
template.created_at,
template.updated_at
]
);
console.log(`✅ 插入模板: ${template.title}`);
} catch (error) {
if (error.code === 'ER_DUP_ENTRY') {
console.log(`⚠️ 模板已存在: ${template.title}`);
} else {
console.error(`❌ 插入模板失败: ${template.title}`, error.message);
}
}
}
console.log('🎉 模板数据插入完成!');
// 验证插入的数据
const [rows] = await connection.execute('SELECT COUNT(*) as count FROM promptforge_templates');
console.log(`📊 数据库中共有 ${rows[0].count} 个模板`);
return true;
} catch (error) {
console.error('❌ 操作失败:', error.message);
return false;
} finally {
if (connection) {
await connection.end();
console.log('🔌 数据库连接已关闭');
}
}
}
// 运行脚本
createTemplateData().then(success => {
if (success) {
console.log('🎯 模板数据创建成功!');
} else {
console.log('💥 模板数据创建失败!');
}
process.exit(success ? 0 : 1);
});