prompt-refiner-gpt
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGPT Prompt Refiner
GPT提示词优化指南
Refine prompts to get better results from GPT models by applying OpenAI's recommended patterns.
通过应用OpenAI推荐的模式优化提示词,从而从GPT模型获得更优结果。
When to Use
适用场景
Invoke this skill when you have a task for GPT that:
- Requires a specific persona or expertise
- Involves procedural steps
- Needs structured output
- Benefits from explicit examples
当你有以下类型的GPT任务时,可使用本方法:
- 需要特定角色或专业能力
- 涉及流程化步骤
- 需要结构化输出
- 可通过明确示例提升效果
Refinement Process
优化流程
Step 1: Analyze the Draft Prompt
步骤1:分析初稿提示词
Review the user's prompt for:
- Clear role/persona definition
- Step-by-step breakdown (if procedural)
- Output format specification
- Concrete examples
Ask clarifying questions if any of these are missing.
检查用户的提示词是否包含:
- 清晰的角色/人设定义
- 分步骤拆解(如果是流程化任务)
- 输出格式说明
- 具体示例
如果有缺失项,可提出澄清问题。
Step 2: Apply GPT-Specific Patterns
步骤2:应用GPT专属优化模式
Role framing:
GPT models respond well to clear role definitions. Start with:
"You are a [specific role] working on [specific context]..."
Numbered procedures:
Break complex tasks into numbered steps that build on each other.
Output specification:
Be explicit about format: "Return as JSON", "Format as markdown with headers", etc.
Chain of thought:
For reasoning tasks, add: "Think through this step by step."
角色设定:
GPT模型对清晰的角色定义响应更好。可以这样开头:
"你是一名[具体角色],正在处理[具体场景]..."
编号流程:
将复杂任务拆解为循序渐进的编号步骤。
输出格式指定:
明确说明输出格式:"以JSON格式返回"、"以带标题的Markdown格式呈现"等。
思维链引导:
对于推理类任务,添加:"请逐步思考这个问题。"
Step 3: Structure the Prompt
步骤3:构建提示词结构
Effective order for GPT:
- Role definition (who/what)
- Context (background info)
- Task (what to do)
- Steps (how to do it, if procedural)
- Output format (what to return)
- Examples (optional clarification)
对GPT有效的内容顺序:
- 角色定义(身份/定位)
- 场景背景(相关信息)
- 任务目标(需要完成的工作)
- 执行步骤(如果是流程化任务,说明如何操作)
- 输出格式(返回内容的形式)
- 示例(可选,用于明确要求)
Step 4: Output the Refined Prompt
步骤4:输出优化后的提示词
Present the improved prompt with:
- Clear role statement
- Numbered steps where applicable
- Explicit output requirements
- An explanation of what changed and why
呈现优化后的提示词时,需包含:
- 清晰的角色说明
- 适用的编号步骤
- 明确的输出要求
- 说明修改内容及原因
Example Transformations
示例转换
Example 1: Security Review
示例1:安全审查
Before:
Review this code for security issuesAfter:
You are a senior security engineer conducting a security audit of a Node.js payment processing service.
Context: This service handles credit card transactions and communicates with Stripe's API. It runs in AWS ECS with access to a PostgreSQL database.
Task: Review the code in src/payments/ for security vulnerabilities.
Complete these steps:
1. Check for proper input validation on all endpoints
2. Verify secrets are not hardcoded or logged
3. Review authentication and authorization logic
4. Check for SQL injection and XSS vulnerabilities
5. Verify proper error handling that doesn't leak sensitive info
6. Review rate limiting and abuse prevention
Output format:
Return a security report in markdown with these sections:
- **Critical**: Issues that must be fixed before deployment
- **High**: Significant risks that should be addressed soon
- **Medium**: Improvements to consider
- **Recommendations**: General security enhancements
For each issue, include:
- File and line number
- Description of the vulnerability
- OWASP category if applicable
- Recommended fix with code example优化前:
Review this code for security issues优化后:
You are a senior security engineer conducting a security audit of a Node.js payment processing service.
Context: This service handles credit card transactions and communicates with Stripe's API. It runs in AWS ECS with access to a PostgreSQL database.
Task: Review the code in src/payments/ for security vulnerabilities.
Complete these steps:
1. Check for proper input validation on all endpoints
2. Verify secrets are not hardcoded or logged
3. Review authentication and authorization logic
4. Check for SQL injection and XSS vulnerabilities
5. Verify proper error handling that doesn't leak sensitive info
6. Review rate limiting and abuse prevention
Output format:
Return a security report in markdown with these sections:
- **Critical**: Issues that must be fixed before deployment
- **High**: Significant risks that should be addressed soon
- **Medium**: Improvements to consider
- **Recommendations**: General security enhancements
For each issue, include:
- File and line number
- Description of the vulnerability
- OWASP category if applicable
- Recommended fix with code exampleExample 2: Refactoring Task
示例2:重构任务
Before:
Refactor this function to be cleanerAfter:
You are a senior TypeScript developer focused on code quality and maintainability.
Context: This function in src/utils/dataProcessor.ts handles data transformation for our analytics pipeline. It currently has high cyclomatic complexity and is difficult to test.
Task: Refactor the processData function to improve readability and testability.
Steps:
1. Analyze the current function and identify code smells
2. Extract logical units into smaller, focused functions
3. Add TypeScript types for all parameters and return values
4. Ensure each extracted function is independently testable
5. Preserve all existing behavior (no functional changes)
6. Add JSDoc comments for public functions
Output format:
1. Brief analysis of issues in the current code (3-5 bullet points)
2. The refactored code
3. List of extracted functions with their responsibilities
4. Example test cases for the new functions优化前:
Refactor this function to be cleaner优化后:
You are a senior TypeScript developer focused on code quality and maintainability.
Context: This function in src/utils/dataProcessor.ts handles data transformation for our analytics pipeline. It currently has high cyclomatic complexity and is difficult to test.
Task: Refactor the processData function to improve readability and testability.
Steps:
1. Analyze the current function and identify code smells
2. Extract logical units into smaller, focused functions
3. Add TypeScript types for all parameters and return values
4. Ensure each extracted function is independently testable
5. Preserve all existing behavior (no functional changes)
6. Add JSDoc comments for public functions
Output format:
1. Brief analysis of issues in the current code (3-5 bullet points)
2. The refactored code
3. List of extracted functions with their responsibilities
4. Example test cases for the new functionsExample 3: API Design
示例3:API设计
Before:
Design an API for user managementAfter:
You are an API architect designing a RESTful API for a B2B SaaS application.
Context: We need user management endpoints for our multi-tenant application. Users belong to organizations, and permissions are role-based (admin, member, viewer).
Task: Design a complete REST API for user management operations.
Requirements:
1. CRUD operations for users
2. Organization membership management
3. Role assignment and permission checking
4. Invitation flow for new users
5. Password reset functionality
Constraints:
- Follow REST best practices
- Use consistent naming conventions
- Support pagination for list endpoints
- Include proper error responses
Output format:
For each endpoint, provide:
- HTTP method and path
- Request body schema (if applicable)
- Response schema
- Possible error codes
- Example request/response
Use OpenAPI 3.0 YAML format for the specification.优化前:
Design an API for user management优化后:
You are an API architect designing a RESTful API for a B2B SaaS application.
Context: We need user management endpoints for our multi-tenant application. Users belong to organizations, and permissions are role-based (admin, member, viewer).
Task: Design a complete REST API for user management operations.
Requirements:
1. CRUD operations for users
2. Organization membership management
3. Role assignment and permission checking
4. Invitation flow for new users
5. Password reset functionality
Constraints:
- Follow REST best practices
- Use consistent naming conventions
- Support pagination for list endpoints
- Include proper error responses
Output format:
For each endpoint, provide:
- HTTP method and path
- Request body schema (if applicable)
- Response schema
- Possible error codes
- Example request/response
Use OpenAPI 3.0 YAML format for the specification.Example 4: Debugging
示例4:调试
Before:
Why is this test failing?After:
You are a senior developer debugging a failing test in a React application.
Context: The test in UserProfile.test.tsx is failing intermittently in CI but passes locally. The component fetches user data and displays it.
Task: Analyze the test and identify the root cause of the flaky failure.
Think through this step by step:
1. What async operations does the test involve?
2. Are there any race conditions?
3. Is the test properly waiting for state updates?
4. Are mocks set up correctly?
5. Could there be timing issues with the test environment?
Output format:
1. Most likely root cause (1-2 sentences)
2. Evidence supporting your diagnosis
3. Recommended fix with code
4. How to verify the fix works优化前:
Why is this test failing?优化后:
You are a senior developer debugging a failing test in a React application.
Context: The test in UserProfile.test.tsx is failing intermittently in CI but passes locally. The component fetches user data and displays it.
Task: Analyze the test and identify the root cause of the flaky failure.
Think through this step by step:
1. What async operations does the test involve?
2. Are there any race conditions?
3. Is the test properly waiting for state updates?
4. Are mocks set up correctly?
5. Could there be timing issues with the test environment?
Output format:
1. Most likely root cause (1-2 sentences)
2. Evidence supporting your diagnosis
3. Recommended fix with code
4. How to verify the fix worksTips for Best Results
最佳实践技巧
- Define the role clearly - "senior security engineer" > "developer"
- Number your steps - GPT follows ordered lists reliably
- Specify output format explicitly - JSON, markdown, etc.
- Use "Think through this step by step" for reasoning tasks
- Provide examples when the expected format is complex
- Include constraints to prevent scope creep
- 清晰定义角色 - "资深安全工程师" > "开发者"
- 为步骤编号 - GPT能可靠地遵循有序列表
- 明确指定输出格式 - JSON、Markdown等
- 推理类任务使用“请逐步思考这个问题”
- 当预期格式复杂时提供示例
- 添加约束条件以避免范围偏离