Skip to content

Commit

Permalink
Update graph_utils.py (#2601)
Browse files Browse the repository at this point in the history
* Update graph_utils.py

Adds save_speaker_transitions_dict

* Update graph_utils.py

Adds export_path:str which defaults to None into visualize_speaker_transitions_dict. In there, run plt.savefig(path) if export_path is not None

* Update graph_utils.py

* Update graph_utils.py

Adds export_path functionality to visualize_speaker_transitions_dict()

---------

Co-authored-by: Chi Wang <wang.chi@microsoft.com>
  • Loading branch information
moresearch and sonichi committed May 10, 2024
1 parent ca8bf89 commit 6dd2b59
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions autogen/graph_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import logging
from typing import Dict, List
from typing import Dict, List, Optional

from autogen.agentchat import Agent

Expand Down Expand Up @@ -110,7 +110,9 @@ def invert_disallowed_to_allowed(disallowed_speaker_transitions_dict: dict, agen
return allowed_speaker_transitions_dict


def visualize_speaker_transitions_dict(speaker_transitions_dict: dict, agents: List[Agent]):
def visualize_speaker_transitions_dict(
speaker_transitions_dict: dict, agents: List[Agent], export_path: Optional[str] = None
):
"""
Visualize the speaker_transitions_dict using networkx.
"""
Expand All @@ -133,4 +135,8 @@ def visualize_speaker_transitions_dict(speaker_transitions_dict: dict, agents: L

# Visualize
nx.draw(G, with_labels=True, font_weight="bold")
plt.show()

if export_path is not None:
plt.savefig(export_path)
else:
plt.show()

0 comments on commit 6dd2b59

Please sign in to comment.