เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Building a conversation-manager class

You’ve joined ChargeNet, a company rolling out a nationwide network of rapid-charging stations for electric vehicles. Your task is to build ChargeBot, a customer-support chatbot. The first step is creating a ConversationManager class to keep track of the chat history so Claude can generate coherent replies.

The boto3 library has been preloaded.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Introduction to Amazon Bedrock

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Create an empty list to store the conversation_history.
  • Add a method add_message() that takes a role and content, and appends a dictionary to the history.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

class ConversationManager:
    def __init__(self):
        self.bedrock = boto3.client("bedrock-runtime", region_name="us-east-1")
        # Create an empty list for the conversation history
        ____

    # Add the method to append messages    
    def ____(self, ____, ____):
        self.conversation_history.append({"role": role, "content": content})
แก้ไขและรันโค้ด