Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

feature/pipelex-list-pipes-cli (#14)

Thomas Hebrard3a11f44f617d
diff --git a/pipelex/cli/_cli.py b/pipelex/cli/_cli.py
index 87ceb08bd..7a5036749 100644
--- a/pipelex/cli/_cli.py
+++ b/pipelex/cli/_cli.py
@@ -1,14 +1,18 @@
import os
import shutil
-from typing import Annotated, Optional
+from itertools import groupby
+from typing import Annotated, Dict, Optional
import typer
from click import Command, Context
+from rich import box
+from rich.table import Table
from typer.core import TyperGroup
from typing_extensions import override
from pipelex import log, pretty_print
from pipelex.exceptions import PipelexCLIError, PipelexConfigError
+from pipelex.hub import get_pipe_provider
from pipelex.libraries.library_config import LibraryConfig
from pipelex.pipelex import Pipelex
from pipelex.tools.config.manager import config_manager
@@ -71,6 +75,72 @@ def show_config() -> None:
raise PipelexConfigError(f"Error loading configuration: {e}")
+def list_pipes() -> None:
+ """List all available pipes."""
+ Pipelex.make()
+
+ def _format_concept_code(concept_code: Optional[str], current_domain: str) -> str:
+ """Format concept code by removing domain prefix if it matches current domain."""
+ if not concept_code:
+ return ""
+ parts = concept_code.split(".")
+ if len(parts) == 2 and parts[0] == current_domain:
+ return parts[1]
+ return concept_code
+
+ try:
+ pipe_provider = get_pipe_provider()
+ pipes = pipe_provider.get_pipes()
+
+ # Sort pipes by domain and code
+ ordered_items = sorted(pipes, key=lambda x: (x.domain or "", x.code or ""))
+
+ # Create dictionary for return value
+ pipes_dict: Dict[str, Dict[str, Dict[str, str]]] = {}
+
+ # Group by domain and create separate tables
+ for domain, domain_pipes in groupby(ordered_items, key=lambda x: x.domain):
+ table = Table(
+ title=f"[bold magenta]domain = {domain}[/]",
+ show_header=True,
+ show_lines=True,
+ header_style="bold cyan",
+ box=box.SQUARE_DOUBLE_HEAD,
+ border_style="blue",
+ )
+
+ table.add_column("Code", style="green")
+ table.add_column("Definition", style="white")
+ table.add_column("Input", style="yellow")
+ table.add_column("Output", style="yellow")
+
+ pipes_dict[domain] = {}
+
+ for pipe in domain_pipes:
+ if pipe.code:
+ input_code = _format_concept_code(pipe.input_concept_code, domain)
+ output_code = _format_concept_code(pipe.output_concept_code, domain)
+
+ table.add_row(
+ pipe.code,
+ pipe.definition or "",
+ input_code,
+ output_code,
+ )
+
+ pipes_dict[domain][pipe.code] = {
+ "definition": pipe.definition or "",
+ "input": pipe.input_concept_code or "",
+ "output": pipe.output_concept_code or "",
+ }
+
+ pretty_print(table)
+
+ except Exception as e:
+ raise PipelexCLIError(f"Failed to list pipes: {e}")
+
+
def main() -> None:
"""Entry point for the pipelex CLI."""
app()
diff --git a/pipelex/libraries/pipelines/questions.py b/pipelex/libraries/pipelines/questions.py
index f66f584ca..96383100c 100644
--- a/pipelex/libraries/pipelines/questions.py
+++ b/pipelex/libraries/pipelines/questions.py
@@ -5,7 +5,6 @@ from typing import Generic, List, Literal, Optional, TypeVar, Union
from pydantic import Field, model_validator
from typing_extensions import Self, override
-from pipelex import pretty_print
from pipelex.core.stuff_content import StructuredContent
@@ -60,12 +59,6 @@ class ThoughtfulAnswer(StructuredContent):
the_lesson: str
the_answer: str
- def pretty_print(self):
- pretty_print(self.the_trap, title="The trap", border_style="bright_red")
- pretty_print(self.the_counter, title="The counter", border_style="bright_yellow")
- pretty_print(self.the_lesson, title="The lesson", border_style="blue")
- pretty_print(self.the_answer, title="The answer", border_style="green")
-
T = TypeVar("T")
diff --git a/pipelex/tools/misc/pretty.py b/pipelex/tools/misc/pretty.py
index b671c6d52..08c514ba2 100644
--- a/pipelex/tools/misc/pretty.py
+++ b/pipelex/tools/misc/pretty.py
@@ -6,6 +6,7 @@ from rich import print as rich_print
from rich.panel import Panel
from rich.pretty import Pretty
from rich.style import StyleType
+from rich.table import Table
from rich.text import Text, TextType
from pipelex.tools.misc.terminal_utils import BOLD_FONT, RESET_FONT, TerminalColor
@@ -39,6 +40,15 @@ def pretty_print_using_rich(
content = Text(content, style="link " + content, no_wrap=True)
else:
content = Text(str(content)) # Treat all other strings as plain text
+ elif isinstance(content, Table):
+ # For tables, print directly without a panel
+ if title:
+ rich_print(f"\n[bold blue]{title}[/]\n")
+ rich_print(content)
+ rich_print("\n")
+ if subtitle:
+ rich_print(f"\n[dim]{subtitle}[/]")
+ return
else:
content = Pretty(content)
panel = Panel(
diff --git a/pipelex/tools/templating/jinja2_rendering.py b/pipelex/tools/templating/jinja2_rendering.py
index 4a6c8a4e6..c63cf1eba 100644
--- a/pipelex/tools/templating/jinja2_rendering.py
+++ b/pipelex/tools/templating/jinja2_rendering.py
@@ -64,7 +64,6 @@ async def render_jinja2(
undeclared_variables.discard("preliminary_text")
if undeclared_variables:
log.verbose(undeclared_variables, "Jinja2 undeclared_variables")
- # pretty_print(undeclared_variables, title="Jinja2 undeclared_variables")
temlating_context = temlating_context.copy()
if prompting_style:
_add_to_templating_context(
diff --git a/pipelex/tools/templating/template_preprocessor.py b/pipelex/tools/templating/template_preprocessor.py
index 2f9c3e145..6e22cfbe9 100644
--- a/pipelex/tools/templating/template_preprocessor.py
+++ b/pipelex/tools/templating/template_preprocessor.py
@@ -74,8 +74,6 @@ def preprocess_template(template: str) -> str:
processed_template = new_template
if changes_made:
- # pretty_print(template, "Original template")
- # pretty_print(processed_template, "Processed template")
pass
return processed_template
diff --git a/pyproject.toml b/pyproject.toml
index 915ce5f6d..f7aa7c684 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[project]
name = "pipelex"
-version = "0.2.8"
+version = "0.2.9"
description = "Pipelex is an open-source dev tool based on a simple declarative language that lets you define replicable, structured, composable LLM pipelines."
authors = [{ name = "Evotis S.A.S.", email = "[email protected]" }]
maintainers = [{ name = "Pipelex staff", email = "[email protected]" }]
diff --git a/uv.lock b/uv.lock
index ca7cedcff..d7328815d 100644
--- a/uv.lock
+++ b/uv.lock
@@ -834,7 +834,7 @@ wheels = [
[[package]]
name = "pipelex"
-version = "0.2.8"
+version = "0.2.9"
source = { editable = "." }
dependencies = [
{ name = "aiofiles" },