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: add docstring documentation #1819

Merged
merged 2 commits into from
Dec 31, 2024
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
3 changes: 0 additions & 3 deletions src/crewai/flow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ def decorator(func):

return decorator


def listen(condition: Union[str, dict, Callable]) -> Callable:
"""
Creates a listener that executes when specified conditions are met.
Expand Down Expand Up @@ -198,7 +197,6 @@ def router(condition: Union[str, dict, Callable]) -> Callable:
"""
def decorator(func):
func.__is_router__ = True
# Handle conditions like listen/start
if isinstance(condition, str):
func.__trigger_methods__ = [condition]
func.__condition_type__ = "OR"
Expand All @@ -220,7 +218,6 @@ def decorator(func):

return decorator


def or_(*conditions: Union[str, dict, Callable]) -> dict:
"""
Combines multiple conditions with OR logic for flow control.
Expand Down
2 changes: 2 additions & 0 deletions src/crewai/flow/flow_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@


class FlowPlot:
"""Handles the creation and rendering of flow visualization diagrams."""

def __init__(self, flow):
"""
Initialize FlowPlot with a flow object.
Expand Down
7 changes: 7 additions & 0 deletions src/crewai/flow/html_template_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@


class HTMLTemplateHandler:
"""Handles HTML template processing and generation for flow visualization diagrams."""

def __init__(self, template_path, logo_path):
"""
Initialize HTMLTemplateHandler with validated template and logo paths.
Expand All @@ -29,19 +31,23 @@ def __init__(self, template_path, logo_path):
raise ValueError(f"Invalid template or logo path: {e}")

def read_template(self):
"""Read and return the HTML template file contents."""
with open(self.template_path, "r", encoding="utf-8") as f:
return f.read()

def encode_logo(self):
"""Convert the logo SVG file to base64 encoded string."""
with open(self.logo_path, "rb") as logo_file:
logo_svg_data = logo_file.read()
return base64.b64encode(logo_svg_data).decode("utf-8")

def extract_body_content(self, html):
"""Extract and return content between body tags from HTML string."""
match = re.search("<body.*?>(.*?)</body>", html, re.DOTALL)
return match.group(1) if match else ""

def generate_legend_items_html(self, legend_items):
"""Generate HTML markup for the legend items."""
legend_items_html = ""
for item in legend_items:
if "border" in item:
Expand Down Expand Up @@ -69,6 +75,7 @@ def generate_legend_items_html(self, legend_items):
return legend_items_html

def generate_final_html(self, network_body, legend_items_html, title="Flow Plot"):
"""Combine all components into final HTML document with network visualization."""
html_template = self.read_template()
logo_svg_base64 = self.encode_logo()

Expand Down
1 change: 1 addition & 0 deletions src/crewai/flow/legend_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

def get_legend_items(colors):
return [
{"label": "Start Method", "color": colors["start"]},
Expand Down
1 change: 1 addition & 0 deletions src/crewai/flow/visualization_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def method_calls_crew(method: Any) -> bool:
return False

class CrewCallVisitor(ast.NodeVisitor):
"""AST visitor to detect .crew() method calls."""
def __init__(self):
self.found = False

Expand Down