Skip to content
Merged
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
119 changes: 0 additions & 119 deletions docs/reference/library-flows.md

This file was deleted.

38 changes: 26 additions & 12 deletions scripts/document_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _get_title() -> str:
def _get_preamble() -> str:
"""Get the common dependency explanation text."""
return """

This document lists all available flows in the NeMo Guardrails library.

## Understanding the tables
Expand Down Expand Up @@ -84,9 +84,11 @@ def _get_preamble() -> str:

"""


CHECK = "✔"
CROSS = "✗"


@dataclass
class Flow:
"""Represents a Colang flow."""
Expand All @@ -100,6 +102,7 @@ class Flow:
uses_llm: bool = False # Uses LLM from config.models
actions: List[str] = field(default_factory=list) # List of actions called by this flow


class FlowAnalyzer:
"""Analyzes Colang flow files and categorizes flows."""

Expand Down Expand Up @@ -133,7 +136,13 @@ class FlowAnalyzer:
re.compile(r"await\s+llm\."),
]

def __init__(self, library_path: Path, provider_list_path: Optional[Path], project_root: Path, output_path: Optional[Path] = None):
def __init__(
self,
library_path: Path,
provider_list_path: Optional[Path],
project_root: Path,
output_path: Optional[Path] = None,
):
self.library_path = library_path
self.provider_list_path = provider_list_path
self.project_root = project_root
Expand Down Expand Up @@ -624,6 +633,7 @@ def _get_relative_path(self, target_path: str) -> str:
except ValueError:
# Paths don't share a common base, use os.path.relpath
import os

return os.path.relpath(str(target), str(output_dir))

def _format_table_header(self, category_key: str, category_title: str, header_prefix: str) -> List[str]:
Expand All @@ -635,7 +645,9 @@ def _format_table_header(self, category_key: str, category_title: str, header_pr
output.append("")
return output

def _format_table_asciidoc(self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False) -> List[str]:
def _format_table_asciidoc(
self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False
) -> List[str]:
"""Format a table in AsciiDoc format."""
output = self._format_table_header(category_key, category_title, "==")
output.append('[cols="2,1,1,1,2,6", options="header"]')
Expand Down Expand Up @@ -667,19 +679,23 @@ def _format_table_asciidoc(self, category_key: str, category_title: str, flows:
else:
examples = "N/A"

output.append(
f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples}"
)
output.append(f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples}")

output.append("|===")
output.append("")
return output

def _format_table_markdown(self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False) -> List[str]:
def _format_table_markdown(
self, category_key: str, category_title: str, flows: List[Flow], include_links: bool = False
) -> List[str]:
"""Format a table in Markdown format."""
output = self._format_table_header(category_key, category_title, "##")
output.append("| Flow Name | Library (`nemoguardrails/library/...`) | Requires a Configured LLM | Requires External Server Calls | Description | Example Configs |")
output.append("|-----------|----------------------------------------|---------------------------|--------------------------------|-------------|-----------------|")
output.append(
"| Flow Name | Library (`nemoguardrails/library/...`) | Requires a Configured LLM | Requires External Server Calls | Description | Example Configs |"
)
output.append(
"|-----------|----------------------------------------|---------------------------|--------------------------------|-------------|-----------------|"
)

for flow in sorted(flows, key=lambda f: (f.library, f.name)):
llm_usage = CHECK if flow.uses_llm else CROSS
Expand All @@ -704,9 +720,7 @@ def _format_table_markdown(self, category_key: str, category_title: str, flows:
else:
examples = "N/A"

output.append(
f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples} |"
)
output.append(f"| `{flow.name}` | {library} | {llm_usage} | {requires_external} | {desc} | {examples} |")

output.append("")
return output
Expand Down
Loading