Introduction to Amazon Bedrock
Nikhil Rangarajan
Data Scientist
class ConversationManager:
def __init__(self): self.bedrock = boto3.client('bedrock-runtime')
self.conversation_history = [] self.max_tokens = 8000
def add_message(self, role, content): self.conversation_history .append({"role": role,
"content": content
})
conversation_manager = ConversationManager()
conversation_manager.add_message("user", "What's the weather like?")
# Send the latest context to the model conversation_history = conversation_manager.conversation_history messages = "\n\n".join( f"{msg['role']}: {msg['content']}" for msg in conversation_history[-2:]) # Only most recent exchanges
# Send the full message to the model response = conversation_manager.bedrock.invoke_model( modelId="amazon.nova-micro-v1:0", body=messages)
Introduction to Amazon Bedrock