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 Activity Diagram and Sequence Diagram. You can easily subscribe to events and keep them in a form that is easy to visualize and analyze.
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")
callback_handler = diagram.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()
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.3.tar.gz
.
File metadata
- Download URL: langchain_plantuml-0.0.3.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5293162f353ab8e3774bac41ba926315d4159a24f8ce935375922c3c3c6a1184 |
|
MD5 | 707da4723b819026a253f1e4105a5067 |
|
BLAKE2b-256 | 0b86042e0915b8b6aff6f9e449fb39e4da0886b6ae30137b135e4effaf8724c6 |
File details
Details for the file langchain_plantuml-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: langchain_plantuml-0.0.3-py3-none-any.whl
- Upload date:
- Size: 15.1 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 | c86953eba411b3f51f98dfae75ea66f7f38dc53d010413e68183f8e62811c69a |
|
MD5 | b7618b27115543a873a5e78b52bb3db4 |
|
BLAKE2b-256 | 79eba333e41bcf3d14dcc1cd4fab10e77800c8b545439163569d9437bdb7af9d |