İleri düzey yönlendirme stratejileri

Amazon Bedrock'a Giriş

Nikhil Rangarajan

Data Scientist

İstem mimarisi

  • Sistem komutları üslup ve yaklaşımı belirler
  • Düşünce zinciri komutları sorun çözme çerçevesi sunar
  • Az örnekli komutlar örnek sağlar
  • Her katman anlayışı artırır, güvenilirliği iyileştirir

İstem mimarisi sırasını gösteren dört bağlı dişli grafiği: Sistem Komutu, Düşünce Zinciri Adımları, Az Örnekli Örnekler ve İçerik İsteği.

Amazon Bedrock'a Giriş

Sistem komutları ve üslup kontrolü

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}"
}
Amazon Bedrock'a Giriş

Düşünce zinciri komutları

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
  • 💡 Modelin düşünme sürecini yönlendirir
Amazon Bedrock'a Giriş

İçerik uyarlama ve parametreler

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]
  • İçerik türüne göre parametreleri ayarlayın
  • Tutarlılık için hazır ayarlar
Amazon Bedrock'a Giriş

Şablonlarla komut üretme

# Komutu yazın
topic = "Cloud Security"
content_type = "blog_post"
prompt = f"Write a {topic} blog post. Use this example: {prompt_template["examples"][0]}"


# Parametreleri tanımlayın temperature = parameters[content_type]["temperature"] top_p = parameters[content_type]["top_p"]
# Modeli çağırın response = bedrock.invoke_model(modelId=model_id, body=json.dumps({"messages": [{"role": "user","content": [{"type": "text", "text": prompt}]}], "temperature": temperature, "top_p": top_p}))
Amazon Bedrock'a Giriş

Hadi pratik yapalım!

Amazon Bedrock'a Giriş

Preparing Video For Download...