prompt-engineering

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Prompt Engineering Guide

提示词工程指南

Master prompt engineering for AI models via inference.sh CLI.
Prompt Engineering Guide
通过inference.sh CLI精通AI模型的提示词工程。
Prompt Engineering Guide

Quick Start

快速开始

bash
curl -fsSL https://cli.inference.sh | sh && infsh login
bash
curl -fsSL https://cli.inference.sh | sh && infsh login

Well-structured LLM prompt

结构清晰的LLM提示词

infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "You are a senior software engineer. Review this code for security vulnerabilities:\n\n
python\nuser_input = request.args.get(\"query\")\nresult = db.execute(f\"SELECT * FROM users WHERE name = {user_input}\")\n
\n\nProvide specific issues and fixes." }'
undefined
infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "You are a senior software engineer. Review this code for security vulnerabilities:\n\n
python\nuser_input = request.args.get(\"query\")\nresult = db.execute(f\"SELECT * FROM users WHERE name = {user_input}\")\n
\n\nProvide specific issues and fixes." }'
undefined

LLM Prompting

LLM提示词编写

Basic Structure

基本结构

[Role/Context] + [Task] + [Constraints] + [Output Format]
[角色/上下文] + [任务] + [约束条件] + [输出格式]

Role Prompting

角色提示法

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "You are an expert data scientist with 15 years of experience in machine learning. Explain gradient descent to a beginner, using simple analogies."
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "You are an expert data scientist with 15 years of experience in machine learning. Explain gradient descent to a beginner, using simple analogies."
}'

Task Clarity

任务明确性

bash
undefined
bash
undefined

Bad: vague

反面示例:模糊

"Help me with my code"
"Help me with my code"

Good: specific

正面示例:具体

"Debug this Python function that should return the sum of even numbers from a list, but returns 0 for all inputs:
def sum_evens(numbers): total = 0 for n in numbers: if n % 2 == 0: total += n return total
Identify the bug and provide the corrected code."
undefined
"Debug this Python function that should return the sum of even numbers from a list, but returns 0 for all inputs:
def sum_evens(numbers): total = 0 for n in numbers: if n % 2 == 0: total += n return total
Identify the bug and provide the corrected code."
undefined

Chain-of-Thought

思维链法

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Solve this step by step:\n\nA store sells apples for $2 each and oranges for $3 each. If someone buys 5 fruits and spends $12, how many of each fruit did they buy?\n\nThink through this step by step before giving the final answer."
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Solve this step by step:\n\nA store sells apples for $2 each and oranges for $3 each. If someone buys 5 fruits and spends $12, how many of each fruit did they buy?\n\nThink through this step by step before giving the final answer."
}'

Few-Shot Examples

少样本示例法

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Convert these sentences to formal business English:\n\nExample 1:\nInput: gonna send u the report tmrw\nOutput: I will send you the report tomorrow.\n\nExample 2:\nInput: cant make the meeting, something came up\nOutput: I apologize, but I will be unable to attend the meeting due to an unforeseen circumstance.\n\nNow convert:\nInput: hey can we push the deadline back a bit?"
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Convert these sentences to formal business English:\n\nExample 1:\nInput: gonna send u the report tmrw\nOutput: I will send you the report tomorrow.\n\nExample 2:\nInput: cant make the meeting, something came up\nOutput: I apologize, but I will be unable to attend the meeting due to an unforeseen circumstance.\n\nNow convert:\nInput: hey can we push the deadline back a bit?"
}'

Output Format Specification

输出格式指定

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Analyze the sentiment of these customer reviews. Return a JSON array with objects containing \"text\", \"sentiment\" (positive/negative/neutral), and \"confidence\" (0-1).\n\nReviews:\n1. \"Great product, fast shipping!\"\n2. \"Meh, its okay I guess\"\n3. \"Worst purchase ever, total waste of money\"\n\nReturn only valid JSON, no explanation."
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Analyze the sentiment of these customer reviews. Return a JSON array with objects containing \"text\", \"sentiment\" (positive/negative/neutral), and \"confidence\" (0-1).\n\nReviews:\n1. \"Great product, fast shipping!\"\n2. \"Meh, its okay I guess\"\n3. \"Worst purchase ever, total waste of money\"\n\nReturn only valid JSON, no explanation."
}'

Constraint Setting

约束条件设置

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Summarize this article in exactly 3 bullet points. Each bullet must be under 20 words. Focus only on actionable insights, not background information.\n\n[article text]"
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Summarize this article in exactly 3 bullet points. Each bullet must be under 20 words. Focus only on actionable insights, not background information.\n\n[article text]"
}'

Image Generation Prompting

图像生成提示词编写

Basic Structure

基本结构

[Subject] + [Style] + [Composition] + [Lighting] + [Technical]
[主体] + [风格] + [构图] + [光线] + [技术参数]

Subject Description

主体描述

bash
undefined
bash
undefined

Bad: vague

反面示例:模糊

"a cat"
"a cat"

Good: specific

正面示例:具体

