0Pricing
AI Prompt Engineering · บทเรียน

พรอมต์ที่สร้างพรอมต์

เครื่องมือสร้างพรอมต์ระบบ เครื่องมือสร้างบุคลิก และโรงงานพรอมต์เฉพาะงาน

พรอมต์ที่สร้างพรอมต์ เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

โรงงานพรอมต์

โรงงานพรอมต์ คือเมตาพรอมต์ที่ generate รูปแบบพรอมต์หลายแบบสำหรับงานหนึ่ง ๆ แทนที่จะเขียนพรอมต์เพียงหนึ่งแบบ คุณจะระบุงานและข้อจำกัด แล้วโรงงานจะสร้างชุดตัวเลือกที่คุณสามารถทดสอบและเลือกใช้ได้

การสร้างรูปแบบต่าง ๆ ของพรอมต์ระบบ

ขอให้โมเดลสร้างรูปแบบต่าง ๆ ของพรอมต์ระบบจำนวน N รูปแบบสำหรับบทบาทเดียวกัน โดยแต่ละรูปแบบใช้โทนหรือสไตล์การสื่อสารที่แตกต่างกัน นี่คือจุดเริ่มต้นสำหรับการทดสอบพรอมต์ระบบแบบ A/B

import anthropic

client = anthropic.Anthropic(api_key='YOUR_API_KEY')

VARIANT_FACTORY_PROMPT = '''Generate {num_variants} different system prompt variants
for a coding assistant targeting junior developers.

Each variant should have a distinctly different approach:
- Variant 1: Friendly and encouraging mentor style
- Variant 2: Concise and technical style
- Variant 3: Socratic method (asks guiding questions instead of giving answers)
- Variant 4: Game-based, uses analogies and rewards
- Variant 5: Strict teacher who corrects mistakes firmly but fairly

For each variant output:
{{"id": 1, "style": "<style name>", "prompt": "<full system prompt>"}}

Return as a JSON array.'''

def generate_prompt_variants(num_variants=5):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=3000,
        messages=[{'role': 'user', 'content':
            VARIANT_FACTORY_PROMPT.format(num_variants=num_variants)}]
    )
    return json.loads(response.content[0].text)

variants = generate_prompt_variants(5)
for v in variants[:2]:
    print(f'Variant {v["id"]} ({v["style"]}): {v["prompt"][:80]}...')

ตัวสร้างแม่แบบพรอมต์เฉพาะงาน

ตัวสร้างแม่แบบพรอมต์จะสร้างแม่แบบที่กำหนดพารามิเตอร์ได้สำหรับประเภทงานเฉพาะ ผลลัพธ์คือแม่แบบที่นำกลับมาใช้ใหม่ได้ ไม่ใช่พรอมต์ที่สร้างขึ้นเพื่อใช้ครั้งเดียว

TEMPLATE_FACTORY_PROMPT = '''Create a production-ready prompt template for the following task.

Task type: {task_type}
Domain: {domain}
Target audience: {audience}

Requirements for the template:
1. Use {{variable}} placeholders for all input values
2. Include role/persona definition
3. Specify exact output format
4. Add quality constraints
5. Include a worked example using {{example_input}} placeholder

Also output:
- variables: list of all {variable} placeholders and their descriptions
- suggested_model: which Claude/GPT model tier is appropriate
- estimated_tokens: rough estimate of output token count

Return as JSON: {{template, variables, suggested_model, estimated_tokens}}'''

def generate_task_template(task_type, domain, audience):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1500,
        messages=[{'role': 'user', 'content':
            TEMPLATE_FACTORY_PROMPT.format(
                task_type=task_type,
                domain=domain,
                audience=audience
            )}]
    )
    return json.loads(response.content[0].text)

template = generate_task_template(
    task_type='summarization',
    domain='legal contracts',
    audience='non-lawyer business executives'
)
print('Template preview:', template['template'][:200], '...')
print('Variables:', template.get('variables', [])[:3])

ตัวสร้างพรอมต์บุคลิก

ตัวสร้างบุคลิกจะสร้างคำจำกัดความบุคลิกอย่างครบถ้วน ซึ่งรวมถึงพรอมต์ระบบ บทสนทนาตัวอย่าง และรูปแบบที่ควรหลีกเลี่ยง (สิ่งที่บุคลิกนั้นไม่ควรพูดหรือทำเด็ดขาด)

