Introduction to Amazon Bedrock
Nikhil Rangarajan
Data Scientist
"Explain the benefits of exercise
in simple terms."
"You are a nutritionist. Explain the
benefits of a balanced diet."
"List the top 3 benefits of cloud
computing in bullet points."
data = json.loads(response['body'].read()) if 'completion' in data: output = data['completion']
else: output = "Key not found"
try: nova_output = data.decode()["output"]
except (KeyError, IndexError) as e: nova_output = f"Error: {str(e)}"
# Ensure proper encoding
output = data['completion'].encode('utf-8').decode('unicode_escape')
print(output)
# Truncate response for display
output = data['completion'][:500] # Limit to 500 characters
print(output)
def categorize_ticket(ticket, categories): prompt = f"Categorize into one: {', '.join(categories)}. Ticket: {ticket}" response = bedrock.invoke_model( modelId='amazon.nova-micro-v1:0', body=json.dumps({"messages": [{"role": "user", "content": [{"text": prompt}]}]}))
return json.loads(nova_response.get("body").read().decode())["output"]
{"output": {"message": {"role": "assistant","content": [
{
"text": "Customer Service"
}]}, "stop_reason": "stop_sequence"}}
Introduction to Amazon Bedrock