Enhancing prompts with role assignment
You work on SkyCast Assistant, a smart-weather platform that turns detailed forecasts into clear insights. They've asked you to work on integrating Amazon Bedrock, and as a first step you add the role of weather assistant to the prompt.
The json
library and bedrock
client have been pre-imported.
This exercise is part of the course
Introduction to Amazon Bedrock
Exercise instructions
- Specify the role of a weather assistant as part of the prompt.
- Parse the response body to extract the output.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Format the prompt with role and required Claude format
prompt = '____'
request_body = json.dumps({"anthropic_version": "bedrock-2023-05-31", "max_tokens": 100,
"messages": [{"role": "user", "content": prompt}]})
response = bedrock.invoke_model(modelId='anthropic.claude-3-5-sonnet-20240620-v1:0',
body=request_body)
# Extract completion from response
output = json.loads(response['body'].____)['content'][0]['text'] # Parse JSON and get completion
print(output)