mcpField
O
openai-prompt-engineer

openai-prompt-engineer

github.com/jamesrochabrunAgent 工作流221206 次安装41 周前更新
代码仓库

关于 openai-prompt-engineer

面向 GPT-5、Claude 和其他大模型的提示词工程 Skill,可创建、评估和改进提示词。它结合通用技巧、模型专属建议,以及测试迭代流程。

主要功能

  1. 01生成和改写提示词
  2. 02分析提示词质量并提出修改建议
  3. 03应用少样本与思维链技巧
  4. 04针对 GPT-5 和 Claude 组织提示词
  5. 05明确输出格式与约束

适用场景

  1. 01为新任务起草提示词
  2. 02改进结果不稳定的现有提示词
  3. 03为 GPT-5 或 Claude 调整提示词
  4. 04检查提示词的清晰度和约束遗漏

MCP 相关

这是一个 Agent Skill,并非 MCP 服务或客户端;README 未说明 MCP 连接方式。

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/jamesrochabrun/skills --skill openai-prompt-engineer

安装后在 Claude Code 中输入/openai-prompt-engineer确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
claude_techniques.md
gpt5_techniques.md
optimization_strategies.md
prompt_patterns.md

详细介绍

OpenAI 提示词工程师

一项全面的技能,用于为 OpenAI 的 GPT-5 和其他现代大模型(LLM)编写、分析和改进提示词,重点关注 GPT-5 专属优化和通用提示技巧。

此技能的作用

帮助你运用前沿技巧创建和优化提示词:

  • 生成新提示词 - 从零开始编写有效的提示词
  • 改进现有提示词 - 提升清晰度、结构和效果
  • 应用最佳实践 - 针对每种模型采用经过验证的技巧
  • 针对特定模型优化 - GPT-5、Claude 专属策略
  • 实现高级模式 - 思维链、少样本、结构化提示
  • 分析提示词质量 - 发现问题并提出改进建议

提示词工程为何重要

缺少优质提示词时:

  • 输出不一致或不正确
  • 指令遵循效果不佳
  • 浪费 token 并增加 API 成本
  • 需要多次尝试
  • 行为难以预测

使用优化后的提示词时:

  • 结果准确且一致
  • 更好地遵循指令
  • 降低成本和延迟
  • 首次尝试即可成功
  • 输出可预测且可靠

支持的模型与方法

GPT-5(OpenAI)
  • 结构化提示(角色 + 任务 + 约束)
  • 推理力度校准
  • Agent 行为控制
  • 冗长度管理
  • 提示词优化器集成
Claude(Anthropic)
  • XML 标签结构
  • 逐步思考
  • 清晰、具体的指令
  • 示例驱动的提示
  • 渐进式披露
通用技巧
  • 思维链提示
  • 少样本学习
  • 零样本提示
  • 自洽性
  • 基于角色的提示

核心提示原则

1. 清晰具体

不佳:“写一篇关于 AI 的文章” 良好:“为有 2-3 年经验的软件工程师写一篇 500 字的技术文章,解释 Transformer 架构。请加入 Python 代码示例,并侧重实际实现。”

2. 提供结构

使用清晰的格式组织指令:

Role: You are a senior Python developer
Task: Review this code for security vulnerabilities
Constraints:
- Focus on OWASP Top 10
- Provide specific line numbers
- Suggest fixes with code examples
Output format: Markdown with severity ratings
3. 使用示例(少样本)

向模型展示你想要的内容:

Input: "User clicked login"
Output: "USER_LOGIN_CLICKED"

Input: "Payment processed successfully"
Output: "PAYMENT_PROCESSED_SUCCESS"

Input: "Email verification failed"
Output: [Your turn]
4. 启用推理

添加类似以下短语:

  • “逐步思考”
  • “我们来逐一分析”
  • “首先分析……然后……”
  • “展示你的推理过程”
5. 定义输出格式

明确指定你希望得到的回复格式:

<output_format>
  <summary>One sentence overview</summary>
  <details>
    <point>Key finding 1</point>
    <point>Key finding 2</point>
  </details>
  <recommendation>Specific action to take</recommendation>
</output_format>

提示词工程工作流

1. 明确目标
  • 你要解决什么任务?
  • 理想的输出是什么?
  • 受众是谁?
  • 你将使用哪种模型?
