Chiến lược nhắc nâng cao

Giới thiệu về Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Kiến trúc prompting

  • System prompt đặt phong cách và cách tiếp cận
  • Chain-of-thought cung cấp khung giải quyết vấn đề
  • Few-shot đưa ví dụ minh họa
  • Mỗi lớp tăng hiểu biết, cải thiện độ tin cậy

Biểu đồ với bốn bánh răng nối nhau thể hiện chuỗi kiến trúc prompt: System Prompt, Chain of Thought Steps, Few-Shot Examples, và Content Request.

Giới thiệu về Amazon Bedrock

System prompt và kiểm soát phong cách

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}"
}
Giới thiệu về 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
  • 💡 Hướng dẫn quá trình suy nghĩ của mô hình
Giới thiệu về Amazon Bedrock

Điều chỉnh nội dung và tham số

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]
  • Điều chỉnh tham số theo loại nội dung
  • Bộ preset tham số để nhất quán
Giới thiệu về Amazon Bedrock

Tạo prompt với mẫu

# 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}))
Giới thiệu về Amazon Bedrock

Passons à la pratique !

Giới thiệu về Amazon Bedrock

Preparing Video For Download...