กลยุทธ์การเขียน prompt ขั้นสูง

Amazon Bedrock เบื้องต้น

Nikhil Rangarajan

Data Scientist

สถาปัตยกรรมของ prompt

  • System prompt กำหนดสไตล์และแนวทาง
  • Chain-of-thought prompt ให้กรอบการแก้ปัญหา
  • Few-shot prompt ให้ตัวอย่าง
  • แต่ละชั้นช่วยเสริมความเข้าใจและเพิ่มความน่าเชื่อถือ

แผนภูมิแสดงเฟือง 4 ตัวที่เชื่อมต่อกัน แสดงลำดับสถาปัตยกรรม prompt ได้แก่ System Prompt, Chain of Thought Steps, Few-Shot Examples และ Content Request

Amazon Bedrock เบื้องต้น

System prompt และการควบคุมสไตล์

prompt_template = {
    "system_prompt": f"""System: Write in a professional but approachable tone.""",

"content_type": "blog_post",
"examples": [ { "title": "Cloud Migration Basics", "content": "Moving to the cloud doesn't have to be complex..." } ],
"task": f"Write a blog post about {topic}"
}
Amazon Bedrock เบื้องต้น

Chain-of-thought prompting

def generate_message_content(text_data):
    steps = [
        "1. Understand the target audience",
        "2. Outline key points",
        "3. Draft a promotional email"
    ]

text_data["text"] += f"\nSteps:{' '.join(steps)}"
return text_data
  • 💡 ชี้นำกระบวนการคิดของโมเดล
Amazon Bedrock เบื้องต้น

การปรับเนื้อหาและพารามิเตอร์

parameters = {

"blog_post": {"temperature": 0.7, "top_p": 0.9}, "social_media": {"temperature": 0.8, "top_p": 0.95},
"technical": {"temperature": 0.4, "top_p": 0.8}
}
content_type = "blog_post" prompt_data["parameters"] = parameters[content_type]
  • ปรับพารามิเตอร์ตามประเภทเนื้อหา
  • ใช้ค่าพารามิเตอร์ที่กำหนดไว้ล่วงหน้าเพื่อความสม่ำเสมอ
Amazon Bedrock เบื้องต้น

สร้าง prompt ด้วย template

# Write the prompt
topic = "Cloud Security"
content_type = "blog_post"
prompt = f"Write a {topic} blog post. Use this example: {prompt_template["examples"][0]}"


# Define the parameters temperature = parameters[content_type]["temperature"] top_p = parameters[content_type]["top_p"]
# Call the model response = bedrock.invoke_model(modelId=model_id, body=json.dumps({"messages": [{"role": "user","content": [{"type": "text", "text": prompt}]}], "temperature": temperature, "top_p": top_p}))
Amazon Bedrock เบื้องต้น

มาฝึกกันเถอะ!

Amazon Bedrock เบื้องต้น

Preparing Video For Download...