Introduction to Amazon Bedrock
Nikhil Rangarajan
Data Scientist

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}"}
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
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]
# 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}))
Introduction to Amazon Bedrock