대화 관리 클래스 만들기
전국 규모의 전기차 급속 충전소 네트워크를 구축 중인 ChargeNet에 합류했어요. 여러분의 임무는 고객 지원 챗봇인 ChargeBot을 만드는 것입니다. 첫 단계로, Claude가 일관성 있는 답변을 생성할 수 있도록 대화 기록을 관리하는 ConversationManager 클래스를 구현하세요.
boto3 라이브러리는 미리 로드되어 있습니다.
이 연습은 강의의 일부입니다
Amazon Bedrock 입문
연습 안내
conversation_history를 저장할 빈 목록을 만드세요.role과content를 받아 기록에 사전을 추가하는add_message()메서드를 추가하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
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})