Visualization and debugging tool for LangChain workflows
Project description
LangChain Visualizer
Adapts ICE for use with LangChain so that you can view LangChain interactions with a beautiful UI.
You can now
- See the full prompt text being sent with every interaction with the LLM
- Tell from the coloring which parts of the prompt are hardcoded and which parts are templated substitutions
- Inspect the execution flow and observe when each function goes up the stack
Quickstart
Install this library:
pip install langchain-visualizer
Then:
- Add
import langchain_visualizer
as the first import in your Python entrypoint file - Write an async function to visualize whichever workflow you're running
- Call
langchain_visualizer.visualize
on that function
For an example, see below instructions on reproducing the screenshot.
Running the example screenshot
To run the example you see in the screenshot, first install this library and optional dependencies:
pip install langchain-visualizer google-search-results openai
If you haven't yet set up your OpenAI API keys or SERP API keys, you can replay the recorded interactions by cloning this repository and running
python tests/agents/test_langchain_getting_started.py
If you have set them up, you can run the following script (adapted from LangChain docs):
import langchain_visualizer
import asyncio
from langchain.agents import initialize_agent, load_tools
from langchain.llms import OpenAI
llm = OpenAI(temperature=0.7)
tools = load_tools(["serpapi", "llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent="zero-shot-react-description", verbose=True)
async def search_agent_demo():
return agent.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!
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 projects
Please check out VCR LangChain, a library that lets you record LLM interactions for your tests and demos!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for langchain_visualizer-0.0.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a037371ed07d2d910b130229cd5a0059f9fdb0dc819b875bb181cc699a4bc178 |
|
MD5 | 922ea348a3df8ed80fc989e5d3361400 |
|
BLAKE2b-256 | 6377aaf7618d1c37df7a1b77425a823a22d5653be441e8793aa4c1cf46bbc21c |
Hashes for langchain_visualizer-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 602bed2994ae35fa077dab87dd1c352b784deeab00346fb7960f34e92cf46b32 |
|
MD5 | f70a10622a07ce3e1c76c61cd2a59e94 |
|
BLAKE2b-256 | 1be73703d90ecd4f77439f87e183f6e0d0c6adbfcebe6131e8969df5a3d2791f |