Skip to main content

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

License PyPi version lint Build status

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:

  1. Add import langchain_plantuml as the first import in your Python entrypoint file
  2. Create a callback using the activity_diagram_callback function
  3. Hook into your LLM application
  4. Call the export_uml_content method of activity_diagram_callback to export the PlantUML content
  5. Save PlantUML content to a file
  6. 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

langchain_plantuml-0.0.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

langchain_plantuml-0.0.3-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

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

Hashes for langchain_plantuml-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5293162f353ab8e3774bac41ba926315d4159a24f8ce935375922c3c3c6a1184
MD5 707da4723b819026a253f1e4105a5067
BLAKE2b-256 0b86042e0915b8b6aff6f9e449fb39e4da0886b6ae30137b135e4effaf8724c6

See more details on using hashes here.

File details

Details for the file langchain_plantuml-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_plantuml-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c86953eba411b3f51f98dfae75ea66f7f38dc53d010413e68183f8e62811c69a
MD5 b7618b27115543a873a5e78b52bb3db4
BLAKE2b-256 79eba333e41bcf3d14dcc1cd4fab10e77800c8b545439163569d9437bdb7af9d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page