การกำหนดฉากอย่างมีประสิทธิภาพ
เทคนิคการวางกรอบ: “คุณคือ...” “เมื่อกำหนดให้...” “เป้าหมายคือ...”
การกำหนดฉากอย่างมีประสิทธิภาพ เป็นบทเรียน AI Prompt Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AI Prompt Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AI Prompt Engineering มีบทเรียนทั้งหมด 4 บทเรียน
กรอบเปิดพรอมต์ที่ใช้ได้ผล
ประโยคแรกของพรอมต์มีความสำคัญที่สุด เพราะเป็นตัวกำหนดบริบทการทำงานของโมเดล หรือมุมมองที่โมเดลใช้ตีความทุกสิ่งที่ตามมา
กรอบเปิดเรื่องที่ได้ผล ได้แก่ คุณคือ... บริบทคือ... เมื่อพิจารณาว่า... และ เป้าหมายคือ... แต่ละกรอบจะเปิดใช้บริบทคนละมิติก่อนเริ่มงานจริง
กรอบ “คุณคือ...”
กรอบ คุณคือ... กำหนดบุคลิกให้โมเดล ซึ่งจะเปิดใช้คำศัพท์ รูปแบบการให้เหตุผล และลำดับความสำคัญที่สัมพันธ์กับบทบาทนั้น
กุญแจสำคัญคือความเฉพาะเจาะจง “คุณคือผู้เชี่ยวชาญ” ยังไม่ชัดเจนพอ “คุณคือวิศวกรไพธอนอาวุโสที่มีประสบการณ์ 10 ปี และให้ความสำคัญกับความอ่านง่ายมากกว่าวิธีที่ดูฉลาดแต่ซับซ้อน” มีความชัดเจนกว่า
กรอบบุคลิกจะใช้ได้ดีที่สุดเมื่อบุคลิกนั้นสื่อถึงวิธีคิดและการสื่อสารเฉพาะแบบที่คุณต้องการ
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
persona_prompts = [
'You are a Socratic philosophy professor. Ask 3 probing questions about this claim: AI will replace programmers.',
'You are a skeptical venture capitalist who has seen 500 pitches. Give brutal feedback on this pitch: We are building an AI writing assistant.',
'You are a patient kindergarten teacher. Explain what a computer does in 3 sentences for 5-year-olds.'
]
for prompt in persona_prompts:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=150,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'--- Persona ---')
print(prompt[:80] + '...')
print(response.content[0].text.strip())
print()กรอบ “คุณคือ...” ในข้อความระบบ
ตำแหน่งที่มีประสิทธิภาพสูงสุดสำหรับกรอบบุคลิกคือ ข้อความระบบ ไม่ใช่ข้อความจากผู้ใช้ บุคลิกในข้อความระบบจะทำงานตลอดการสนทนา — ไม่จำเป็นต้องย้ำซ้ำ
บุคลิกในข้อความระบบที่ออกแบบมาอย่างดีสามารถเปลี่ยนรูปแบบการตอบของผู้ช่วยปัญญาประดิษฐ์ได้อย่างสิ้นเชิงตลอดคำถามต่อเนื่องนับสิบข้อ
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
# Persona set once in system; stays active for all turns
system_persona = (
'You are Marcus, a senior software architect at a Fortune 500 company. '
'You have 20 years of experience with distributed systems. '
'Your communication style: direct, pragmatic, no buzzwords. '
'You always ask about scale and failure modes before giving architecture advice. '
'If a question lacks context, ask one clarifying question before answering.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role': 'system', 'content': system_persona},
{'role': 'user', 'content': 'Should we use microservices for our new product?'}
]
)
print(response.choices[0].message.content)กรอบ “บริบทคือ...”
กรอบ บริบทคือ... จะกำหนดพื้นหลังของสถานการณ์โดยไม่กำหนดบุคลิก ใช้กรอบนี้เมื่อต้องการให้โมเดลใช้เหตุผลกับสถานการณ์เฉพาะของคุณ แทนการสวมบทบาทเป็นตัวละคร
กรอบนี้มีประสิทธิภาพเป็นพิเศษกับงานด้านเทคนิคและการวิเคราะห์ ซึ่งคุณต้องการให้โมเดลใช้เหตุผลในฐานะตัวมันเอง แต่ตระหนักถึงข้อจำกัดของคุณอย่างครบถ้วน
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=300,
messages=[{
'role': 'user',
'content': (
'The context is: we are a 5-person startup with $2M in seed funding. '
'Our Python monolith handles 10,000 users and is starting to show performance issues. '
'We have one backend engineer and cannot hire more for 6 months. '
'We need to choose between refactoring the monolith vs migrating to microservices.\n\n'
'Give a recommendation with 3 supporting reasons. Be direct.'
)
}]
)
print(response.content[0].text)กรอบ “เมื่อพิจารณาว่า...”
กรอบ เมื่อพิจารณาว่า... จะกำหนดข้อเท็จจริงหรือสมมติฐานตั้งต้นที่ส่งผลต่อคำตอบทั้งหมด ใช้กรอบนี้เพื่อกำหนดข้อเท็จจริงที่โมเดลต้องถือว่าเป็นจริงสำหรับงานนั้น
กรอบนี้มีประโยชน์อย่างมากสำหรับการวิเคราะห์สมมติฐาน การวางแผนแบบมีเงื่อนไข และการเขียนตามสถานการณ์ ซึ่งคุณต้องการให้โมเดลใช้เหตุผลจากจุดเริ่มต้นที่เฉพาะเจาะจง
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
scenarios = [
'Given that our user base will grow 10x in 6 months, what architecture changes should we make today?',
'Given that we must launch in 2 weeks with the current team, which features should we cut from the MVP?',
'Given that our API key was exposed publicly for 3 hours, what steps should we take in the next 24 hours?'
]
for scenario in scenarios:
response = client.chat.completions.create(
model='gpt-4o',
max_tokens=120,
messages=[{
'role': 'user',
'content': scenario + ' (Answer in 3 bullet points.)'
}]
)
print(f'Scenario: {scenario[:60]}...')
print(response.choices[0].message.content.strip())
print()กรอบ “เป้าหมายคือ...”
กรอบ เป้าหมายคือ... ระบุจุดประสงค์ปลายทางของผลลัพธ์ ซึ่งแตกต่างจากคำสั่งของงาน เพราะกรอบนี้อธิบายว่าเหตุใดคุณจึงต้องการผลลัพธ์นี้ และผลลัพธ์ต้องทำอะไรให้สำเร็จ
กรอบนี้ช่วยให้โมเดลตัดสินใจย่อย ๆ ได้ดีขึ้น เช่น ควรใช้ระดับการโน้มน้าวใจเท่าใด ควรเตรียมรับมือข้อโต้แย้งใด และควรใส่หรือละเว้นรายละเอียดใด
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
goal_frames = [
(
'The goal is to get the reader to schedule a 30-minute demo call. '
'Write a 100-word cold outreach email for our AI data pipeline tool '
'targeting data engineers at e-commerce companies.'
),
(
'The goal is to help the reader pass a senior Python interview at a FAANG company. '
'Explain Python decorators with one conceptual explanation and one practical code example.'
)
]
for prompt in goal_frames:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
messages=[{'role': 'user', 'content': prompt}]
)
print('--- Goal Frame ---')
print(prompt[:80] + '...')
print(response.content[0].text.strip())
print()การผสานกรอบเปิดเรื่อง
พรอมต์ที่ทรงพลังที่สุดมักผสานกรอบเปิดเรื่องหลายกรอบไว้ก่อนคำสั่งของงาน โครงสร้างประสิทธิภาพสูงที่ใช้กันทั่วไปมีดังนี้:
- คุณคือ... [บุคลิก]
- บริบทคือ... [สถานการณ์]
- เป้าหมายคือ... [จุดประสงค์ปลายทาง]
- เมื่อพิจารณาว่า... [สมมติฐานหรือข้อจำกัดสำคัญ]
- [คำสั่งของงาน]
แต่ละกรอบจะเพิ่มชั้นของการกำหนดทิศทาง เมื่อใช้ร่วมกันแล้ว โมเดลแทบไม่ต้องคาดเดาเองเลย
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
combined_frame_prompt = (
'You are a senior product manager with 10 years of B2B SaaS experience.\n'
'The context is: our team is debating whether to build a native mobile app '
'or keep investing in our responsive web app.\n'
'The goal is: to help our leadership team make a clear go/no-go decision at '
'next week\'s board meeting.\n'
'Given that: we have 3 engineers, $300k runway, and 85% of current users are on desktop.\n\n'
'Write a 250-word recommendation memo with a clear position (build or wait) '
'and 3 supporting arguments. End with one risk to monitor.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': combined_frame_prompt}]
)
print(response.choices[0].message.content)การกำหนดโทนและน้ำเสียง
กรอบเปิดเรื่องยังสามารถกำหนดโทนและน้ำเสียงได้โดยไม่ต้องใช้คำว่า “โทน” เลย การอธิบายบุคลิกและสถานการณ์จะกำหนดระดับภาษาโดยนัย:
- “คุณเป็นผู้ให้คำปรึกษาที่อบอุ่นและอดทน ซึ่งพูดคุยกับนักเรียนที่กำลังประสบปัญหา” → ให้ความอบอุ่นและกำลังใจโดยอัตโนมัติ
- “คุณเป็นเจ้าหน้าที่ส่งกำลังบำรุงทางทหารที่พูดตรงประเด็น” → ตรงไปตรงมาและแม่นยำโดยอัตโนมัติ
- “คุณเป็นนักข่าวเทคโนโลยีที่มีไหวพริบ ซึ่งเขียนให้ไวร์ด” → ฉลาดมีไหวพริบและเข้าถึงง่ายโดยอัตโนมัติ
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
frames = [
'You are a warm, patient mentor. Explain why learning to code is hard but worth it.',
'You are a no-nonsense military logistics officer. Explain why learning to code is hard but worth it.',
'You are a witty tech journalist writing for Wired. Explain why learning to code is hard but worth it.'
]
for frame in frames:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=80,
messages=[{'role': 'user', 'content': frame + ' (2 sentences only)'}]
)
print(f'Frame: {frame[:55]}...')
print(response.content[0].text.strip())
print()การกำหนดกรอบเพื่อความเคร่งครัดในการวิเคราะห์
เมื่อคุณต้องการการวิเคราะห์ที่เคร่งครัดและวิพากษ์วิจารณ์ แทนการเห็นด้วยอย่างกระตือรือร้น ให้เปิดด้วยกรอบที่กระตุ้นกรอบความคิดแบบสงสัยหรือเชิงวิเคราะห์อย่างชัดเจน:
- “คุณเป็นผู้ตรวจสอบเชิงวิพากษ์ ซึ่งมีหน้าที่ค้นหาจุดบกพร่อง...”
- “จงสวมบทบาทเป็นฝ่ายคัดค้านและท้าทายประเด็นต่อไปนี้...”
- “ให้ถือว่าสิ่งที่ตรงข้ามกับความเชื่อโดยทั่วไปเป็นจริง แล้วโต้แย้งว่า...”
- “จงนำเสนอข้อโต้แย้งฉบับที่แข็งแกร่งที่สุดของฝ่ายคัดค้านที่อ่อนแอที่สุด...”
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
analytical_frames = [
'You are a critical reviewer whose job is to find fatal flaws. Review this startup idea: a subscription box for AI prompt templates.',
'Play devil\'s advocate. Challenge this claim: AI will make every knowledge worker 10x more productive.',
'Steelman the weakest argument against remote work, then give the strongest counter-argument.'
]
for frame in analytical_frames:
response = client.chat.completions.create(
model='gpt-4o',
max_tokens=120,
messages=[{'role': 'user', 'content': frame + ' (3 sentences max)'}]
)
print(f'Frame type: analytical/critical')
print(f'Prompt: {frame[:60]}...')
print(response.choices[0].message.content.strip())
print()เมื่อไม่ควรใช้กรอบบุคลิก (NOT)
กรอบบุคลิกไม่ใช่เครื่องมือที่เหมาะสมเสมอไป ควรหลีกเลี่ยงเมื่อ:
- คุณต้องการดึงข้อมูลอย่างเป็นกลาง — บุคลิกอาจเพิ่มอคติ
- คุณกำลังประมวลผลข้อมูลที่มีโครงสร้าง — บุคลิกทำให้เสียสมาธิ
- งานเป็นกระบวนการเชิงกลล้วน ๆ — ไม่มีการใช้เหตุผลเข้ามาเกี่ยวข้อง
- คุณต้องการการประเมินตามจริงจากโมเดล — บุคลิกจะกำหนดความคิดเห็น
สำหรับงานอย่าง “แปลง CSV นี้เป็นเจสัน” หรือ “นับจำนวนประโยคในย่อหน้านี้” ไม่จำเป็นต้องใช้กรอบใด ๆ — ใช้เพียงคำสั่งก็พอ
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
# Persona frame is unhelpful here — just adds tokens
prompt_with_unnecessary_frame = (
'You are an expert data processing specialist with years of experience. '
'Convert the following to JSON: Name: Alice, Age: 30, City: London'
)
# Clean, direct instruction
prompt_direct = (
'Convert to a JSON object with keys name, age, city:\n'
'Name: Alice, Age: 30, City: London'
)
for label, prompt in [('WITH UNNECESSARY FRAME', prompt_with_unnecessary_frame), ('DIRECT', prompt_direct)]:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=50,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'[{label}]')
print(response.content[0].text.strip())
print()การทดสอบกรอบของคุณ
วิธีที่ดีที่สุดในการเรียนรู้ว่ากรอบใดเหมาะกับกรณีใช้งานของคุณ คือทำการทดสอบ A/B โดยใช้งานเดียวกัน กรอบเปิดเรื่องต่างกัน แล้วเปรียบเทียบผลลัพธ์
ให้ทดสอบมิติต่อไปนี้:
- ไม่มีกรอบ เทียบกับมีกรอบบุคลิก
- บุคลิกกว้าง ๆ เทียบกับบุคลิกที่เฉพาะเจาะจง
- มีเฉพาะกรอบบริบท เทียบกับกรอบบริบทและกรอบเป้าหมาย
- กรอบเดียว เทียบกับกรอบที่ผสานกัน
จดบันทึกว่ากรอบใดให้ผลลัพธ์ดีที่สุดสำหรับงานแต่ละประเภทที่คุณทำ
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
task = 'Explain the pros and cons of using TypeScript over JavaScript.'
frames = {
'No frame': task,
'Persona frame': f'You are a TypeScript advocate who also knows JavaScript deeply. {task}',
'Goal frame': f'The goal is to help a JavaScript developer decide if switching to TypeScript is worth it. {task}',
'Combined frame': f'You are a pragmatic senior engineer. The goal is to help a JavaScript developer decide. {task} Give a balanced view in 3 bullet points.'
}
for label, prompt in frames.items():
response = client.chat.completions.create(
model='gpt-4o', max_tokens=80,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'[{label}]: {response.choices[0].message.content.strip()[:120]}...')
print()ตรวจสอบความรู้
นักพัฒนาต้องการให้ปัญญาประดิษฐ์วิจารณ์ชุดสไลด์นำเสนอธุรกิจของตนอย่างรุนแรงและตรงไปตรงมา — ไม่ต้องให้กำลังใจ ไม่ต้องสมดุล และให้วิจารณ์ในเชิงคัดค้านอย่างเต็มที่ กรอบเปิดเรื่องใดทำได้ดีที่สุด
การกำหนดฉาก — ทบทวน
กรอบเปิดเรื่องจะกำหนดทิศทางให้โมเดลก่อนที่โมเดลจะอ่านคำสั่งของงาน กรอบที่มีประสิทธิภาพสูงสุดสี่กรอบ ได้แก่:
- “คุณคือ...”: กำหนดบุคลิกที่มีความเชี่ยวชาญ รูปแบบการสื่อสาร และลำดับความสำคัญเฉพาะ
- “บริบทคือ...”: กำหนดพื้นหลังของสถานการณ์โดยไม่กำหนดบุคลิก
- “เมื่อพิจารณาว่า...”: กำหนดข้อสมมติหรือข้อจำกัดที่โมเดลต้องถือว่าเป็นจริง
- “เป้าหมายคือ...”: กำหนดจุดประสงค์ปลายทางของผลลัพธ์
ผสานกรอบต่าง ๆ สำหรับงานที่ซับซ้อน ไม่ต้องใช้กรอบกับงานที่เป็นกระบวนการเชิงกลล้วน ๆ และทดสอบรูปแบบของกรอบเพื่อค้นหาวิธีที่เหมาะกับกรณีใช้งานของคุณที่สุด
คำถามที่พบบ่อย
บทเรียน “การกำหนดฉากอย่างมีประสิทธิภาพ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การกำหนดฉากอย่างมีประสิทธิภาพ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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 ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “การกำหนดฉากอย่างมีประสิทธิภาพ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน AI Prompt Engineering นี้ได้ไหม
ได้ บทเรียน AI Prompt Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บริบทในการเขียนพรอมต์ให้ปัญญาประดิษฐ์หมายถึงอะไร
- การให้ข้อมูลพื้นฐาน
- การกำหนดฉากอย่างมีประสิทธิภาพ
- ความยาวและความเกี่ยวข้องของบริบท