PERSONA_FACTORY_PROMPT = '''Design a complete AI assistant persona for: {application}.

Output a JSON object with these keys:
- name: persona name
- tagline: one-sentence description
- system_prompt: full system prompt (150-250 words)
- communication_style: 4-5 sentences describing how this persona communicates
- example_good_response: example of an ideal response to a typical user question
- example_bad_response: example of a response that would break character or violate guidelines
- persona_rules: list of 5 behavioral rules specific to this persona
- forbidden_phrases: list of 5 phrases this persona would never use

Make the persona distinct, consistent, and aligned with the application context.'''

def generate_persona(application):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            PERSONA_FACTORY_PROMPT.format(application=application)}]
    )
    return json.loads(response.content[0].text)

persona = generate_persona('a mental wellness check-in app for university students')
print('Persona:', persona['name'])
print('Tagline:', persona['tagline'])
print('System prompt preview:', persona['system_prompt'][:150], '...')

ตัวสร้างกรณีทดสอบ

เมตาพรอมต์สามารถสร้างกรณีทดสอบที่หลากหลายสำหรับประเมินคุณภาพพรอมต์ ตัวสร้างกรณีทดสอบจะสร้างข้อมูลนำเข้าจากผู้ใช้ที่ครอบคลุมการใช้งานทั่วไป กรณีขอบเขต และข้อมูลนำเข้าที่มุ่งโจมตีระบบ

TEST_CASE_FACTORY = '''Generate {num_cases} test cases for evaluating an AI assistant.

Assistant description: {assistant_description}

For each test case provide:
- id: number
- category: one of [typical, edge_case, adversarial, off_topic, ambiguous]
- user_message: the input message
- expected_behavior: what a good response should do (not the response itself)
- failure_modes: what wrong responses might look like

Distribution: 5 typical, 3 edge cases, 2 adversarial, 2 off-topic, 3 ambiguous.
Return as JSON array.'''

def generate_test_cases(assistant_description, num_cases=15):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=3000,
        messages=[{'role': 'user', 'content':
            TEST_CASE_FACTORY.format(
                num_cases=num_cases,
                assistant_description=assistant_description
            )}]
    )
    return json.loads(response.content[0].text)

test_cases = generate_test_cases(
    'A Python coding tutor for beginners that explains errors in simple language'
)
for tc in test_cases[:3]:
    print(f'[{tc["category"]}] {tc["user_message"][:60]}...')

ตัวสร้างตัวอย่างจากข้อมูลไม่กี่ตัวอย่าง

การเขียนตัวอย่างจากข้อมูลไม่กี่ตัวอย่างด้วยตนเองต้องใช้เวลามาก ตัวสร้างตัวอย่างประเภทนี้จะสร้างตัวอย่างจากคำอธิบายงานและตัวอย่างตั้งต้นที่มีให้เลือก

FEW_SHOT_FACTORY = '''Generate {num_examples} high-quality few-shot examples for:
Task: {task_description}

Each example must:
- Be realistic and representative of the actual task
- Show the exact input-output format
- Cover different sub-types or difficulty levels
- Be labeled: [Easy], [Medium], or [Hard]

Format exactly as:
---EXAMPLE {n}---
Input: <input>
Output: <output>
[Difficulty: Easy/Medium/Hard]

Make examples progressively more complex from first to last.'''

def generate_few_shot_examples(task_description, num_examples=5):
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            FEW_SHOT_FACTORY.format(
                task_description=task_description,
                num_examples=num_examples
            )}]
    )
    return response.content[0].text

examples = generate_few_shot_examples(
    'Classify customer emails into: Complaint, Question, Praise, Refund Request'
)
print(examples[:500], '...')

ตัวสร้างพรอมต์ห่วงโซ่ความคิด

การสร้างพรอมต์ห่วงโซ่ความคิด (CoT) ต้องให้ตัวสร้างสร้างทั้งโครงสร้างการให้เหตุผลและห่วงโซ่การให้เหตุผลตัวอย่าง เมตาพรอมต์นี้มีความซับซ้อนมากขึ้น เพราะจะสร้างพรอมต์ CoT ที่มีโครงสร้างครบถ้วน

COT_PROMPT_FACTORY = '''Design a chain-of-thought prompt for solving: {problem_type}

The prompt must:
1. Define the step-by-step reasoning process specific to this problem type
2. Include a worked example showing the full reasoning chain
3. Use "Think step by step" or equivalent CoT trigger phrase
4. End with a clear output specification

Output format:
{
  "cot_trigger": "the trigger phrase",
  "reasoning_steps": ["step 1 description", "step 2 description", ...],
  "worked_example": {
    "problem": "...",
    "reasoning": "Step 1: ... Step 2: ... etc.",
    "answer": "..."
  },
  "full_prompt_template": "the complete template with {problem} placeholder"
}'''

