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 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:

  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 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

langchain_plantuml-0.0.6.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

langchain_plantuml-0.0.6-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file langchain_plantuml-0.0.6.tar.gz.

File metadata

  • Download URL: langchain_plantuml-0.0.6.tar.gz
  • Upload date:
  • Size: 10.9 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.6.tar.gz
Algorithm Hash digest
SHA256 f2267cca421e5ba231ffb3237daa39d40502877775e21fe789a772a195315d12
MD5 dc02adb03ac95db095e32ee31df9a972
BLAKE2b-256 7df98ce82dff4415a3d472d0328b08f22573358d6da684f5c3ce572c1da85966

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for langchain_plantuml-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ec0db758af2f6471aa0828691f7e83f2895a248d23c552099e29b002971fc4f3
MD5 c4d559e744af147211108c8eeb9de6df
BLAKE2b-256 e290dd54dcbc9e274ccd54292b32550b5809e283154c7f4d3844e830a6ac8348

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