用途
本技能是一份关于提示工程模式、最佳实践与优化技术的专家指南。当用户希望改进提示词、学习提示策略,或需要提升大语言模型(LLM)的性能、可靠性与可控性时,可参考本指南。
主要能力
1. 少样本学习(Few-Shot Learning)
通过展示示例而非解释规则来教会模型。包含 2-5 个输入-输出对,用以演示期望的行为。适用于需要一致格式、特定推理模式或处理边界情况的场景。更多示例可提升准确率,但会消耗 token,需根据任务复杂度权衡。
示例(从支持工单中提取关键信息):
输入:"My login doesn't work and I keep getting error 403" 输出:{"issue": "authentication", "error_code": "403", "priority": "high"}
输入:"Feature request: add dark mode to settings" 输出:{"issue": "feature_request", "error_code": null, "priority": "low"}
待处理:"Can't upload files larger than 10MB, getting timeout"
2. 思维链提示(Chain-of-Thought Prompting)
在给出最终答案前要求逐步推理。可添加 "Let's think step by step"(零样本),或包含示例推理轨迹(少样本)。适用于需要多步逻辑、数学推理的复杂问题,或需要验证模型思考过程的场景。据资料所述,可将分析类任务的准确率提升 30-50%。
示例:
Analyze this bug report and determine root cause.
Think step by step:
1. What is the expected behavior?
2. What is the actual behavior?
3. What changed recently that could cause this?
4. What components are involved?
5. What is the most likely root cause?
Bug: "Users can't save drafts after the cache update deployed yesterday"
3. 提示优化(Prompt Optimization)
通过测试与迭代系统性地改进提示。从简单开始,衡量性能(准确率、一致性、token 使用量),然后迭代。在多样化输入(包括边界情况)上测试,使用 A/B 测试比较不同版本。对于一致性与成本敏感的生产环境提示尤为关键。
示例:
版本 1(简单):"Summarize this article" → 结果:长度不一致,遗漏要点
版本 2(添加约束):"Summarize in 3 bullet points" → 结果:结构更好,但仍遗漏细节
版本 3(添加推理):"Identify the 3 main findings, then summarize each" → 结果:一致、准确,捕捉关键信息
4. 模板系统(Template Systems)
构建带变量、条件区块与模块化组件的可复用提示结构。适用于多轮对话、基于角色的交互,或同一模式应用于不同输入的场景。可减少重复并确保相似任务的一致性。
示例:
# Reusable code review template
template = """
Review this {language} code for {focus_area}.
Code:
{code_block}
Provide feedback on:
{checklist}
"""
# Usage
prompt = template.format(
language="Python",
focus_area="security vulnerabilities",
code_block=user_code,
checklist="1. SQL injection\n2. XSS risks\n3. Authentication"
)
5. 系统提示设计(System Prompt Design)
设置在整个对话中持续生效的全局行为与约束。定义模型的角色、专业水平、输出格式与安全准则。系统提示用于不应逐轮变化的稳定指令,从而释放用户消息的 token 用于可变内容。
示例:
System: You are a senior backend engineer specializing in API design.
Rules:
- Always consider scalability and performance
- Suggest RESTful patterns by default
- Flag security concerns immediately
- Provide code examples in Python
- Use early return pattern
Format responses as:
- Analysis
- Recommendation
- Code example
- Trade-offs
关键模式
渐进式披露(Progressive Disclosure)
从简单提示开始,仅在需要时增加复杂度:
- 第 1 级:直接指令
"Summarize this article"
- 第 2 级:添加约束
"Summarize this article in 3 bullet points, focusing on key findings"
- 第 3 级:添加推理
"Read this article, identify the main findings, then summarize in 3 bullet points"
- 第 4 级:添加示例
包含 2-3 个带输入-输出对的示例摘要
指令层级(Instruction Hierarchy)
[System Context] → [Task Instruction] → [Examples] → [Input Data] → [Output Format]
错误恢复(Error Recovery)
构建能优雅处理失败的提示:
- 包含回退指令
- 请求置信度分数
- 在不确定时请求替代解释
- 指定如何标示缺失信息
最佳实践
- 具体明确:模糊的提示会产生不一致的结果
- 展示而非讲述:示例比描述更有效
- 充分测试:在多样化、有代表性的输入上评估
- 快速迭代:小改动可能带来大影响
- 监控性能:在生产环境中跟踪指标
- 版本控制:将提示视为代码并进行适当版本管理
- 记录意图:解释提示为何如此结构化
常见陷阱
- 过度工程:在尝试简单提示前就使用复杂提示
- 示例污染:使用与目标任务不匹配的示例
- 上下文溢出:过多示例超出 token 限制
- 指令模糊:留下多种解释空间
- 忽视边界情况:未在异常或边界输入上测试
适用场景与限制
本指南适用于提示词改进、提示策略学习与生产提示优化等场景。资料未提供具体的安装命令、收费方式、价格或平台支持信息,相关内容暂未提供。