optimize: 优化 Prompt 构建器逻辑,引入结构化标签提升输出质量
This commit is contained in:
@@ -1,23 +1,29 @@
|
||||
export const buildPrompt = (task, constraints, references) => {
|
||||
let prompt = `# Role\n你是一个资深的专业写作助手,请严格按照以下要求进行创作。\n\n`
|
||||
let prompt = `# Role\n你是一个资深的专业写作专家。你具备极强的风格模仿能力和逻辑组织能力,能够根据提供的参考资料和风格分析,创作出高度一致的高质量文稿。\n\n`;
|
||||
|
||||
// 1. 注入规范
|
||||
prompt += `# System Constraints (必须遵守)\n`
|
||||
constraints.forEach(tag => prompt += `- ${tag}\n`)
|
||||
prompt += `\n`
|
||||
// 1. 注入规范与风格分析
|
||||
prompt += `# Instructions & Style Constraints\n`;
|
||||
prompt += `<global_rules>\n`;
|
||||
constraints.forEach(tag => prompt += `- ${tag}\n`);
|
||||
prompt += `</global_rules>\n\n`;
|
||||
|
||||
// 2. 注入参考案例 (Few-Shot)
|
||||
if (references.length > 0) {
|
||||
prompt += `# Reference Cases (请模仿以下风格)\n`
|
||||
prompt += `# Style Reference Cases\n`;
|
||||
prompt += `请深度学习并模仿以下参考资料的语调、用词习惯、句式结构和情感色彩:\n`;
|
||||
references.forEach((ref, idx) => {
|
||||
prompt += `<case_${idx + 1} title="${ref.title}">\n${ref.content}\n</case_${idx + 1}>\n\n`
|
||||
})
|
||||
prompt += `<case_${idx + 1} title="${ref.title}">\n${ref.content}\n</case_${idx + 1}>\n\n`;
|
||||
});
|
||||
}
|
||||
|
||||
// 3. 注入用户任务
|
||||
prompt += `# Current Task (User Input)\n${task}`
|
||||
prompt += `# Current Writing Task\n`;
|
||||
prompt += `请基于上述所有风格约束和参考案例,执行以下写作任务:\n`;
|
||||
prompt += `<task_content>\n${task}\n</task_content>\n\n`;
|
||||
|
||||
return prompt
|
||||
prompt += `直接开始输出正文内容,无需任何开场白或解释。`;
|
||||
|
||||
return prompt;
|
||||
}
|
||||
|
||||
export const parseStreamResponse = (chunk) => {
|
||||
|
||||
Reference in New Issue
Block a user