def generate_cot_prompt(problem_type):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=1500,
        messages=[{'role': 'user', 'content':
            COT_PROMPT_FACTORY.format(problem_type=problem_type)}]
    )
    return json.loads(response.content[0].text)

cot = generate_cot_prompt('debugging Python runtime errors')
print('CoT steps:', cot['reasoning_steps'][:3])
print('Trigger:', cot['cot_trigger'])

การเลือกและให้คะแนนรูปแบบต่าง ๆ ของพรอมต์

หลังจากสร้างรูปแบบต่าง ๆ ของพรอมต์หลายรูปแบบแล้ว ให้ใช้เมตาพรอมต์สำหรับให้คะแนนเพื่อจัดอันดับคุณภาพก่อนทดสอบ วิธีนี้จะกรองตัวเลือกเบื้องต้นและลดจำนวนการเรียกใช้บริการจริงที่จำเป็น

SCORING_PROMPT = '''You are evaluating prompt variants for quality.
Rate each variant on these criteria (1-5):

1. Clarity: Is the task and output format clearly defined?
2. Completeness: Are all necessary instructions present?
3. Constraints: Are appropriate constraints and guardrails in place?
4. Conciseness: Is there unnecessary length that dilutes the prompt?
5. Robustness: Would this handle edge cases and adversarial inputs?

For each variant output:
{"id": <id>, "scores": {clarity: N, completeness: N, constraints: N,
conciseness: N, robustness: N}, "total": N, "rationale": "<2 sentences>"}

Return JSON array sorted by total score descending.

Variants to evaluate:
{variants_json}'''

def rank_prompt_variants(variants):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=2000,
        messages=[{'role': 'user', 'content':
            SCORING_PROMPT.format(
                variants_json=json.dumps(variants, indent=2)
            )}]
    )
    return json.loads(response.content[0].text)

ranked = rank_prompt_variants(variants)
print('Top variant:', ranked[0]['id'], '| Score:', ranked[0]['total'])
print('Rationale:', ranked[0]['rationale'][:100])

ความแตกต่างของพรอมต์: การสร้างความหลากหลายสูงสุด

เมื่อสร้างรูปแบบต่าง ๆ ของพรอมต์ ความหลากหลายมีความสำคัญพอ ๆ กับคุณภาพ ให้ใช้คำสั่งที่ระบุเรื่องความหลากหลายอย่างชัดเจน เพื่อป้องกันไม่ให้โมเดลสร้างรูปแบบที่แทบจะเหมือนกัน

DIVERSITY_FACTORY = '''Generate 5 MAXIMALLY DIVERSE prompt variants for:
Task: {task_description}

Diversity requirements:
- Each variant must use a DIFFERENT cognitive approach:
  1. Direct instruction approach
  2. Role-based persona approach
  3. Example-first (few-shot) approach
  4. Constraint-based (tell what NOT to do) approach
  5. Output-format-first approach (start by defining desired output)

- No two variants should share more than 20% of their wording
- Each variant should be completable without reference to the others

For each variant tag it with its approach name.
Return as JSON array: [{"approach": "...", "prompt": "..."}]'''

def generate_diverse_variants(task_description):
    import json
    response = client.messages.create(
        model='claude-opus-4-5', max_tokens=3000,
        messages=[{'role': 'user', 'content':
            DIVERSITY_FACTORY.format(task_description=task_description)}]
    )
    return json.loads(response.content[0].text)

diverse = generate_diverse_variants('Answering customer questions about product returns')
for v in diverse:
    print(f'Approach: {v["approach"]} | Prompt: {v["prompt"][:60]}...')

การสร้างกระบวนการทำงานของตัวสร้างพรอมต์

กระบวนการทำงานของตัวสร้างพรอมต์ที่สมบูรณ์จะรวมการสร้าง การให้คะแนน การตรวจสอบความหลากหลาย และการส่งออกไว้ด้วยกัน เพื่อสร้างชุดตัวเลือกพรอมต์ที่พร้อมใช้งาน

def prompt_factory_pipeline(task_description, num_candidates=5, top_k=3):
    print(f'[1/4] Generating {num_candidates} diverse prompt variants...')
    variants = generate_diverse_variants(task_description)

    print('[2/4] Scoring prompt quality...')
    ranked = rank_prompt_variants(variants)

    print('[3/4] Selecting top candidates...')
    top_candidates = ranked[:top_k]

    print('[4/4] Generating test cases for evaluation...')
    test_cases = generate_test_cases(task_description, num_cases=10)

    output = {
        'task': task_description,
        'candidates': top_candidates,
        'test_cases': test_cases,
        'recommendation': (
            f'Start A/B testing with top 3 candidates. '
            f'Run each against {len(test_cases)} test cases. '
            f'Promote the highest-scoring candidate to production.'
        )
    }
    print('Pipeline complete.')
    return output

