langchain_core.runnables.graph_png.PngDrawer¶
- class langchain_core.runnables.graph_png.PngDrawer(fontname: Optional[str] = None, labels: Optional[LabelsDict] = None)[source]¶
- 用于将状态图绘制为PNG文件的辅助类。 - 它需要安装 graphviz 和 pygraphviz。 :param fontname: 用于标签的字体 :param labels: 标签覆盖的字典。该字典 - 应采用以下格式:{ - “nodes”: {
- “node1”: “CustomLabel1”, “node2”: “CustomLabel2”, “__end__”: “End Node” 
 - }, “edges”: { - “continue”: “ContinueLabel”, “end”: “EndLabel” - } - } 键是原始标签,值是新的标签。 - 使用方法
- drawer = PngDrawer() drawer.draw(state_graph, 'graph.png') 
 - 初始化PNG绘图器。 - 参数
- fontname (Optional[str]) – 用于标签的字体。默认为“arial”。 
- labels (Optional[LabelsDict]) – - 标签覆盖的字典。该字典应采用以下格式:{ - “nodes”: {
- “node1”: “CustomLabel1”, “node2”: “CustomLabel2”, “__end__”: “End Node” 
 - }, “edges”: { - “continue”: “ContinueLabel”, “end”: “EndLabel” - } - } 键是原始标签,值是新的标签。默认为None。 
 
 - 方法 - __init__([fontname, labels])- 初始化PNG绘图器。 - add_edge(viz, source, target[, label, ...])- 将边添加到图中。 - add_edges(viz, graph)- 将边添加到图中。 - add_node(viz, node)- 将节点添加到图中。 - add_nodes(viz, graph)- 将节点添加到图中。 - draw(graph[, output_path])- 将给定的状态图绘制到PNG文件中。 - get_edge_label(label)- 返回用于边的标签。 - get_node_label(label)- 返回用于节点的标签。 - update_styles(viz, graph)- 更新入口节点和END节点的样式。 - __init__(fontname: Optional[str] = None, labels: Optional[LabelsDict] = None) None[source]¶
- 初始化PNG绘图器。 - 参数
- fontname (Optional[str]) – 用于标签的字体。默认为“arial”。 
- labels (Optional[LabelsDict]) – - 标签覆盖的字典。该字典应采用以下格式:{ - “nodes”: {
- “node1”: “CustomLabel1”, “node2”: “CustomLabel2”, “__end__”: “End Node” 
 - }, “edges”: { - “continue”: “ContinueLabel”, “end”: “EndLabel” - } - } 键是原始标签,值是新的标签。默认为None。 
 
- 返回类型
- None 
 
 - add_edge(viz: Any, source: str, target: str, label: Optional[str], conditional: bool = False) None[source]¶
- 将边添加到图中。 - 参数
- viz (Any) – 图viz对象。 
- source (str) – 源节点。 
- target (str) – 目标节点。 
- label (Optional[str]) – 边的标签。默认为None。 
- conditional (bool) – 边是否为条件边。默认为False。 
 
- 返回
- None 
- 返回类型
- None 
 
 - add_edges(viz: Any, graph: Graph) None[source]¶
- 将边添加到图中。 - 参数
- viz (Any) – 图viz对象。 
- 图 (Graph) – 要绘制的图。 
 
- 返回类型
- None 
 
 - add_node(viz: Any, node: str) None[source]¶
- 将节点添加到图中。 - 参数
- viz (Any) – 图viz对象。 
- node (str) – 要添加的节点。 
 
- 返回
- None 
- 返回类型
- None 
 
 - add_nodes(viz: Any, graph: Graph) None[source]¶
- 将节点添加到图中。 - 参数
- viz (Any) – 图viz对象。 
- 图 (Graph) – 要绘制的图。 
 
- 返回类型
- None