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. You can easily subscribe to events and keep them in a form that is easy to visualize and analyze.
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 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?")
plantuml_content = callback_handler.export_uml_content()
with open("example.puml", "w") as f:
for line in plantuml_content:
f.write(str(line) + "\n")
You will get the following PlantUML activity diagram
Exporting PlantUML to PNG
You can download plantuml.1.2023.10.jar
java -DPLANTUML_LIMIT_SIZE=81920 -jar plantuml-1.2023.10.jar example.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.1.tar.gz
.
File metadata
- Download URL: langchain_plantuml-0.0.1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.17
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7050b076162ed29356e644e3c977970017cec051d4a6cad75bb6f358d68c4fc5 |
|
MD5 | 73eaeefc193778433b6710153fccc81d |
|
BLAKE2b-256 | bb7ee44fea29acd354d216af90b1f1c039dbd2b06fe505aa5a98eaaad73cb657 |
File details
Details for the file langchain_plantuml-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: langchain_plantuml-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.8 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 | ada9c31643e1a7255001d2b34b5946a71a5a65468fee7f9d33fb8fe691108c17 |
|
MD5 | b78891b9a3a964940b47f9d414dc19c8 |
|
BLAKE2b-256 | 6ec3147a019a96bc5cf9ac10e313ef7783b2711e0d815d16469c12b124284df0 |