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.
APACHE-2.0 License
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
Install this library:
pip install langchain-plantuml
Then:
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)
You can download plantuml.1.2023.10.jar
java -DPLANTUML_LIMIT_SIZE=81920 -jar plantuml-1.2023.10.jar example-activity.puml