Aan de slagGa gratis aan de slag

Configure outputs for multiple tools

Your chatbot's graph is ready to go! Now you can test how the chatbot works with different queries that should require different tools. To manage your chatbot's messages, the following modules have already been imported and your chatbot's config parameters have been set for one session.

from langchain_core.messages import AIMessage, HumanMessage

config = {"configurable": {"thread_id": "1"}}

Deze oefening maakt deel uit van de cursus

Designing Agentic Systems with LangChain

Cursus bekijken

Oefeninstructies

  • Create an inputs message dictionary with the user's query as content for HumanMessage.
  • Stream msg and metadata from the chatbot app by iterating over the results using the .stream() method incorporating inputs and config.
  • Check if each msg has content and is not a HumanMessage, then print its content with flush set to True for immediate output printing.
  • Test the chatbot using multi_tool_output() with queries requiring different tools.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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?")
Code bewerken en uitvoeren