Subscribe to events using a callback and store them in PlantUML format. You can easily subscribe to events and keep them in a form that is easy to visualize and analyze.
Project description
Visualization UML diagram tool for LangChain workflows
Subscribe to events using a callback and store them in PlantUML format to easily visualize LangChain workflow in Activity Diagram and Sequence Diagram. You can easily subscribe to events and keep them in a form that is easy to visualize and analyze using PlantUML.
Activity Diagram
Sequence Diagram
Quick Start
Install this library:
pip install langchain-plantuml
Then:
- Add import langchain_plantuml as the first import in your Python entrypoint file
- Create a callback using the activity_diagram_callback function
- Hook into your LLM application
- Call the export_uml_content method of activity_diagram_callback to export the PlantUML content
- Save PlantUML content to a file
- Exporting PlantUML to PNG
Running the minimal activity diagram example.
from langchain import OpenAI, LLMChain, PromptTemplate
from langchain.memory import ConversationBufferMemory
from langchain_plantuml import diagram
template = """You are a chatbot having a conversation with a human.
{chat_history}
Human: {human_input}
Chatbot:"""
prompt = PromptTemplate(
input_variables=["chat_history", "human_input"], template=template
)
memory = ConversationBufferMemory(memory_key="chat_history")
activity_diagram = diagram.activity_diagram_callback(note_max_length=2000)
sequence_diagram = diagram.sequence_diagram_callback(note_max_length=2000)
llm_chain = LLMChain(
llm=OpenAI(),
prompt=prompt,
verbose=True,
memory=memory,
callbacks=[activity_diagram, sequence_diagram]
)
try:
llm_chain.predict(human_input="What did biden say about ketanji brown jackson in the state of the union address?")
finally:
activity_diagram.save_uml_content("example_1_activity-plantuml.puml")
sequence_diagram.save_uml_content("example_1_sequence-plantuml.puml")
You will get the following PlantUML activity diagram
Sequence Diagram
callback_handler = diagram.sequence_diagram_callback()
Custom note max Length(default 1000)
callback_handler = diagram.activity_diagram_callback(note_max_length=2000)
Custom note wrap width(default 500)
callback_handler = diagram.activity_diagram_callback(note_wrap_width=500)
Exporting PlantUML to PNG
You can download plantuml.1.2023.10.jar
java -DPLANTUML_LIMIT_SIZE=81920 -jar plantuml-1.2023.10.jar example-activity.puml
Project details
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
File details
Details for the file langchain_plantuml-0.0.7.tar.gz
.
File metadata
- Download URL: langchain_plantuml-0.0.7.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6513034d3779c709a8d839049fe810312ae4453461597b0233a8b94c505dbdbd |
|
MD5 | dc65d51a6593f8037183b4b09d4882bb |
|
BLAKE2b-256 | 33fab2e7e9e7922d2069f37e833952a5215e4c19e0714c5159f0364edbb59625 |
File details
Details for the file langchain_plantuml-0.0.7-py3-none-any.whl
.
File metadata
- Download URL: langchain_plantuml-0.0.7-py3-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ce9d54c76f9856a571f13b94c22d28df38f1819b019a17885e25622fd990be3 |
|
MD5 | 3b7b73d50af89e666c8cb0ccf936819c |
|
BLAKE2b-256 | c53fee7988f3d7d9a09da75cd34a997ddf291d522b3cb054cb80d7e8a4379f78 |