Geavanceerde promptingstrategieën

Introductie tot Amazon Bedrock

Nikhil Rangarajan

Data Scientist

Promptarchitectuur

  • Systeemprompts bepalen stijl en aanpak
  • Chain-of-thought-prompts geven een oplossingskader
  • Few-shot-prompts geven voorbeelden
  • Elke laag bouwt begrip op en verhoogt betrouwbaarheid

Een diagram met vier gekoppelde tandwielen dat de promptarchitectuur toont: systeemprompt, chain-of-thought-stappen, few-shot-voorbeelden en contentverzoek.

Introductie tot Amazon Bedrock

Systeemprompts en stijlaanpassing

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}"
}
Introductie tot 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
  • 💡 Stuurt het denkproces van het model
Introductie tot Amazon Bedrock

Contentaanpassing en parameters

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]
  • Pas parameters aan per contenttype
  • Voorinstellingen voor consistentie
Introductie tot Amazon Bedrock

Prompts genereren met templates

# 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}))
Introductie tot Amazon Bedrock

Laten we oefenen!

Introductie tot Amazon Bedrock

Preparing Video For Download...