2. 选择技巧
  • 简单任务? → 直接指令
  • 复杂推理? → 思维链
  • 模式匹配? → 少样本示例
  • 需要一致性? → 结构化格式 + 示例
3. 编写提示词

使用此模板:

[ROLE/CONTEXT]
You are [specific role with relevant expertise]

[TASK]
[Clear, specific task description]

[CONSTRAINTS]
- [Limitation 1]
- [Limitation 2]

[FORMAT]
Output should be [exact format specification]

[EXAMPLES - if using few-shot]
[Example 1]
[Example 2]

[THINK STEP-BY-STEP - if complex reasoning]
Before answering, [thinking instruction]
4. 测试并迭代
  • 运行提示词
  • 分析输出质量
  • 发现问题
  • 优化并重试
  • 记录有效做法

高级技巧

思维链(CoT)提示

**适用场景:**复杂推理、数学、多步骤问题

**工作原理:**要求模型展示中间步骤

示例:

Problem: A store has 15 apples. They sell 60% in the morning and
half of what's left in the afternoon. How many remain?

Please solve this step-by-step:
1. Calculate morning sales
2. Calculate remaining after morning
3. Calculate afternoon sales
4. Calculate final remaining

**结果:**通过明确推理获得更准确的答案

少样本提示

**适用场景:**模式匹配、分类、风格迁移

**工作原理:**提供 2-5 个示例,然后给出实际任务

示例:

Convert casual text to professional business tone:

Input: "Hey! Thanks for reaching out. Let's chat soon!"
Output: "Thank you for your message. I look forward to our conversation."

Input: "That's a great idea! I'm totally on board with this."
Output: "I appreciate your suggestion and fully support this initiative."

Input: "Sounds good, catch you later!"
Output: [Model completes]
零样本思维链

**适用场景:**没有示例的复杂问题

**工作原理:**只需添加“我们来逐步思考”

示例:

Question: What are the security implications of storing JWTs
in localStorage?

Let's think step by step:

神奇短语:“我们来逐步思考” → 显著提升推理能力

使用 XML 生成结构化输出

**适用场景:**使用 Claude 或需要可解析的输出

示例:

Analyze this code for issues. Structure your response as:

<analysis>
  <security_issues>
    <issue severity="high|medium|low">
      <description>What's wrong</description>
      <location>File and line number</location>
      <fix>How to fix it</fix>
    </issue>
  </security_issues>
  <performance_issues>
    
  </performance_issues>
  <best_practices>
    <suggestion>Improvement suggestion</suggestion>
  </best_practices>
</analysis>
渐进式披露

**适用场景:**大上下文、多步骤工作流

**工作原理:**将任务拆分为多个阶段,只请求当前所需内容

示例:

Stage 1: "Analyze this codebase structure and list the main components"
[Get response]

Stage 2: "Now, for the authentication component you identified,
show me the security review"
[Get response]

Stage 3: "Based on that review, generate fixes for the high-severity issues"

针对特定模型的最佳实践

GPT-5 优化

结构化提示词:

ROLE: Senior TypeScript Developer
TASK: Implement user authentication service
CONSTRAINTS:
- Use JWT with refresh tokens
- TypeScript with strict mode
- Include comprehensive error handling
- Follow SOLID principles
OUTPUT: Complete TypeScript class with JSDoc comments
REASONING_EFFORT: high (for complex business logic)

控制 Agent 行为:

"Implement this feature step-by-step, asking for confirmation
before each major decision"

OR

"Complete this task end-to-end without asking for guidance.
Persist until fully handled."

管理详略程度:

"Provide a concise implementation (under 100 lines) focusing
only on core functionality"
Claude 优化

使用 XML 标签:

<instruction>
Review this pull request for security issues
</instruction>

<code>
[Code to review]
</code>

<focus_areas>
- SQL injection vulnerabilities
- XSS attack vectors
- Authentication bypasses
- Data exposure risks
</focus_areas>

<output_format>
For each issue found, provide:
1. Severity (Critical/High/Medium/Low)
2. Location
3. Explanation
4. Fix recommendation
</output_format>

循序渐进地思考:

Think through this architecture decision step by step:
1. First, identify the requirements
2. Then, list possible approaches
3. Evaluate trade-offs for each
4. Make a recommendation with reasoning

