Bắt đầu ngayBắt đầu miễn phí

Tạo nội dung theo phong cách với Bedrock

Nhóm developer relations của StellarStack đang viết nội dung blog. Bạn sẽ xây dựng một system prompt để yêu cầu Claude sử dụng giọng điệu chuyên nghiệp nhưng thân thiện khi giải thích các thực tiễn tốt nhất về cloud cho người dùng StellarStack.

Các thư viện jsonboto3, cùng với client bedrock, đã được nạp sẵn.

Bài tập này là một phần của khóa học

Giới thiệu về Amazon Bedrock

Xem khóa học

Hướng dẫn bài tập

  • Sử dụng các giá trị từ dictionary prompt_template để xây dựng prompt cuối cùng.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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"])
Chỉnh sửa và Chạy Mã