Queries and responses
The agent graph is set up so your chatbot is ready to run! Now you can define a function that allows the chatbot to answer queries using ChatGPT. This function will stream through the graph events in real-time and return the last message as a response to the user's query.
Questo esercizio fa parte del corso
Designing Agentic Systems with LangChain
Istruzioni dell'esercizio
- Define the
stream_graph_updates()function to acceptuser_inputas a string parameter for chatbot execution. - Apply the
.stream()method tographto stream events withuser_inputas a"user"message in"messages". - For each
iteminevent.values(), retrieve and print the response using the"messages"key initem. - Pass
user_queryto thestream_graph_updates()function to test the chatbot.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# Define a function to execute the chatbot based on user input
def stream_graph_updates(____: ____):
# Start streaming events from the graph with the user's input
for event in graph.____({"____": [("____", ____)]}):
# Retrieve and print the chatbot node responses
for ____ in event.values():
print("Agent:", ____["____"])
# Define the user query and run the chatbot
____ = "Who is Ada Lovelace?"
stream_graph_updates(____)