明确具体:

BAD: "Make the response professional"
GOOD: "Use formal business language, avoid contractions,
address the user as 'you', keep sentences under 20 words"

提示词改进清单

使用此清单改进任何提示词:

  • 明确角色 - 是否指定了 AI 的专业领域?
  • 具体任务 - 要做什么是否清晰明确?
  • 列出约束 - 限制是否清晰?
  • 指定格式 - 是否定义了输出结构?
  • 提供示例 - 是否展示了你想要的内容(如有需要)?
  • 启用推理 - 如果任务复杂,是否要求逐步思考?
  • 包含上下文 - AI 是否具备必要的背景信息?
  • 涵盖边缘情况 - 是否处理了例外情况?
  • 指定长度 - 输出长度是否明确?
  • 定义语气和风格 - 是否指定了期望的表达方式?

常见提示词问题及修复方法

问题:指令含糊

修改前:

"Write some code for user authentication"

修改后:

"Write a TypeScript class called AuthService that:
- Accepts email/password credentials
- Validates against a User repository
- Returns a JWT token on success
- Throws AuthenticationError on failure
- Includes comprehensive JSDoc comments
- Follows dependency injection pattern"
问题:缺少示例(有需要时)

修改前:

"Convert these variable names to camelCase"

修改后:

"Convert these variable names to camelCase:

user_name → userName
total_count → totalCount
is_active → isActive

Now convert:
order_status →
created_at →
max_retry_count →"
问题:缺少输出格式

修改前:

"Analyze this code for problems"

修改后:

"Analyze this code and output in this format:

## Security Issues
- [Issue]: [Description] (Line X)

## Performance Issues
- [Issue]: [Description] (Line X)

## Code Quality
- [Issue]: [Description] (Line X)

## Recommendations
1. [Priority 1 fix]
2. [Priority 2 fix]"
问题:任务过于复杂(一次完成)

修改前:

"Build a complete e-commerce backend with authentication,
payments, inventory, and shipping"

修改后(渐进式):

"Let's build this in stages:

Stage 1: Design the authentication system architecture
[Get response, review]

Stage 2: Implement the auth service
[Get response, review]

Stage 3: Add payment processing
[Continue...]"

使用此技能

生成新提示词

提问:

"Using the prompt-engineer skill, create a prompt for:
[Describe your task and requirements]"

你将获得:

  • 结构化提示词模板
  • 推荐技巧
  • 适用时提供的少样本示例
  • 针对特定模型的优化
改进现有提示词

提问:

"Using the prompt-engineer skill, improve this prompt:

[Your current prompt]

Goal: [What you want to achieve]
Model: [GPT-5 / Claude / Other]"

你将获得:

  • 对当前问题的分析
  • 改进后的版本
  • 修改说明
  • 预期效果提升
分析提示词质量

提问:

"Using the prompt-engineer skill, analyze this prompt:
[Your prompt]"

你将获得:

  • 质量评分
  • 已发现的弱点
  • 具体的改进建议
  • 违反最佳实践之处

实际案例

示例 1:代码审查提示词

任务: 获得全面、一致的代码审查

优化后的提示词:

ROLE: Senior Software Engineer conducting PR review

REVIEW THIS CODE:
[code block]

REVIEW CRITERIA:
1. Security vulnerabilities (OWASP Top 10)
2. Performance issues
3. Code quality and readability
4. Best practices compliance
5. Test coverage gaps

OUTPUT FORMAT:
For each issue found:
- Severity: [Critical/High/Medium/Low]
- Category: [Security/Performance/Quality/Testing]
- Location: [File:Line]
- Issue: [Clear description]
- Impact: [Why this matters]
- Fix: [Specific code recommendation]

At the end, provide:
- Overall assessment (Approve/Request Changes/Comment)
- Summary of critical items that must be fixed
示例 2:技术文档

任务: 生成清晰的 API 文档

优化后的提示词:

ROLE: Technical writer with API documentation expertise

TASK: Generate API documentation for this endpoint

ENDPOINT DETAILS:
[code/specs]

DOCUMENTATION REQUIREMENTS:
- Target audience: Junior to mid-level developers
- Include curl and JavaScript examples
- Explain all parameters clearly
- Show example responses with descriptions
- Include common error cases
- Add troubleshooting section

