28차시. Conditional Edge 이해
퀴즈 2 — 의도가 비면 document로 보내기
의도가 비어 있으면 document를 반환하세요.
빈칸 코드에서 시작합니다.
def route_intent(state):
pass결과 보기 (예시 풀이)
# 의도(intent)가 비어 있으면 손해가 덜한 document 로 보냅니다.
def route_intent(state):
# None, "" 모두 거짓이므로 or 뒤의 기본값이 쓰입니다.
intent = state.get("intent") or "document"
return intent
# 키가 아예 없을 때, None 일 때, 빈 문자열일 때, 값이 있을 때를 차례로 봅니다.
cases = [{}, {"intent": None}, {"intent": ""}, {"intent": "greeting"}, {"intent": "calc"}]
for s in cases:
# 앞의 세 경우는 document, 뒤의 두 경우는 그 값 그대로여야 합니다.
print(s, "->", route_intent(s))
실행 결과
{} -> document
{'intent': None} -> document
{'intent': ''} -> document
{'intent': 'greeting'} -> greeting
{'intent': 'calc'} -> calc채점 기준: None이나 빈 문자열은 document.
관련 교안: 28차시 「5. 질문 유형 라우팅 개념」