Stilgerechte Inhaltserstellung mit Bedrock
Das Developer-Relations-Team von StellarStack schreibt Blogartikel. Du baust einen System-Prompt, der Claude anweist, bei der Erklärung von Cloud-Best Practices für StellarStack-Nutzer eine professionelle, aber freundliche Stimme zu verwenden.
Die Bibliotheken json und boto3 sowie der bedrock-Client sind vorab geladen.
Diese Übung ist Teil des Kurses
Einführung in Amazon Bedrock
Anleitung zur Übung
- Verwende Werte aus dem Dictionary
prompt_template, um den finalen Prompt zu erstellen.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
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="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"])