FORMAT:
# [Endpoint Name]

## Overview
[One paragraph description]

## Endpoint
`[HTTP METHOD] /path`

## Parameters
| Name | Type | Required | Description |
|------|------|----------|-------------|

## Request Example
```bash
[curl example]

响应

成功(200)
[example with inline comments]
错误
  • 400:[说明和修复方法]
  • 401:[说明和修复方法]

常见问题

[故障排除指南]


### Example 3: Data Analysis

**Task:** Analyze data and provide insights

**Optimized Prompt:**

角色:精通业务指标的数据分析师

数据: [数据集]

分析请求: 逐步分析这些数据:

  1. 首先:识别关键指标和趋势
  2. 然后:计算:
    • 增长率(环比)
    • 平均值
    • 异常情况或离群值
  3. 接下来:得出业务洞察
  4. 最后:提供可执行的建议

输出格式:

执行摘要

[2-3 句话]

关键指标

| 指标 | 数值 | 变化 | 趋势 |

洞察

  1. [包含支持数据的洞察]
  2. [包含支持数据的洞察]

建议

  1. [行动]:[预期影响]
  2. [行动]:[预期影响]

方法

[简要说明分析方法]


## Best Practices Summary

### DO ✅

- **Be specific** - Exact requirements, not vague requests
- **Use structure** - Organize with clear sections
- **Provide examples** - Show what you want (few-shot)
- **Request reasoning** - "Think step-by-step" for complex tasks
- **Define format** - Specify exact output structure
- **Test iteratively** - Refine based on results
- **Match to model** - Use model-specific techniques
- **Include context** - Give necessary background
- **Handle edge cases** - Specify exception handling
- **Set constraints** - Define limitations clearly

### DON'T ❌

- **Be vague** - "Write something about X"
- **Skip examples** - When patterns need to be matched
- **Assume format** - Model will choose unpredictably
- **Overload single prompt** - Break complex tasks into stages
- **Ignore model differences** - GPT-5 and Claude need different approaches
- **Give up too soon** - Iterate on prompts
- **Mix instructions** - Keep separate concerns separate
- **Forget constraints** - Specify ALL requirements
- **Use ambiguous terms** - "Good", "professional", "better" without definition
- **Skip testing** - Always validate outputs

## Quick Reference

### Prompt Template (Universal)

[角色] 你是[具体专业领域的专家]

[上下文] [背景信息]

[任务] [清晰、具体的任务]

[约束]

  • [限制 1]
  • [限制 2]

[格式] [确切的输出结构]

[示例 - 可选] [2-3 个示例]

[推理 - 可选] 按步骤思考: [思考指导]


### When to Use Each Technique

| Technique | Best For | Example Use Case |
|-----------|----------|------------------|
| Chain-of-Thought | Complex reasoning | Math, logic puzzles, multi-step analysis |
| Few-Shot | Pattern matching | Classification, style transfer, formatting |
| Zero-Shot | Simple, clear tasks | Direct questions, basic transformations |
| Structured (XML) | Parsed output | Data extraction, API responses |
| Progressive Disclosure | Large tasks | Full implementations, research |
| Role-Based | Expert knowledge | Code review, architecture decisions |

### Model Selection Guide

**Use GPT-5 when:**
- Need strong reasoning
- Agentic behavior helpful
- Code generation focus
- Latest knowledge needed

**Use Claude when:**
- Very long context (100K+ tokens)
- Detailed instruction following
- Safety-critical applications
- Prefer XML structuring

## Resources

All reference materials included:
- GPT-5 specific techniques and patterns
- Claude optimization strategies
- Advanced prompting patterns
- Optimization and improvement frameworks

## Summary

Effective prompt engineering:
- **Saves time** - Get right results faster
- **Reduces costs** - Fewer API calls needed
- **Improves quality** - More accurate, consistent outputs
- **Enables complexity** - Tackle harder problems
- **Scales knowledge** - Capture best practices

Use this skill to create prompts that:
- Are clear and specific
- Use proven techniques
- Match your model
- Get consistent results
- Achieve your goals

---

**Remember:** A well-crafted prompt is worth 10 poorly-attempted ones. Invest time upfront for better results.

评论

支持 Markdown