follow the tutorial and make a terminal chat ap with rich text wehrer I can chat with…
- User
follow the tutorial and make a terminal chat ap with rich text wehrer I can chat with llama3.1 from ollama: r_schema]: tool_name = tool_obj["function"]["name"] if tool_name != "final_answer": graph.add_edge(tool_name, "oracle") # ————————>
if anything goes to final answer, it must then move to END
graph.add_edge("final_answer", END)
runnable = graph.compile()
To view the graph, we can generate a mermaid graph like so:
import nest_asyncio from IPython.display import Image, display from langchain_core.runnables.graph import CurveStyle, MermaidDrawMethod, NodeStyles
nest_asyncio.apply() # Required for Jupyter Notebook to run async functions
display( Image( runnable.get_graph().draw_mermaid_png( curve_style=CurveStyle.LINEAR, node_colors=NodeStyles(first="#ffdfba", last="#baffc9", default="#fad7de"), wrap_label_n_words=9, output_file_path=None, draw_method=MermaidDrawMethod.PYPPETEER, background_color="white", padding=10, ) ) )
Mermaid diagram showing the agent flow. Testing the Agent
Our agent has now been constructed so we can test it. First, let's check for the best pizza in Rome:
out = runnable.invoke({ "input": "where is the best pizza in rome?", "chat_history": [], })
run_oracle router run_tool | search.invoke(input={'query': 'best pizza in Rome'}) Best pizza in Rome? Visited Rome and had one of the best pizzas of my life Best Pizza in Rome! run_oracle router run_tool | final_answer.invoke(input={'answer': 'Based on your question, I would recommend trying Seu Pizza Illuminati in Rome for an amazing pizza experience. They are known for their creative use of condiments and experiments with vegetables. If you prefer a Neapolitan-style pizza, Pizzeria da Remo or Emma might be the perfect choice for you. Both places have received great reviews from locals and visitors alike.', 'phone_number': '', 'address': ''})We extract the answer:
out["output"]
{'answer': 'Based on your question, I would recommend trying Seu Pizza Illuminati in Rome for an amazing pizza experience. They are known for their creative use of condiments and experiments with vegetables. If you prefer a Neapolitan-style pizza, Pizzeria da Remo or Emma might be the perfect choice for you. Both places have received great reviews from locals and visitors alike.', 'phone_number': '', 'address': ''}We are recommended Seu Pizza Illuminati, a seemingly notorious pizzeria known for their less traditional and more experimental Neapolitan pizzas.
- Assistant