Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add a demonstration script to generate a graphviz pdf graph from a Dialogue #472

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mkdocs = "^1.4.2"
mkdocs-material = "^9.1.13"
ruff = "^0.3.4"
pre-commit = "^3.6.2"
graphviz = "^0.20.3"

[tool.poetry.extras]
all = ["tortoise-orm", "geopy", "fetchai-babble", "pyngrok", "fastapi"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import graphviz
from uagents.experimental.dialogues import Dialogue


def generate_graph(dialogue: Dialogue):
"""Create a graphviz diagram of the Dialogue's state graph to visually verify it

Note requires local installation of Graphviz,
e.g. `brew install graphviz` on macOS"""

dot = graphviz.Digraph(comment=dialogue.name)

for node in dialogue.nodes:
dot.node(node.name, str(node.name))

for edge in dialogue.edges:
dot.edge(str(edge.parent.name), str(edge.child.name), str(edge.name))

# the dot source gives a nice text based summary of the edges and nodes
print(dot.source)

# rendering the graph creates a pdf file in the current directory and
# opens it automatically. If you omit the `view=True` parameter, it
# just creates the file without auto opening it.
dot.render(f"{dialogue.name.lower()}.gv", view=True)
Loading