Get startedGet started for free

Styled content generation with Bedrock

System prompts are powerful tools for setting tone and structure in content generation. In this exercise, you'll use a prompt template to direct Claude to generate content in a professional but friendly tone.

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

This exercise is part of the course

Introduction to Amazon Bedrock

View Course

Exercise instructions

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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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

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

response = bedrock.invoke_model(modelId="anthropic.claude-3-5-sonnet-20240620-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"])
Edit and Run Code