infsh app run falai/flux-dev --input '{ "prompt": "A fluffy orange tabby cat with green eyes, sitting on a vintage leather armchair" }'
undefined
infsh app run falai/flux-dev --input '{ "prompt": "A fluffy orange tabby cat with green eyes, sitting on a vintage leather armchair" }'
undefined

Style Keywords

风格关键词

bash
infsh app run falai/flux-dev --input '{
  "prompt": "Portrait photograph of a woman, shot on Kodak Portra 400 film, soft natural lighting, shallow depth of field, nostalgic mood, analog photography aesthetic"
}'
bash
infsh app run falai/flux-dev --input '{
  "prompt": "Portrait photograph of a woman, shot on Kodak Portra 400 film, soft natural lighting, shallow depth of field, nostalgic mood, analog photography aesthetic"
}'

Composition Control

构图控制

bash
infsh app run falai/flux-dev --input '{
  "prompt": "Wide establishing shot of a cyberpunk city skyline at night, rule of thirds composition, neon signs in foreground, towering skyscrapers in background, rain-slicked streets"
}'
bash
infsh app run falai/flux-dev --input '{
  "prompt": "Wide establishing shot of a cyberpunk city skyline at night, rule of thirds composition, neon signs in foreground, towering skyscrapers in background, rain-slicked streets"
}'

Quality Keywords

画质关键词

photorealistic, 8K, ultra detailed, sharp focus, professional,
masterpiece, high quality, best quality, intricate details
photorealistic, 8K, ultra detailed, sharp focus, professional,
masterpiece, high quality, best quality, intricate details

Negative Prompts

负面提示词

bash
infsh app run falai/flux-dev --input '{
  "prompt": "Professional headshot portrait, clean background",
  "negative_prompt": "blurry, distorted, extra limbs, watermark, text, low quality, cartoon, anime"
}'
bash
infsh app run falai/flux-dev --input '{
  "prompt": "Professional headshot portrait, clean background",
  "negative_prompt": "blurry, distorted, extra limbs, watermark, text, low quality, cartoon, anime"
}'

Video Prompting

视频生成提示词编写

Basic Structure

基本结构

[Shot Type] + [Subject] + [Action] + [Setting] + [Style]
[镜头类型] + [主体] + [动作] + [场景] + [风格]

Camera Movement

镜头运动

bash
infsh app run google/veo-3-1-fast --input '{
  "prompt": "Slow tracking shot following a woman walking through a sunlit forest, golden hour lighting, shallow depth of field, cinematic, 4K"
}'
bash
infsh app run google/veo-3-1-fast --input '{
  "prompt": "Slow tracking shot following a woman walking through a sunlit forest, golden hour lighting, shallow depth of field, cinematic, 4K"
}'

Action Description

动作描述

bash
infsh app run google/veo-3-1-fast --input '{
  "prompt": "Close-up of hands kneading bread dough on a wooden surface, flour dust floating in morning light, slow motion, cozy baking aesthetic"
}'
bash
infsh app run google/veo-3-1-fast --input '{
  "prompt": "Close-up of hands kneading bread dough on a wooden surface, flour dust floating in morning light, slow motion, cozy baking aesthetic"
}'

Temporal Keywords

时间相关关键词

slow motion, timelapse, real-time, smooth motion,
continuous shot, quick cuts, frozen moment
slow motion, timelapse, real-time, smooth motion,
continuous shot, quick cuts, frozen moment

Advanced Techniques

高级技术

System Prompts

系统提示词

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "system": "You are a helpful coding assistant. Always provide code with comments. If you are unsure about something, say so rather than guessing.",
  "prompt": "Write a Python function to validate email addresses using regex."
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "system": "You are a helpful coding assistant. Always provide code with comments. If you are unsure about something, say so rather than guessing.",
  "prompt": "Write a Python function to validate email addresses using regex."
}'

Structured Output

结构化输出

bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Extract information from this text and return as JSON:\n\n\"John Smith, CEO of TechCorp, announced yesterday that the company raised $50 million in Series B funding. The round was led by Venture Partners.\"\n\nSchema:\n{\n  \"person\": string,\n  \"title\": string,\n  \"company\": string,\n  \"event\": string,\n  \"amount\": string,\n  \"investor\": string\n}"
}'
bash
infsh app run openrouter/claude-sonnet-45 --input '{
  "prompt": "Extract information from this text and return as JSON:\n\n\"John Smith, CEO of TechCorp, announced yesterday that the company raised $50 million in Series B funding. The round was led by Venture Partners.\"\n\nSchema:\n{\n  \"person\": string,\n  \"title\": string,\n  \"company\": string,\n  \"event\": string,\n  \"amount\": string,\n  \"investor\": string\n}"
}'

Iterative Refinement

迭代优化

bash
undefined
bash
undefined

Start broad

初始版本:宽泛

infsh app run falai/flux-dev --input '{ "prompt": "A castle on a hill" }'
infsh app run falai/flux-dev --input '{ "prompt": "A castle on a hill" }'

Add specifics

添加细节

infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill" }'
infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill" }'

Add style

添加风格

infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill, dramatic sunset sky, fantasy art style, epic composition" }'
infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill, dramatic sunset sky, fantasy art style, epic composition" }'

Add technical