# result = prompt_factory_pipeline(
#     'Summarizing customer support tickets for a priority queue'
# )
# print(result['recommendation'])

รูปแบบที่ควรหลีกเลี่ยงในการสร้างพรอมต์

ตัวสร้างพรอมต์มีรูปแบบความล้มเหลวอยู่หลายประการ การทำความเข้าใจรูปแบบที่ควรหลีกเลี่ยงเหล่านี้ช่วยให้สร้างเมตาพรอมต์และพรอมต์ตัวเลือกได้ดีขึ้น

PROMPT_FACTORY_ANTIPATTERNS = {
    'Generic variants': {
        'problem': 'All variants say the same thing in slightly different words',
        'cause': 'No diversity instruction in the meta-prompt',
        'fix': 'Explicitly specify different approaches or styles for each variant'
    },
    'Hallucinated instructions': {
        'problem': 'Generated prompt references APIs, rules, or facts that do not exist',
        'cause': 'Model fills gaps in its knowledge with plausible-sounding content',
        'fix': 'Review all domain-specific claims; add validation step'
    },
    'Missing edge case coverage': {
        'problem': 'Generated prompts only handle happy path, not failures',
        'cause': 'Meta-prompt did not specify adversarial/edge case requirements',
        'fix': 'Explicitly ask for edge case handling in the meta-prompt'
    },
    'Over-length inflation': {
        'problem': 'Generated prompts are verbose and repetitive',
        'cause': 'Model padds output without conciseness constraint',
        'fix': 'Add word count constraint: "between 100-200 words"'
    }
}

for pattern, info in PROMPT_FACTORY_ANTIPATTERNS.items():
    print(f'{pattern}:')
    print(f'  Fix: {info["fix"]}')

ตรวจสอบความเข้าใจอย่างรวดเร็ว

คุณต้องการรูปแบบพรอมต์ระบบ 5 รูปแบบสำหรับการทดสอบผู้ช่วยเขียนโค้ดแบบ A/B คำสั่งเมตาพรอมต์ใดดีที่สุดในการทำให้แน่ใจว่ารูปแบบเหล่านั้นแตกต่างกันอย่างแท้จริง

สรุปตัวสร้างพรอมต์

ตัวสร้างพรอมต์ใช้เมตาพรอมต์เพื่อสร้างพรอมต์ตัวเลือกจำนวนมาก:

  • ตัวสร้างรูปแบบต่าง ๆ: สร้างรูปแบบที่หลากหลายจำนวน N รูปแบบสำหรับการทดสอบแบบ A/B
  • ตัวสร้างแม่แบบ: สร้างแม่แบบที่กำหนดพารามิเตอร์ได้จากคำอธิบายงาน
  • ตัวสร้างบุคลิก: สร้างคำจำกัดความบุคลิกฉบับเต็ม ซึ่งรวมถึงพรอมต์ระบบและตัวอย่าง
  • ตัวสร้างกรณีทดสอบ: สร้างข้อมูลนำเข้าจากการใช้งานทั่วไป กรณีขอบเขต และการโจมตีระบบ
  • ตัวสร้างตัวอย่างจากข้อมูลไม่กี่ตัวอย่าง: สร้างคู่ตัวอย่างข้อมูลนำเข้าและผลลัพธ์ตามระดับความยากที่ระบุ
  • เมตาพรอมต์สำหรับให้คะแนน: จัดอันดับตัวเลือกที่สร้างขึ้นก่อนการทดสอบจริง
  • ข้อกำหนดด้านความหลากหลาย: ระบุแนวทางที่แตกต่างกันเพื่อป้องกันไม่ให้ได้รูปแบบที่แทบจะเหมือนกัน

คำถามที่พบบ่อย

บทเรียน “พรอมต์ที่สร้างพรอมต์” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “พรอมต์ที่สร้างพรอมต์” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AI Prompt Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “พรอมต์ที่สร้างพรอมต์”

เครื่องมือสร้างพรอมต์ระบบ เครื่องมือสร้างบุคลิก และโรงงานพรอมต์เฉพาะงาน คุณปฏิบัติ AI Prompt Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AI Prompt Engineering หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AI Prompt Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “พรอมต์ที่สร้างพรอมต์” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม

ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เมตาพรอมต์คืออะไร
  2. พรอมต์ที่สร้างพรอมต์
  3. ระบบพรอมต์ที่ปรับปรุงตนเอง
  4. การประเมินและคัดเลือกในการปรับปรุงตนเอง
← กลับไปที่ AI Prompt Engineering