Package: langchain-visualizer
LangChain VisualizerAdaptsOught's ICE visualizerfor use withLangChainso that you can view LangChain interactions with a beautiful UI.You can nowSee the full prompt text being sent with every interaction with the LLMTell from the coloring which parts of the prompt are hardcoded and which parts are templated substitutionsInspect the execution flow and observe when each function goes up the stackSee the costs of each LLM call, and of the entire run, if you are using OpenAI'stext-davinci-003modelQuickstartInstall this library:pipinstalllangchain-visualizerNote that if you're on a Linux distribution, you may need to install libyaml first:aptinstall-ylibyaml-devThen:Addimport langchain_visualizerasthe first importin your Python entrypoint fileWrite an async function to visualize whichever workflow you're runningCalllangchain_visualizer.visualizeon that functionFor an example, see below instructions on reproducing the screenshot.Running the example screenshotTo run the example you see in the screenshot, first install this library and optional dependencies:pipinstalllangchain-visualizergoogle-search-resultsopenaiIf you haven't yet set up yourOpenAI API keysor SERP API keys, you canreplay the recorded interactionsby cloning this repository and running$pipinstallvcr-langchain
$OPENAI_API_KEY=dummypythontests/agents/test_langchain_getting_started.pyIf you have set them up, you can run the following script (adapted fromLangChain docs):importlangchain_visualizerimportasynciofromlangchain.agentsimportinitialize_agent,load_toolsfromlangchain.llmsimportOpenAIllm=OpenAI(temperature=0.7)tools=load_tools(["serpapi","llm-math"],llm=llm)agent=initialize_agent(tools,llm,agent="zero-shot-react-description",verbose=True)asyncdefsearch_agent_demo():returnagent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 ""power?")langchain_visualizer.visualize(search_agent_demo)A browser window will open up, and you can actually see the agent execute happen in real-time!Jupyter notebook supportJupyter notebooks are now supported! To use this inside a Jupyter notebook,make sure to import thevisualizefunction fromlangchain_visualizer.jupyterinstead.Please look atthe demo notebookto see an example of how it can be used in Jupyter.Visualizing embeddingsIf you want to also visualize documents being chunked up for embeddings, you can now do so by calling thevisualize_embeddingsfunction before you visualize the main chain:fromlangchain_visualizerimportvisualize,visualize_embeddingsasyncdefrun_chain():...visualize_embeddings()visualize(run_chain)Why not just use LangChain's built-in tracer?For me personally:I prefer the ICE UI. In particular:I like the colored highlighting of parts of the prompt that are filled-in template variablesI like the ability to quickly inspect different LLM calls without leaving the trace pageI prefer the visualization of my agent logic to remain static when LLM calls are cachedI prefer seeing when the tool (e.g.PythonREPL) actually gets called, rather than just the high-level execution of the chain (e.g.LLMMathChain)That being said, LangChain's tracer is definitely better supported.Please note that there is a lot of langchain functionality that I haven't gotten around to hijacking for visualization.If there's anything you need to show up in the execution trace, please open a PR or issue.My other projectsPlease check outVCR LangChain, a library that lets you record LLM interactions for your tests and demos!