Aan de slagGa gratis aan de slag

Build a tool that invokes the LLM

The school administration loves your work on the education app with the Wikipedia search agent. They would love you to expand the app even further with some additional tools. Here, you'll build a tool called historical_events() that's able to invoke the LLM within the body of the tool to answer questions about famous dates in history. The Wikipedia tool has already been set up for you and the llm is available in your environment.

Deze oefening maakt deel uit van de cursus

Designing Agentic Systems with LangChain

Cursus bekijken

Oefeninstructies

  • Add a decorator to label the tool and set the input format to string.
  • Within the try block, use the .invoke() method with the llm to query the LLM with the date_input to generate historical events.
  • Return the content of the LLM's response using .content.
  • Add an Exception block as e to catch errors and format the error message to include the error details.

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# Use a decorator to label the tool and set the input format to string
@____
def historical_events(date_input: ____) -> ____:
    """Provide a list of important historical events for a given date in any format."""
    try:

      	# Invoke the LLM to interpret the date and generate historical events
        response = ____.____(f"List important historical events that occurred on {____}.")
        
        # Return the response
        return ____.____

    # Set an exception block for errors in retrieval
    except ____ as ____:
        return f"Error retrieving events: {str(____)}"
Code bewerken en uitvoeren