添加技术参数

infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill, dramatic sunset sky, fantasy art style by Greg Rutkowski, epic composition, 8K, highly detailed" }'
undefined
infsh app run falai/flux-dev --input '{ "prompt": "A medieval stone castle on a grassy hill, dramatic sunset sky, fantasy art style by Greg Rutkowski, epic composition, 8K, highly detailed" }'
undefined

Multi-Turn Reasoning

多轮推理

bash
undefined
bash
undefined

First: analyze

第一步:分析

infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "Analyze this business problem: Our e-commerce site has a 70% cart abandonment rate. List potential causes." }'
infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "Analyze this business problem: Our e-commerce site has a 70% cart abandonment rate. List potential causes." }'

Second: prioritize

第二步:优先级排序

infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "Given these causes of cart abandonment: [previous output], rank them by likely impact and ease of fixing. Format as a priority matrix." }'
infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "Given these causes of cart abandonment: [previous output], rank them by likely impact and ease of fixing. Format as a priority matrix." }'

Third: action plan

第三步:行动计划

infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "For the top 3 causes identified, provide specific A/B tests we can run to validate and fix each issue." }'
undefined
infsh app run openrouter/claude-sonnet-45 --input '{ "prompt": "For the top 3 causes identified, provide specific A/B tests we can run to validate and fix each issue." }'
undefined

Model-Specific Tips

模型专属技巧

Claude

Claude

  • Excels at nuanced instructions
  • Responds well to role-playing
  • Good at following complex constraints
  • Prefers explicit output formats
  • 擅长处理细致的指令
  • 对角色扮演类提示词响应良好
  • 能很好地遵循复杂约束
  • 偏好明确的输出格式

GPT-4

GPT-4

  • Strong at code generation
  • Works well with examples
  • Good structured output
  • Responds to "let's think step by step"
  • 代码生成能力强
  • 结合示例使用效果佳
  • 擅长生成结构化输出
  • 对“让我们一步步思考”这类指令响应良好

FLUX

FLUX

  • Detailed subject descriptions
  • Style references work well
  • Lighting keywords important
  • Negative prompts supported
  • 需要详细的主体描述
  • 风格参考效果显著
  • 光线关键词很重要
  • 支持负面提示词

Veo

Veo

  • Camera movement keywords
  • Cinematic language works well
  • Action descriptions important
  • Include temporal context
  • 重视镜头运动关键词
  • 电影化语言效果好
  • 动作描述很关键
  • 需包含时间上下文

Common Mistakes

常见错误

MistakeProblemFix
Too vagueUnpredictable outputAdd specifics
Too longModel loses focusPrioritize key info
ConflictingConfuses modelRemove contradictions
No formatInconsistent outputSpecify format
No examplesUnclear expectationsAdd few-shot
错误类型问题解决方法
过于模糊输出不可预测添加细节
过于冗长模型失去焦点优先保留关键信息
相互矛盾让模型困惑移除矛盾内容
未指定格式输出不一致明确指定格式
未提供示例期望不清晰添加少样本示例

Prompt Templates

提示词模板

Code Review

代码审查

Review this [language] code for:
1. Bugs and logic errors
2. Security vulnerabilities
3. Performance issues
4. Code style/best practices

Code:
[code]

For each issue found, provide:
- Line number
- Issue description
- Severity (high/medium/low)
- Suggested fix
审查这段[语言]代码,重点关注:
1. 漏洞和逻辑错误
2. 安全隐患
3. 性能问题
4. 代码风格/最佳实践

代码:
[code]

针对发现的每个问题,提供:
- 行号
- 问题描述
- 严重程度(高/中/低)
- 修复建议

Content Writing

内容创作

Write a [content type] about [topic].

Audience: [target audience]
Tone: [formal/casual/professional]
Length: [word count]
Key points to cover:
1. [point 1]
2. [point 2]
3. [point 3]

Include: [specific elements]
Avoid: [things to exclude]
撰写一篇[内容类型]关于[主题]。

受众:[目标受众]
语气:[正式/随意/专业]
篇幅:[字数]
需涵盖的关键点:
1. [要点1]
2. [要点2]
3. [要点3]

需包含:[特定元素]
需避免:[排除内容]

Image Generation

图像生成

[Subject with details], [setting/background], [lighting type],
[art style or photography style], [composition], [quality keywords]
[带细节的主体], [场景/背景], [光线类型],
[艺术风格或摄影风格], [构图], [画质关键词]

Related Skills

相关技能

bash
undefined
bash
undefined

Video prompting guide

视频提示词指南

npx skills add inference-sh/skills@video-prompting-guide
npx skills add inference-sh/skills@video-prompting-guide

LLM models

LLM模型

npx skills add inference-sh/skills@llm-models
npx skills add inference-sh/skills@llm-models

Image generation

图像生成

npx skills add inference-sh/skills@ai-image-generation
npx skills add inference-sh/skills@ai-image-generation

Full platform skill

完整平台技能

npx skills add inference-sh/skills@inference-sh

Browse all apps: `infsh app list`
npx skills add inference-sh/skills@inference-sh

浏览全部应用:`infsh app list`