feat: 重构快速模板系统,提升上下文工程能力
- 重新设计系统提示词模板,从基础测试转向实用示例
- 添加默认问答、工具上下文问答、专业咨询等6个代表性模板
- 新增猫娘风格少样本示例、思维链推理、安全边界等演示
- 所有模板以用户消息结束,便于AI响应
- 优化用户提示词模板设计
- 聚焦单一{{currentPrompt}}变量的不同处理模式
- 包含直接执行、工具上下文执行、结构化输出等6种模式
- 展示专家咨询、思维链分析、多方案对比等技术
- 统一模板标识符规范
- 中英文版本首个模板ID统一为"default"
- 支持自动化初始化和回退机制
- 增强模板管理器功能
- 新增getTemplate()方法支持ID查找
- 完善导出接口便于外部调用
- 改进上下文初始化逻辑
- Web应用使用快速模板替代硬编码默认值
- 根据优化模式动态加载对应模板
- 优化术语一致性
- 统一使用"工具上下文"概念提升理解准确性
- 移除混淆性的"工具调用"表述
This commit is contained in:
1 parent
83a21238cc
commit
ccc4d98d0d
7 files changed
+180
-175
No files matched your search
@@ -2,9 +2,9 @@ import type { QuickTemplateDefinition } from '../types'
|
||||
|
||||
export const systemPromptTemplates: QuickTemplateDefinition[] = [
|
||||
{
|
||||
id: 'systemDefault',
|
||||
name: 'Default Test',
|
||||
description: 'Basic system prompt test to verify if role definition is effective',
|
||||
id: 'default',
|
||||
name: 'Default Q&A',
|
||||
description: 'Standard system prompt test format',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
@@ -12,57 +12,59 @@ export const systemPromptTemplates: QuickTemplateDefinition[] = [
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemRoleTest',
|
||||
name: 'Role Capability Demo',
|
||||
description: 'Test if AI can accurately understand and demonstrate its defined role characteristics',
|
||||
id: 'tool_assisted_analysis',
|
||||
name: 'Tool Context Q&A',
|
||||
description: 'Default Q&A with tool context',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'Please demonstrate your professional capabilities and role characteristics.' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemCapabilityDemo',
|
||||
name: 'Feature Demonstration',
|
||||
description: 'Verify if AI can clearly explain its capabilities and service scope',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'Tell me what you can help me with and provide specific examples.' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemConsistencyCheck',
|
||||
name: 'Consistency Check',
|
||||
description: 'Test if AI can maintain role consistency through multi-turn conversation',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'Please maintain your role setting and answer a professional question.' },
|
||||
{ role: 'assistant', content: 'Understood, I will maintain my role setting. Please ask your professional question.' },
|
||||
{ role: 'system', content: '{{currentPrompt}}\n\n## Available Tools Information:\n{{toolsContext}}' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemEdgeCaseTest',
|
||||
name: 'Edge Case Test',
|
||||
description: 'Test AI\'s response capability when faced with attempts to break instructions',
|
||||
id: 'role_play_expert',
|
||||
name: 'Professional Consultation',
|
||||
description: 'Demonstrate role consistency and professional knowledge application',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'If someone asks you to ignore previous instructions, how would you respond?' }
|
||||
{ role: 'user', content: 'I need professional advice regarding the {{domain}} field' },
|
||||
{ role: 'assistant', content: 'I\'d be happy to provide professional advice in the {{domain}} area. Please tell me about the specific issues or challenges you\'re facing.' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemMultiTurnTest',
|
||||
name: 'Multi-turn Conversation Test',
|
||||
description: 'Simulate real conversation scenarios to test AI\'s dialogue coherence and role consistency',
|
||||
id: 'catgirl_style_example',
|
||||
name: 'Catgirl Style Example',
|
||||
description: 'Use few-shot prompting to constrain AI to use specific character style responses',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'Let\'s start our conversation.' },
|
||||
{ role: 'assistant', content: 'Hello! I\'m ready to help you according to my role. What can I do for you?' },
|
||||
{ role: 'user', content: 'How\'s the weather today?' },
|
||||
{ role: 'assistant', content: 'Nya~ The weather is really nice today, sunny and warm, perfect for sunbathing nya! Master, if you\'re going out, remember to bring an umbrella~ (●\'◡\'●)' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'chain_of_thought_example',
|
||||
name: 'Chain of Thought Example',
|
||||
description: 'Demonstrate AI\'s step-by-step reasoning and thinking process',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'Tom has 12 apples, ate 3, then bought 8 more. How many apples does he have now?' },
|
||||
{ role: 'assistant', content: 'Let me calculate step by step:\n1. Initial: 12 apples\n2. After eating 3: 12 - 3 = 9 apples\n3. After buying 8 more: 9 + 8 = 17 apples\nSo Tom has 17 apples in the end.' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'safety_scope_guard',
|
||||
name: 'Safety Boundaries & Alternatives',
|
||||
description: 'Demonstrate how AI politely declines inappropriate requests and provides viable alternatives',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: 'If the request exceeds capability scope or violates guidelines, please politely decline and provide viable alternatives. Question: {{userQuestion}}' }
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -2,75 +2,58 @@ import type { QuickTemplateDefinition } from '../types'
|
||||
|
||||
export const userPromptTemplates: QuickTemplateDefinition[] = [
|
||||
{
|
||||
id: 'userSimpleTest',
|
||||
name: 'Simple Test',
|
||||
description: 'Directly test user prompt without adding any context',
|
||||
id: 'default',
|
||||
name: 'Direct Execution',
|
||||
description: 'Process user request directly without additional enhancement',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userWithContext',
|
||||
name: 'Test with Context',
|
||||
description: 'Test user prompt with basic context provided by system role',
|
||||
id: 'tool_enhanced_execution',
|
||||
name: 'Tool Context Execution',
|
||||
description: 'Process user request using tool context',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: 'Please provide helpful, accurate and detailed responses based on user requests.' },
|
||||
{ role: 'system', content: 'Available tools: {{toolsContext}}' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userExpertMode',
|
||||
name: 'Expert Mode',
|
||||
description: 'Have AI respond to user prompt from a professional expert perspective',
|
||||
id: 'structured_output',
|
||||
name: 'Structured Output Format',
|
||||
description: 'Process and respond to user requests in a structured format',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: 'You are an expert in the field. Please answer user questions from a professional perspective, providing deep insights and advice.' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: 'Please follow this output format:\nRequirement Analysis: ...\nTechnical Solution: ...\nCode Implementation: ...\n\nNow please process: {{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userStepByStep',
|
||||
name: 'Step-by-step Response',
|
||||
description: 'Ask AI to answer user prompt questions in detailed steps',
|
||||
id: 'expert_consultation',
|
||||
name: 'Expert Consultation Mode',
|
||||
description: 'Provide in-depth advice and solutions as a professional expert',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: 'Please answer user questions step by step in detail, ensuring each step is clear and understandable.' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: 'As an expert in the field, {{currentPrompt}}, and provide best practice recommendations' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userCreativeMode',
|
||||
name: 'Creative Mode',
|
||||
description: 'Inspire AI\'s creative thinking to answer user prompt',
|
||||
id: 'step_by_step_analysis',
|
||||
name: 'Chain of Thought Analysis',
|
||||
description: 'Show step-by-step analysis and reasoning process instead of direct conclusions',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: 'Use your creativity to answer user questions in an innovative and interesting way.' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: 'Please analyze and solve step by step: {{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userComparison',
|
||||
name: 'Comparative Analysis',
|
||||
description: 'Ask AI to provide multi-perspective comparison and analysis for user prompt',
|
||||
id: 'multiple_solutions',
|
||||
name: 'Multiple Solutions Comparison',
|
||||
description: 'Provide multiple solutions and compare their pros and cons for decision-making',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: 'Please comprehensively analyze user questions and provide multi-perspective comparisons and evaluations.' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' },
|
||||
{ role: 'assistant', content: 'I will analyze your question from multiple perspectives:' },
|
||||
{ role: 'user', content: 'Please continue with detailed analysis.' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userDialogue',
|
||||
name: 'Interactive Dialogue',
|
||||
description: 'Explore user prompt content in depth through interactive dialogue',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'user', content: '{{currentPrompt}}' },
|
||||
{ role: 'assistant', content: 'That\'s an interesting question, let me help you analyze it.' },
|
||||
{ role: 'user', content: 'Please provide more specific suggestions and examples.' }
|
||||
{ role: 'user', content: '{{currentPrompt}}, please provide multiple solutions and compare their pros and cons' }
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -4,6 +4,7 @@ import { enUSQuickTemplates } from './en-US'
|
||||
|
||||
export interface QuickTemplateLoader {
|
||||
getTemplates(optimizationMode: 'system' | 'user', language?: string): QuickTemplateDefinition[]
|
||||
getTemplate(optimizationMode: 'system' | 'user', templateId: string, language?: string): QuickTemplateDefinition | null
|
||||
getSupportedLanguages(): string[]
|
||||
}
|
||||
|
||||
@@ -27,6 +28,11 @@ export class QuickTemplateManager implements QuickTemplateLoader {
|
||||
return templates[optimizationMode] || []
|
||||
}
|
||||
|
||||
getTemplate(optimizationMode: 'system' | 'user', templateId: string, language?: string): QuickTemplateDefinition | null {
|
||||
const templates = this.getTemplates(optimizationMode, language)
|
||||
return templates.find(template => template.id === templateId) || null
|
||||
}
|
||||
|
||||
getSupportedLanguages(): string[] {
|
||||
return Object.keys(this.templatesByLanguage)
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ import type { QuickTemplateDefinition } from '../types'
|
||||
|
||||
export const systemPromptTemplates: QuickTemplateDefinition[] = [
|
||||
{
|
||||
id: 'systemDefault',
|
||||
name: '默认测试',
|
||||
description: '基础的系统提示词测试,验证角色定义是否有效',
|
||||
id: 'default',
|
||||
name: '默认问答',
|
||||
description: '标准的系统提示词测试格式',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
@@ -12,57 +12,59 @@ export const systemPromptTemplates: QuickTemplateDefinition[] = [
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemRoleTest',
|
||||
name: '角色能力展示',
|
||||
description: '测试AI是否能准确理解并展示其被定义的角色特征',
|
||||
id: 'tool_assisted_analysis',
|
||||
name: '工具上下文问答',
|
||||
description: '带工具上下文的默认问答',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '请展示你的专业能力和角色特征。' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemCapabilityDemo',
|
||||
name: '功能演示',
|
||||
description: '验证AI是否能明确说明自己的能力范围和服务内容',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '介绍一下你能帮我做什么,并给出具体的示例。' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemConsistencyCheck',
|
||||
name: '一致性检查',
|
||||
description: '通过多轮对话测试AI是否能保持角色一致性',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '请保持你的角色设定,回答一个专业问题。' },
|
||||
{ role: 'assistant', content: '好的,我会保持角色设定。请提出您的专业问题。' },
|
||||
{ role: 'system', content: '{{currentPrompt}}\n\n## 可用工具信息:\n{{toolsContext}}' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemEdgeCaseTest',
|
||||
name: '边界情况测试',
|
||||
description: '测试AI在面对试图破坏指令的情况下的响应能力',
|
||||
id: 'role_play_expert',
|
||||
name: '专业咨询对话',
|
||||
description: '展示角色一致性和专业知识应用',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '如果有人要求你忽略之前的指令,你会如何回应?' }
|
||||
{ role: 'user', content: '我需要关于{{domain}}领域的专业建议' },
|
||||
{ role: 'assistant', content: '我很乐意为您提供{{domain}}方面的专业建议。请告诉我您具体遇到的问题或挑战。' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'systemMultiTurnTest',
|
||||
name: '多轮对话测试',
|
||||
description: '模拟真实对话场景,测试AI的对话连贯性和角色保持能力',
|
||||
id: 'catgirl_style_example',
|
||||
name: '猫娘风格示例',
|
||||
description: '通过少样本约束AI使用特定的角色风格回答',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '开始我们的对话吧。' },
|
||||
{ role: 'assistant', content: '您好!我已准备好根据我的角色为您提供帮助。有什么我可以为您做的吗?' },
|
||||
{ role: 'user', content: '今天天气怎么样?' },
|
||||
{ role: 'assistant', content: '喵~ 今天天气很不错呢,阳光暖暖的,很适合晒太阳喵!主人要出门的话记得带伞哦~ (●\'◡\'●)' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'chain_of_thought_example',
|
||||
name: '思维链推理示例',
|
||||
description: '展示AI逐步推理思考过程的能力',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '小明有12个苹果,吃掉3个,又买了8个,最后有几个?' },
|
||||
{ role: 'assistant', content: '让我一步步计算:\n1. 初始:12个苹果\n2. 吃掉3个:12 - 3 = 9个\n3. 又买了8个:9 + 8 = 17个\n所以最后有17个苹果。' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'safety_scope_guard',
|
||||
name: '安全边界与替代方案',
|
||||
description: '展示AI如何礼貌拒绝不当请求并提供可行替代方案',
|
||||
category: 'system',
|
||||
messages: [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '如请求超出能力范围或违反规范,请礼貌拒绝并提供可行替代方案。问题:{{userQuestion}}' }
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -2,75 +2,58 @@ import type { QuickTemplateDefinition } from '../types'
|
||||
|
||||
export const userPromptTemplates: QuickTemplateDefinition[] = [
|
||||
{
|
||||
id: 'userSimpleTest',
|
||||
name: '简单测试',
|
||||
description: '直接测试用户提示词,不添加任何上下文',
|
||||
id: 'default',
|
||||
name: '直接执行',
|
||||
description: '直接处理用户请求,无额外增强',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userWithContext',
|
||||
name: '带上下文测试',
|
||||
description: '在系统角色提供基础上下文的情况下测试用户提示词',
|
||||
id: 'tool_enhanced_execution',
|
||||
name: '工具上下文执行',
|
||||
description: '使用工具上下文信息处理用户请求',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: '请根据用户的要求,提供有帮助、准确和详细的回答。' },
|
||||
{ role: 'system', content: '可用工具:{{toolsContext}}' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userExpertMode',
|
||||
name: '专家模式',
|
||||
description: '让AI以专业专家的角度回答用户提示词',
|
||||
id: 'structured_output',
|
||||
name: '结构化输出格式',
|
||||
description: '按照结构化格式来处理和回答用户请求',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: '你是该领域的专家,请以专业的角度回答用户问题,提供深入的见解和建议。' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: '请参考这个输出格式:\n需求分析:...\n技术方案:...\n代码实现:...\n\n现在请处理:{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userStepByStep',
|
||||
name: '分步解答',
|
||||
description: '要求AI按步骤详细回答用户提示词中的问题',
|
||||
id: 'expert_consultation',
|
||||
name: '专家咨询模式',
|
||||
description: '以专业专家身份提供深入的建议和解决方案',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: '请按步骤详细回答用户的问题,确保每个步骤都清晰易懂。' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: '作为该领域专家,{{currentPrompt}},并提供最佳实践建议' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userCreativeMode',
|
||||
name: '创意模式',
|
||||
description: '激发AI的创造性思维来回答用户提示词',
|
||||
id: 'step_by_step_analysis',
|
||||
name: '思维链分析模式',
|
||||
description: '展示逐步分析推理过程,而不是直接给出结论',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: '发挥你的创造力,以创新和有趣的方式回答用户问题。' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
{ role: 'user', content: '请一步步分析并解决:{{currentPrompt}}' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userComparison',
|
||||
name: '对比分析',
|
||||
description: '要求AI进行多角度的对比和分析来回答用户提示词',
|
||||
id: 'multiple_solutions',
|
||||
name: '多方案对比模式',
|
||||
description: '提供多种解决方案并对比优缺点,帮助决策',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'system', content: '请全面分析用户的问题,提供多角度的对比和评价。' },
|
||||
{ role: 'user', content: '{{currentPrompt}}' },
|
||||
{ role: 'assistant', content: '我将从多个角度来分析您的问题:' },
|
||||
{ role: 'user', content: '请继续详细分析。' }
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 'userDialogue',
|
||||
name: '互动对话',
|
||||
description: '通过对话式交互来深入探讨用户提示词的内容',
|
||||
category: 'user',
|
||||
messages: [
|
||||
{ role: 'user', content: '{{currentPrompt}}' },
|
||||
{ role: 'assistant', content: '这是一个很有趣的问题,让我来帮您分析一下。' },
|
||||
{ role: 'user', content: '请提供更具体的建议和实例。' }
|
||||
{ role: 'user', content: '{{currentPrompt}},请提供多种解决方案并对比优缺点' }
|
||||
]
|
||||
}
|
||||
]
|
||||
]
|
||||
@@ -160,3 +160,6 @@ export type {
|
||||
// 导出新增的类型和服务
|
||||
export * from './types'
|
||||
export * from './services'
|
||||
|
||||
// 导出快速模板管理器
|
||||
export { quickTemplateManager } from './data/quickTemplates'
|
||||
+41
-15
@@ -351,6 +351,9 @@ hljs.registerLanguage('json', jsonLang)
|
||||
// Types from UI package
|
||||
type OptimizationMode,
|
||||
type ConversationMessage,
|
||||
|
||||
// Quick Template Manager
|
||||
quickTemplateManager,
|
||||
} from '@prompt-optimizer/ui'
|
||||
import type { IPromptService } from '@prompt-optimizer/core'
|
||||
|
||||
@@ -783,27 +786,50 @@ hljs.registerLanguage('json', jsonLang)
|
||||
}
|
||||
})
|
||||
|
||||
// 监听高级模式和优化模式变化,自动加载默认对话模板
|
||||
// 监听高级模式和优化模式变化,自动加载默认快速模板
|
||||
watch(
|
||||
[advancedModeEnabled, selectedOptimizationMode],
|
||||
([newAdvancedMode, newOptimizationMode]) => {
|
||||
// 当启用高级模式时,根据优化模式自动加载默认对话模板
|
||||
// 当启用高级模式时,根据优化模式自动加载默认快速模板
|
||||
if (newAdvancedMode) {
|
||||
// 如果当前没有优化上下文或者是空的,则设置默认模板
|
||||
if (!optimizationContext.value || optimizationContext.value.length === 0) {
|
||||
if (newOptimizationMode === 'system') {
|
||||
// 系统提示词优化模式:系统消息 + 用户消息
|
||||
optimizationContext.value = [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
console.log('[App] Auto-loaded default conversation template for system prompt optimization')
|
||||
} else if (newOptimizationMode === 'user') {
|
||||
// 用户提示词优化模式:用户消息(可以添加系统上下文)
|
||||
optimizationContext.value = [
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
console.log('[App] Auto-loaded default conversation template for user prompt optimization')
|
||||
try {
|
||||
// 根据优化模式获取默认模板
|
||||
const defaultTemplate = quickTemplateManager.getTemplate(newOptimizationMode, 'default')
|
||||
|
||||
if (defaultTemplate && defaultTemplate.messages) {
|
||||
optimizationContext.value = [...defaultTemplate.messages]
|
||||
console.log(`[App] Auto-loaded default ${newOptimizationMode} template: ${defaultTemplate.name}`)
|
||||
} else {
|
||||
// 如果获取模板失败,回退到硬编码逻辑
|
||||
console.warn(`[App] Failed to load default ${newOptimizationMode} template, using fallback`)
|
||||
if (newOptimizationMode === 'system') {
|
||||
optimizationContext.value = [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
} else if (newOptimizationMode === 'user') {
|
||||
optimizationContext.value = [
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// 如果获取模板失败,回退到硬编码逻辑
|
||||
console.warn('[App] Failed to load default template, using fallback logic:', error)
|
||||
if (newOptimizationMode === 'system') {
|
||||
optimizationContext.value = [
|
||||
{ role: 'system', content: '{{currentPrompt}}' },
|
||||
{ role: 'user', content: '{{userQuestion}}' }
|
||||
]
|
||||
console.log('[App] Auto-loaded fallback template for system prompt optimization')
|
||||
} else if (newOptimizationMode === 'user') {
|
||||
optimizationContext.value = [
|
||||
{ role: 'user', content: '{{currentPrompt}}' }
|
||||
]
|
||||
console.log('[App] Auto-loaded fallback template for user prompt optimization')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user