0Pricing
Prompt Engineering & LLM Optimization for Developers · บทเรียน

พรอมต์กำหนดบทบาทและบุคลิก

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

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

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Intro: Role-Playing Prompts

Welcome to Role-Playing & Persona Prompts! This technique helps you guide Large Language Models (LLMs) to generate more specific and relevant outputs.

Think of it as giving the LLM a job description before it starts working on your request.

What are Persona Prompts?

A persona prompt assigns a specific identity, role, or character to an LLM. This can include:

  • An expert (e.g., 'senior software engineer')
  • A specific type of assistant (e.g., 'friendly travel agent')
  • A fictional character (e.g., 'wise old wizard')
  • A specific interface (e.g., 'Linux terminal')

By defining a persona, you influence the LLM's tone, style, and even its knowledge focus.

Why Use Persona Prompts?

Using personas offers several key advantages:

  • Consistent Output: Ensures the LLM maintains a specific tone and style throughout the conversation.
  • Targeted Knowledge: Helps the LLM focus on relevant information for the assigned role.
  • Improved Relevance: Generates answers tailored to the perspective of the persona.
  • Controlled Format: Can guide the LLM to output information in a specific structure.

Crafting a Role Statement

To assign a role, simply state it clearly at the beginning of your prompt. Use phrases like:

  • Act as a [role]...
  • You are a [role]...
  • Simulate a [role]...

Be explicit about the role and any key characteristics.

Example: The Expert Engineer

Here's how you might prompt an LLM to act as a senior software engineer. Notice how the role sets the context for the advice.

Act as a senior software engineer.
Explain the importance of code readability for junior developers in a simple way.

Run: Expert Engineer Prompt

Let's see this in action! This Python snippet simulates sending a prompt to an LLM API. The key is the 'engineer_prompt' string.

import os

def get_llm_response(prompt_text):
    # In a real app, this would be an actual API call (e.g., OpenAI, Anthropic)
    print(f"--- Sending Prompt ---\n{prompt_text}\n--- LLM Response (simulated) ---")
    if "senior software engineer" in prompt_text.lower():
        return "As a senior software engineer, I'd say good variable names are key for readable code. Also, break down complex functions into smaller, focused units. It makes maintenance and collaboration much easier!"
    else:
        return "I processed your request."

def main():
    engineer_prompt = (
        "Act as a senior software engineer. "
        "Explain the importance of clean code in a simple way."
    )
    print("Engineer's advice:")
    print(get_llm_response(engineer_prompt))

if __name__ == "__main__":
    main()

Example: The Creative Storyteller

Personas aren't just for experts! You can also use them for creative tasks. Here, we'll ask the LLM to act as a storyteller.

You are a whimsical storyteller. Write a very short tale about a tiny robot who dreams of flying, using no more than 50 words.

Combining Roles & Constraints

You can make persona prompts even more powerful by adding specific constraints or instructions. For example:

  • Act as a JSON API that returns user data. Only output JSON.
  • You are a helpful coding assistant. Provide Python code examples only.
  • Simulate a debugging console. Only respond with error messages and suggestions.

This ensures both the role and the desired output format are met.

Best Practices for Personas

To get the most out of persona prompts:

  • Be Specific: A clear role is better than a vague one.
  • Keep it Concise: Don't overload the role description.
  • Test & Iterate: Experiment to see which roles work best for your task.
  • Avoid Over-constraining: Give the LLM enough room to generate useful responses within the role.

Quick Check: Persona Power

You've learned about the power of persona prompts. Which of the following are key benefits of assigning a role to an LLM?

Recap: Mastering Personas

Great job! You've mastered the basics of Role-Playing & Persona Prompts.

  • You learned how to assign a specific identity to an LLM.
  • You saw how personas ensure consistent tone, focused knowledge, and relevant output.
  • You practiced crafting clear role statements and combining them with constraints.

Next, we'll dive into Instruction Following & Constraints to further refine your LLM interactions!

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

บทเรียน “พรอมต์กำหนดบทบาทและบุคลิก” ฟรีหรือไม่

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

คุณจะเรียนรู้อะไรในบทเรียน “พรอมต์กำหนดบทบาทและบุคลิก”

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

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

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

บทเรียน “พรอมต์กำหนดบทบาทและบุคลิก” ใช้เวลานานแค่ไหน

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

ฉันเขียนและรันโค้ดในบทเรียน Prompt Engineering & LLM Optimization for Developers นี้ได้ไหม

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

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

  1. พรอมต์กำหนดบทบาทและบุคลิก
  2. การทำตามคำสั่งและข้อจำกัด
  3. การปรับปรุงพรอมต์แบบวนซ้ำ
  4. ตัวคั่นและพรอมต์แบบมีโครงสร้าง
← กลับไปที่ Prompt Engineering & LLM Optimization for Developers