ladderlore
  • 输入服务名称,例如 S3 或 IAM。

概念 · 基于 AIF-C01

Task-specific prompt engineering

Build a prompt for one task: examples, reasoning, role, output schema and sampling settings, then test and version it.

本课尚未翻译,暂以英文显示。

你在AI Practitioner中已学过

  • Zero-shot, single-shot and few-shot differ in how many examples you show.
  • Chain-of-thought asks for step-by-step reasoning. A system prompt holds standing rules.
  • Prompt chaining feeds one answer into the next prompt.
阅读AI Practitioner课程
  • Zero-shot

    Use for
    Simple, clear tasks
    Cost
    Fewest tokens
  • Few-shot

    Use for
    Format and tone
    Cost
    More tokens each call
  • Chain of thought

    Use for
    Logic and math
    Cost
    Longer output
  • Role and system prompt

    Use for
    Rules and persona
    Cost
    Small
  • JSON schema

    Use for
    Output parsed by code
    Cost
    Small
  • Prompt chaining

    Use for
    Multi-step tasks
    Cost
    More calls
Techniques and what each costs.

1 / 2

  • Zero-shot

    Use for
    Simple, clear tasks
    Cost
    Fewest tokens
  • Few-shot

    Use for
    Format and tone
    Cost
    More tokens each call
  • Chain of thought

    Use for
    Logic and math
    Cost
    Longer output

2 / 2

  • Role and system prompt

    Use for
    Rules and persona
    Cost
    Small
  • JSON schema

    Use for
    Output parsed by code
    Cost
    Small
  • Prompt chaining

    Use for
    Multi-step tasks
    Cost
    More calls
Techniques and what each costs.
  • Temperature

    Randomness. Low for facts, high for creative text.

  • Top-p

    Sample from the smallest set of tokens whose chances add up to p.

  • Top-k

    Sample only from the k most likely tokens.

  • Max tokens and stop

    Limit the length and end the output at a marker.

Four settings that shape the output.

是什么

Shape the prompt to the task. For classification or extraction, give a role, the allowed labels, two or three examples (few-shot) and the exact output format. For math or logic, ask for step-by-step reasoning (chain of thought) before the final answer. Put standing rules and the role in the system prompt and the request in the user prompt. Ask for JSON that follows a stated schema so code can parse it, and validate it in code. Split a big task into a chain: one prompt extracts, the next summarizes, so each is simpler and easier to test.

是什么

Sampling settings change the style of the output. Temperature controls randomness: a low value (near 0) gives consistent, factual answers, and a high value gives varied, creative ones. Top-p (nucleus sampling) picks from the smallest group of likely tokens whose probabilities add up to p. Top-k picks only from the k most likely tokens. Change temperature or top-p, not both at once. Maximum tokens and stop sequences limit the output.

Treat prompts like code. Keep them in Amazon Bedrock Prompt Management, which stores versions and variables. Test every change against a fixed set of examples, for example with a Bedrock evaluation job, and compare versions before release.

要记住

  • Few-shot examples fix format and tone. Chain of thought helps multi-step reasoning.
  • System prompt: role and standing rules. User prompt: the request.
  • Ask for JSON in a stated schema, then validate it.
  • Prompt chaining: split a task into simple prompts.

要记住

  • Temperature: low for facts and extraction, high for creative text. Top-p and top-k limit the token pool.
  • Version prompts and test them against a fixed example set.

考试中

  • “The same answer every time for data extraction” points to a low temperature.
  • “Output must be parsed by code” points to a JSON output schema in the prompt.
  • “Compare two versions of a prompt before release” points to prompt versions and an evaluation job.