เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Styled content generation with Bedrock

StellarStack’s developer-relations team is writing blog content. You’ll build a system prompt that tells Claude to use a professional-yet-friendly voice when explaining cloud best practices to StellarStack users.

The json and boto3 libraries, as well as the bedrock client, are preloaded.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Amazon Bedrock

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Use values from the prompt_template dictionary to build the final prompt.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

prompt_template = {
    "tone": "Write in a professional but friendly tone.",
    "task": "Write a blog post about",
    "topic": "multi-cloud best practices for StellarStack users"
}

# Use the dictionary values to build the prompt 
prompt = f"{prompt_template['____']}\n{prompt_template['____']} {prompt_template['____']}"

response = bedrock.invoke_model(modelId="us.anthropic.claude-sonnet-4-5-20250929-v1:0",
    body=json.dumps({"anthropic_version": "bedrock-2023-05-31", "max_tokens": 100,
        "messages": [{"role": "user", "content": [{"type": "text", "text": prompt}]}]}))

print(json.loads(response["body"].read().decode())["content"][0]["text"])
แก้ไขและรันโค้ด