여러 도구에 맞게 결과물 설정하기
이제 챗봇의 그래프가 준비되었어요! 서로 다른 도구가 필요할 다양한 질의로 챗봇이 어떻게 동작하는지 시험해 보세요. 챗봇의 메시지를 관리하기 위해 다음 모듈이 이미 임포트되어 있고, 한 세션용 config 매개변수도 설정되어 있어요.
from langchain_core.messages import AIMessage, HumanMessage
config = {"configurable": {"thread_id": "1"}}
이 연습은 강의의 일부입니다
LangChain으로 에이전트형 시스템 설계하기
연습 안내
- 사용자의
query를HumanMessage의content로 넣어inputs메시지 딕셔너리를 만드세요. .stream()메서드를 사용해inputs와config를 포함하여 결과를 반복(iterate)하면서 챗봇app에서msg와metadata를 스트리밍하세요.- 각
msg에content가 있고HumanMessage가 아니라면, 즉시 출력되도록flush를True로 설정해 그content를 출력하세요. - 서로 다른 도구가 필요한 질의로
multi_tool_output()을 사용해 챗봇을 테스트하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Create input message with the user's query
def multi_tool_output(____):
inputs = {"messages": [____(____=____)]}
# Stream messages and metadata from the chatbot application
for ____, ____ in app.____(____, ____, stream_mode="messages"):
# Check if the message has content and is not from a human
if ____.____ and not isinstance(____, ____):
print(____.____, end="", flush=____)
print("\n")
# Call the chatbot with different tools
____("Is `may a moody baby doom a yam` a palindrome?")
____("What happened on 20th July, 1969?")