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
LangChain PlantUML Callback Handler
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 plantuml
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")
callback_handler = plantuml.activity_diagram_callback()
llm_chain = LLMChain(
llm=OpenAI(),
prompt=prompt,
verbose=True,
memory=memory,
callbacks=[callback_handler]
)
llm_chain.predict(human_input="Hi there my friend")
llm_chain.predict(human_input="Not too bad - how are you?")
callback_handler.save_uml_content("example-activity.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
Hashes for langchain_plantuml-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec0db758af2f6471aa0828691f7e83f2895a248d23c552099e29b002971fc4f3 |
|
MD5 | c4d559e744af147211108c8eeb9de6df |
|
BLAKE2b-256 | e290dd54dcbc9e274ccd54292b32550b5809e283154c7f4d3844e830a6ac8348 |